Class: Amber::Render::Template
- Inherits:
-
Object
- Object
- Amber::Render::Template
- Defined in:
- lib/amber/render/template.rb
Constant Summary collapse
- PROPERTY_HEADER =
/^\s*(^(|- )@\w[^\n]*?\n)*/m
- RENDER_MAP =
{ :text => 'render_textile', :textile => 'render_textile', :md => 'render_markdown', :markdown => 'render_markdown', :html => 'render_raw', :raw => 'render_raw', :none => 'render_none', :erb => 'render_none' }
- TEXTILE_TOC_RE =
/^\s*h([1-6])\.\s+(.*)/
- ERB_TAG_RE =
/<%=.*?%>/
- ERB_PLACEHOLDER_RE =
/xx erb tag\d+ xx/
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#partial ⇒ Object
readonly
Returns the value of attribute partial.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Template
constructor
A new instance of Template.
-
#render(view, options = {}) ⇒ Object
returns rendered content or title, depending on render_mode.
Constructor Details
#initialize(options = {}) ⇒ Template
Returns a new instance of Template.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/amber/render/template.rb', line 33 def initialize(={}) if [:file] @file = [:file] @type = [:type] || type_from_file(@file) elsif [:content] @content = [:content] @type = [:type] # e.g. :haml. required if @content end @partial = [:partial] end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
30 31 32 |
# File 'lib/amber/render/template.rb', line 30 def content @content end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
28 29 30 |
# File 'lib/amber/render/template.rb', line 28 def file @file end |
#partial ⇒ Object (readonly)
Returns the value of attribute partial.
31 32 33 |
# File 'lib/amber/render/template.rb', line 31 def partial @partial end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
29 30 31 |
# File 'lib/amber/render/template.rb', line 29 def type @type end |
Instance Method Details
#render(view, options = {}) ⇒ Object
returns rendered content or title, depending on render_mode. anchors are always automatically added to content headings.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/amber/render/template.rb', line 48 def render(view, ={}) view.locals[:_type] = @type render_mode = .delete(:mode) || :content toc_option = .delete(:toc) if render_mode == :title render_title(view) else html = render_html(view) toc_renderer = RegexTableOfContents.new(html, ) if render_mode == :toc toc_renderer.to_toc elsif toc_option === false toc_renderer.to_html elsif toc_option || render_mode == :toc_and_content %(<div id="TOC">%s</div>\n\n%s) % [toc_renderer.to_toc, toc_renderer.to_html] else toc_renderer.to_html end end end |