Class: RailsMarkdownTemplates::Renderer
- Inherits:
-
Redcarpet::Render::HTML
- Object
- Redcarpet::Render::HTML
- RailsMarkdownTemplates::Renderer
- Includes:
- Redcarpet::Render::SmartyPants
- Defined in:
- lib/rails_markdown_templates/renderer.rb
Overview
Custom Redcarpet HTML renderer for Markdown with a metadata block
Instance Attribute Summary collapse
-
#metadata ⇒ Object
Returns the value of attribute metadata.
Instance Method Summary collapse
-
#doc_footer ⇒ Object
Rendered after all the other elements.
-
#doc_header ⇒ Object
Render before any other elements.
-
#initialize(options = {}) ⇒ Renderer
constructor
A new instance of Renderer.
-
#metadata_json ⇒ Object
Get JSON for the metadata.
-
#metadata_tags ⇒ Object
Get HTML tag(s) for the metadata.
-
#preprocess(full_document) ⇒ Object
Preprocess the whole document before the rendering process.
Constructor Details
#initialize(options = {}) ⇒ Renderer
Returns a new instance of Renderer.
31 32 33 34 |
# File 'lib/rails_markdown_templates/renderer.rb', line 31 def initialize(={}) super @metadata = {} end |
Instance Attribute Details
#metadata ⇒ Object
Returns the value of attribute metadata.
29 30 31 |
# File 'lib/rails_markdown_templates/renderer.rb', line 29 def @metadata end |
Instance Method Details
#doc_footer ⇒ Object
Rendered after all the other elements
54 55 56 |
# File 'lib/rails_markdown_templates/renderer.rb', line 54 def nil end |
#doc_header ⇒ Object
Render before any other elements
49 50 51 |
# File 'lib/rails_markdown_templates/renderer.rb', line 49 def doc_header nil end |
#metadata_json ⇒ Object
Get JSON for the metadata
44 45 46 |
# File 'lib/rails_markdown_templates/renderer.rb', line 44 def .to_json.html_safe end |
#metadata_tags ⇒ Object
Get HTML tag(s) for the metadata
37 38 39 40 41 |
# File 'lib/rails_markdown_templates/renderer.rb', line 37 def .map do |k,v| "<meta name=\"#{k}\" content=\"#{v}\" />" end.join("\n").html_safe end |
#preprocess(full_document) ⇒ Object
Preprocess the whole document before the rendering process
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rails_markdown_templates/renderer.rb', line 59 def preprocess(full_document) # Extract and store metadata block from start of document # # N.B. Implementation "borrowed" from Metadown: # # https://github.com/steveklabnik/metadown full_document =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m self. = YAML.load($1) if $1 # Return the document without the leading metadata block $POSTMATCH or full_document end |