class Glyph::MacroNode

A Glyph macro in Glyph Abstract Syntax Tree @since 0.3.0

Public Instance Methods

attr(name)
Alias for: attribute
attribute(name) click to toggle source

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
Also aliased as: attr
attributes() click to toggle source

@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
Also aliased as: attrs
attrs()
Alias for: attributes
child_macros() click to toggle source

@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
contents() click to toggle source

@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
dispatch(node) click to toggle source

@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
evaluate(context, options={}) click to toggle source

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
expand(context) click to toggle source

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
param(n)
Alias for: parameter
parameter(n) click to toggle source

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
Also aliased as: param
parameters() click to toggle source

@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
Also aliased as: params
params()
Alias for: parameters
source() click to toggle source

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
to_s() click to toggle source

@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
value() click to toggle source

Equivalent to Glyph::MacroNode#parameter(0). @since 0.3.0

# File lib/glyph/syntax_node.rb, line 106
def value
        parameter(0)
end