Skip to content

Commit

Permalink
Added image replace to wysiwyg editor core field paragraphs
Browse files Browse the repository at this point in the history
  • Loading branch information
cykod committed Jun 10, 2010
1 parent 6847490 commit b8f161d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/content/core_field.rb
Expand Up @@ -190,6 +190,7 @@ def form_field(f,field_name,field_opts,options={})

class EditorField < Content::CoreField::HtmlField #:nodoc:all
content_display :html
setup_model(:required) { |cls,fld| cls.before_save() { |entry| entry.send("#{fld.model_field.field}=",ContentFilter.wysiwyg_replace_images(entry.send(fld.model_field.field)) ) } }
# Everything the same as StringField that we want to display an editor area
def form_field(f,field_name,field_opts,options={})
f.editor_area field_name, field_opts.merge(options)
Expand Down
15 changes: 15 additions & 0 deletions app/models/content_filter.rb
Expand Up @@ -176,6 +176,21 @@ def self.markdown_replace_images(code,image_folder_path,live_url = false) #:nodo
cd
end


def self.wysiwyg_replace_images(html)
html = html.gsub(/\/__fs__\/([0-9a-fA-F\/]+)(\:([a-zA-Z_]+)){0,1}/) do |match|
size = $3 ? $3 : nil
file_id = $1.split("/")[-1].to_i
file = DomainFile.find_by_id(file_id)
if file
file.url(size)
else
"/images/missing_image.gif"
end
end

end

def self.html_replace_images(code,image_folder_path,live_url = false) #:nodoc:

re = Regexp.new("(['\"])images\/([a-zA-Z0-9_\\-\\/. :]+?)\\1" ,Regexp::IGNORECASE | Regexp::MULTILINE)
Expand Down

0 comments on commit b8f161d

Please sign in to comment.