Class: Glyph::MacroNode
- Inherits:
-
SyntaxNode
- Object
- Hash
- Node
- SyntaxNode
- Glyph::MacroNode
- Defined in:
- lib/glyph/syntax_node.rb
Overview
A Glyph macro in Glyph Abstract Syntax Tree
Instance Attribute Summary
Attributes inherited from Node
Instance Method Summary collapse
-
#attribute(name) ⇒ Glyph::AttributeNode?
(also: #attr)
Returns the attribute syntax node with the specified name.
-
#attributes ⇒ Array<Glyph::AttributeNode>
(also: #attrs)
An array of the child attribute nodes.
-
#child_macros ⇒ Array<Glyph::MacroNode>
An array of the child macro nodes.
-
#contents ⇒ String
A textual representation of the macro parameters.
-
#dispatch(node) ⇒ Object
Calls the ruby block stored in the :dispatch key, if present, in the context of node.
-
#evaluate(context, options = {}) ⇒ String
Expands the macro.
-
#expand(context) ⇒ String
Expands the macro corresponding to self.
-
#parameter(n) ⇒ Glyph::ParameterNode?
(also: #param)
Returns the parameter syntax node at the specified index.
-
#parameters ⇒ Array<Glyph::ParameterNode>
(also: #params)
An array of the child parameter nodes.
-
#source ⇒ Object
Returns where the macro was used (used in Glyph::Analyzer).
-
#to_s ⇒ String
A textual representation of the macro.
-
#value ⇒ Object
Equivalent to Glyph::MacroNode#parameter(0).
Methods inherited from SyntaxNode
Methods inherited from Node
#&, #<<, #==, #>>, #ascend, #child, #clear, #descend, #each_child, #find_child, #find_parent, #from, #initialize, #inspect, #root, #to_hash, #to_node
Methods inherited from Hash
Constructor Details
This class inherits a constructor from Node
Instance Method Details
#attribute(name) ⇒ Glyph::AttributeNode? Also known as: attr
Returns the attribute syntax node with the specified name
120 121 122 |
# File 'lib/glyph/syntax_node.rb', line 120 def attribute(name) attributes.select{|n| n[:name] == name}[0] end |
#attributes ⇒ Array<Glyph::AttributeNode> Also known as: attrs
Returns an array of the child attribute nodes.
112 113 114 |
# File 'lib/glyph/syntax_node.rb', line 112 def attributes children.select{|n| n.is_a? AttributeNode } end |
#child_macros ⇒ Array<Glyph::MacroNode>
Returns an array of the child macro nodes.
88 89 90 91 92 93 94 |
# File 'lib/glyph/syntax_node.rb', line 88 def child_macros macros = [] parameters.each do |p| macros += p.children.select{|n| n.is_a? MacroNode } end macros end |
#contents ⇒ String
Returns a textual representation of the macro parameters.
69 70 71 |
# File 'lib/glyph/syntax_node.rb', line 69 def contents attributes.join+parameters.join("|") end |
#dispatch(node) ⇒ Object
Calls the ruby block stored in the :dispatch key, if present, in the context of node
160 161 162 163 |
# File 'lib/glyph/syntax_node.rb', line 160 def dispatch(node) return self[:dispatch].call node if self[:dispatch] false end |
#evaluate(context, options = {}) ⇒ String
Expands the macro
76 77 78 |
# File 'lib/glyph/syntax_node.rb', line 76 def evaluate(context, ={}) self[:value] = (context) end |
#expand(context) ⇒ String
Expands the macro corresponding to self
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/glyph/syntax_node.rb', line 133 def (context) self[:source] = context[:source] self[:document] = context[:document] self[:info] = context[:info] self[:value] = "" dispatched = parent_macro.dispatch(self) if parent_macro return dispatched if dispatched if Glyph['options.macro_set'] == "xml" || Glyph::MACROS[self[:name]].blank? && Glyph['options.xml_fallback'] then m = Glyph::MacroNode.new m[:name] = :xml Glyph::Macro.new(m). return m[:dispatch].call self end Glyph::Macro.new(self). end |
#parameter(n) ⇒ Glyph::ParameterNode? Also known as: param
Returns the parameter syntax node at the specified index
100 101 102 |
# File 'lib/glyph/syntax_node.rb', line 100 def parameter(n) parameters[n] end |
#parameters ⇒ Array<Glyph::ParameterNode> Also known as: params
Returns an array of the child parameter nodes.
82 83 84 |
# File 'lib/glyph/syntax_node.rb', line 82 def parameters children.select{|n| n.is_a? ParameterNode } end |
#source ⇒ Object
Returns where the macro was used (used in Glyph::Analyzer)
151 152 153 154 155 |
# File 'lib/glyph/syntax_node.rb', line 151 def source s = self[:source][:file] rescue nil s ||= self[:source][:name] rescue nil s end |
#to_s ⇒ String
Returns a textual representation of the macro.
62 63 64 65 |
# File 'lib/glyph/syntax_node.rb', line 62 def to_s e = self[:escape] ? "=" : "" "#{self[:name]}["+e+contents+e+"]" end |
#value ⇒ Object
Equivalent to Glyph::MacroNode#parameter(0).
106 107 108 |
# File 'lib/glyph/syntax_node.rb', line 106 def value parameter(0) end |