Class: Spirit::Document
- Inherits:
-
Object
- Object
- Spirit::Document
- Defined in:
- lib/spirit/document.rb
Overview
Document written in Genie Markup Language.
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#engine ⇒ Object
readonly
Returns the value of attribute engine.
-
#rndr ⇒ Object
readonly
Returns the value of attribute rndr.
Instance Method Summary collapse
-
#initialize(source, opts = {}) ⇒ Document
constructor
Creates a new document from the given source.
-
#render(anIO = nil) ⇒ String, Fixnum
Rendered output is returned as a string if
anIO
is not provided.
Constructor Details
#initialize(source, opts = {}) ⇒ Document
Creates a new document from the given source. It should contain valid markdown + embedded YAML.
18 19 20 21 22 23 24 25 26 |
# File 'lib/spirit/document.rb', line 18 def initialize(source, opts={}) opts = MARKDOWN_EXTENSIONS.merge opts @rndr = Render::HTML.new @engine = ::Redcarpet::Markdown.new(rndr, opts) @data = case when source.respond_to?(:to_str) then source.to_str when source.respond_to?(:read) then source.read else nil end end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
11 12 13 |
# File 'lib/spirit/document.rb', line 11 def data @data end |
#engine ⇒ Object (readonly)
Returns the value of attribute engine.
11 12 13 |
# File 'lib/spirit/document.rb', line 11 def engine @engine end |
#rndr ⇒ Object (readonly)
Returns the value of attribute rndr.
11 12 13 |
# File 'lib/spirit/document.rb', line 11 def rndr @rndr end |
Instance Method Details
#render(anIO = nil) ⇒ String, Fixnum
Rendered output is returned as a string if anIO
is not provided. The output is sanitized with Render::Sanitize, and should be considered safe for embedding into a HTML page without further escaping or sanitization.
38 39 40 41 42 |
# File 'lib/spirit/document.rb', line 38 def render(anIO=nil) output = engine.render(data) return anIO.write(output) unless anIO.nil? output end |