Class: Almodovar::ResourcePresenter::HtmlSerializer

Inherits:
Serializer
  • Object
show all
Defined in:
lib/almodovar-server/resource_presenter/html_serializer.rb

Constant Summary collapse

TEMPLATE_PATH =
File.join(File.dirname(__FILE__), 'template.html.erb')

Instance Attribute Summary

Attributes inherited from Serializer

#options, #resource

Instance Method Summary collapse

Methods inherited from Serializer

#initialize, #options_for_link

Constructor Details

This class inherits a constructor from Almodovar::ResourcePresenter::Serializer

Instance Method Details

#beautify(representation) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/almodovar-server/resource_presenter/html_serializer.rb', line 24

def beautify(representation)
  formatter = Rouge::Formatters::HTML.new
  lexer = Rouge::Lexers::XML.new
  body = formatter.format(lexer.lex(representation))
  body = body.gsub(/\"(http\S+)\"/) { url = $1; "\"<a href=\"#{url}\">#{url}</a>\"" }
  body.html_safe
end

#metadataObject



20
21
22
# File 'lib/almodovar-server/resource_presenter/html_serializer.rb', line 20

def 
  resource.resource_class.
end

#metadata_text(text) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/almodovar-server/resource_presenter/html_serializer.rb', line 32

def (text)
  return if text.blank?

  if indentation = text[/\n\s+/]
    text = text.gsub(indentation, "\n")
  end

  text = text.strip
  text = GitHub::Markdown.render text
  text.html_safe
end

#to_htmlObject



15
16
17
18
# File 'lib/almodovar-server/resource_presenter/html_serializer.rb', line 15

def to_html
  template = File.read(TEMPLATE_PATH)
  ERB.new(template).result(binding)
end