Class: Treetop::Runtime::TemplateNode

Inherits:
SyntaxNode
  • Object
show all
Defined in:
lib/alongslide/treetop/parser.rb

Overview

Template node base class. Covers panels, panel templates, sections.

Direct Known Subclasses

PanelNode, SectionNode, UserTemplateNode

Instance Method Summary collapse

Instance Method Details

#is_user_templateObject

Default.



90
91
92
# File 'lib/alongslide/treetop/parser.rb', line 90

def is_user_template
  false
end

#renderObject

Load template and render it, with content, if applicable.



41
42
43
# File 'lib/alongslide/treetop/parser.rb', line 41

def render
  ::Alongslide::Templates::render_template template_name, is_user_template, render_params
end

#render_paramsObject

Sections and panels optionally implement generic “class_params”, as well as required identifier.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/alongslide/treetop/parser.rb', line 48

def render_params
  params = {content: template_content || []}

  classes = if respond_to? :class_params
    class_params.elements.map do |item|
      item.param.text_value
    end
  end
  params[:classes] = (classes || []).join(" ")

  if respond_to? :identifier
    params[:identifier] = identifier.text_value
  end

  return params
end

#template_contentObject

If Node has “contents”, prepare content for template’s variable of the same name.

This may mean rendering another subtemplate, or simply some Markdown.



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/alongslide/treetop/parser.rb', line 76

def template_content
  if respond_to? :contents and contents
    contents.elements.map do |item|
      if item.content.respond_to? :template
        item.content.template.renderable.template.render
      else
        ::Alongslide::render item.text_value, plain: true
      end
    end
  end
end

#template_nameObject

Template named in directive is what to look for in filesystem.



67
68
69
# File 'lib/alongslide/treetop/parser.rb', line 67

def template_name
  command.text_value
end