Class: Humpyard::Elements::TextElement

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/humpyard/elements/text_element.rb

Overview

Humpyard::Elements::TextElement is a model of a text element.

Instance Method Summary collapse

Instance Method Details

#html_content(options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/humpyard/elements/text_element.rb', line 15

def html_content(options = {})
  if content.blank?
    html = ''
  else
    if Object.const_defined?('RedCloth')
      html = RedCloth.new(content).to_html
    else
      html = content.gsub("\n", "<br />")
    end
  end
  
  unless html.blank?
    html = Humpyard.uri_parser.substitute html if options[:parse_uris]
    
    html.gsub(/(href="[a-z]*:\/\/)/,'target="blank" \1').html_safe
  else
    ''
  end
end

#html_content=(content) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/humpyard/elements/text_element.rb', line 35

def html_content= content
  if content.blank?
    self.content = ''
  else
    if Object.const_defined?('RedCloth')
      require 'html_to_textile'           
      self.content = HtmlToTextile.new(content.gsub("\n", ' ')).to_textile
    else
      self.content = content.gsub(/<br[^>]*>/, "\n").gsub(/<[^>]*>/, '')
    end
  end
end