class Glyph::MacroNode
Public Instance Methods
Returns the attribute syntax node with the specified name
@param [Symbol] name the name of the attribute @return [Glyph::AttributeNode, nil] an attribute node @since 0.3.0
# File lib/glyph/syntax_node.rb, line 120 def attribute(name) attributes.select{|n| n[:name] == name}[0] end
@return [Array<Glyph::AttributeNode>] an array of the child attribute nodes @since 0.3.0
# File lib/glyph/syntax_node.rb, line 112 def attributes children.select{|n| n.is_a? AttributeNode } end
@return [Array<Glyph::MacroNode>] an array of the child macro nodes @since 0.4.0
# 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
@return [String] a textual representation of the macro parameters. @since 0.3.0
# File lib/glyph/syntax_node.rb, line 69 def contents attributes.join+parameters.join("|") end
@since 0.5.0 Calls the ruby block stored in the :dispatch key, if present, in the context of node
# File lib/glyph/syntax_node.rb, line 160 def dispatch(node) return self[:dispatch].call node if self[:dispatch] false end
Expands the macro @return [String] the value of the macro @since 0.3.0
# File lib/glyph/syntax_node.rb, line 76 def evaluate(context, options={}) self[:value] = expand(context) end
Expands the macro corresponding to self @param [Glyph::MacroNode] context the context of the macro @return [String] the value of the macro @since 0.3.0
# File lib/glyph/syntax_node.rb, line 133 def expand(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).expand return m[:dispatch].call self end Glyph::Macro.new(self).expand end
Returns the parameter syntax node at the specified index @param [Fixnum] n the index of the parameter @return [Glyph::ParameterNode, nil] a parameter node @since 0.3.0
# File lib/glyph/syntax_node.rb, line 100 def parameter(n) parameters[n] end
@return [Array<Glyph::ParameterNode>] an array of the child parameter nodes @since 0.3.0
# File lib/glyph/syntax_node.rb, line 82 def parameters children.select{|n| n.is_a? ParameterNode } end
Returns where the macro was used (used in Glyph::Analyzer
) @since 0.4.0
# File lib/glyph/syntax_node.rb, line 151 def source s = self[:source][:file] rescue nil s ||= self[:source][:name] rescue nil s end
@return [String] a textual representation of the macro @since 0.3.0
# File lib/glyph/syntax_node.rb, line 62 def to_s e = self[:escape] ? "=" : "" "#{self[:name]}["+e+contents+e+"]" end
Equivalent to Glyph::MacroNode#parameter(0)
. @since 0.3.0
# File lib/glyph/syntax_node.rb, line 106 def value parameter(0) end