Class: PagesCore::HtmlFormatter

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::AssetTagHelper, ImagesHelper
Defined in:
app/formatters/pages_core/html_formatter.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ImagesHelper

#dynamic_image_tag, #original_dynamic_image_tag, #uncropped_dynamic_image_tag

Constructor Details

#initialize(string, options = {}) ⇒ HtmlFormatter

Returns a new instance of HtmlFormatter.



13
14
15
16
# File 'app/formatters/pages_core/html_formatter.rb', line 13

def initialize(string, options = {})
  @string = string
  @options = options
end

Class Method Details

.to_html(string, options = {}) ⇒ Object



8
9
10
# File 'app/formatters/pages_core/html_formatter.rb', line 8

def to_html(string, options = {})
  new(string, options).to_html
end

Instance Method Details

#to_htmlObject



18
19
20
21
22
23
24
25
# File 'app/formatters/pages_core/html_formatter.rb', line 18

def to_html
  string = parse_images(parse_files(parse_attachments(@string)))
  if @options[:shorten] && string.length > @options[:shorten]
    string = string[0..@options[:shorten]] + "..."
  end
  string += " #{@options[:append]}" if @options[:append]
  RedCloth.new(string).to_html.html_safe
end