Class: Dryml::DrymlDoc::TagDef

Inherits:
Object
  • Object
show all
Includes:
classy_module do def comment_intro comment && comment =~ /(.*?)^#/m ? $1 : comment end def comment_rest comment && comment[comment_intro.length.classy_module do def comment_intro comment && comment =~ /(.*?)^#/m ? $1 : comment end def comment_rest comment && comment[comment_intro.length..-1] end %w(comment comment_intro comment_rest).each do |m| class_eval "def #{m}_html; Maruku.new(#{m}).to_html.gsub(/&/, '&'); end" end end
Defined in:
lib/dryml/dryml_doc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(taglib, node) ⇒ TagDef

Returns a new instance of TagDef.



74
75
76
77
# File 'lib/dryml/dryml_doc.rb', line 74

def initialize(taglib, node)
  @taglib = taglib
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



79
80
81
# File 'lib/dryml/dryml_doc.rb', line 79

def node
  @node
end

#taglibObject (readonly)

Returns the value of attribute taglib.



79
80
81
# File 'lib/dryml/dryml_doc.rb', line 79

def taglib
  @taglib
end

Instance Method Details

#attributesObject

An array of the arrtibute names defined by this tag



124
125
126
# File 'lib/dryml/dryml_doc.rb', line 124

def attributes
  (node.attributes['attrs'] || "").split(/\s*,\s*/).where_not.blank?
end

#commentObject

The contents of the XML or ERB comment, if any, immediately above the tag definition



102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/dryml/dryml_doc.rb', line 102

def comment
  @comment ||= begin
    space = node.previous_sibling and
      space.to_s.blank? && space.to_s.count("\n") == 1 and
      comment_node = space.previous_sibling

    if comment_node.is_a?(REXML::Comment)
      doc.restore_erb_scriptlets(comment_node.to_s.strip)
    elsif space.to_s.strip.starts_with?("[![DRYML-ERB")
      text = doc.restore_erb_scriptlets(space.to_s.strip)
      text.match(/.*<%#(.*?)%>$/m)[1] rescue nil
    end
  end
end

#extension?Boolean

Is this an <extend>?

Returns:

  • (Boolean)


151
152
153
# File 'lib/dryml/dryml_doc.rb', line 151

def extension?
  node.name == "extend"
end

#filenameObject



91
92
93
94
95
96
97
98
99
# File 'lib/dryml/dryml_doc.rb', line 91

def filename
  @filename ||= begin
                  page = node.parent
                  while page.name != 'dryml_page' do
                    page = node.parent
                  end
                  page.attributes['path']
                end
end

#for_typeObject

The definition’s ‘for’ attribute



157
158
159
# File 'lib/dryml/dryml_doc.rb', line 157

def for_type
  node.attributes['for']
end

#merge_attrsObject

The name of the tag, if any, that this definition merges its attributes into That is, the tag with ‘merge’ or ‘merge-attrs’ declared



170
171
172
# File 'lib/dryml/dryml_doc.rb', line 170

def merge_attrs
  REXML::XPath.first(node, ".//*[@merge|@merge-attrs]")._?.name
end

#merge_paramsObject

The name of the tag, if any, that this definition merges its parameters into That is, the tag with ‘merge’ or ‘merge-params’ declared



164
165
166
# File 'lib/dryml/dryml_doc.rb', line 164

def merge_params
  REXML::XPath.first(node, ".//*[@merge|@merge-params]")._?.name
end

#nameObject



83
84
85
# File 'lib/dryml/dryml_doc.rb', line 83

def name
  node.attributes['tag']
end

#no_doc?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/dryml/dryml_doc.rb', line 119

def no_doc?
  comment =~ /^nodoc\b/
end

#parameters(element = node) ⇒ Object

Returns a recursive array srtucture, where each item in the array is a pair: [parameter_name, sub_parameters] (sub-parameters is the same kind of structure)



131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/dryml/dryml_doc.rb', line 131

def parameters(element=node)
  result = []
  element.elements.each do |e|
    if (p = e.attributes['param'])
      param_name = p == "&true" ? e.name : p
      result << [param_name, parameters(e)]
    else
      result.concat(parameters(e))
    end
  end
  result
end

#polymorphic?Boolean

Is this the base definition of a polymorphic tag

Returns:

  • (Boolean)


146
147
148
# File 'lib/dryml/dryml_doc.rb', line 146

def polymorphic?
  node.attributes['polymorphic'].present?
end

#sourceObject



87
88
89
# File 'lib/dryml/dryml_doc.rb', line 87

def source
  doc.restore_erb_scriptlets(node.to_s).strip
end