Class: Dryml::DrymlDoc::TagDef
- Inherits:
-
Object
- Object
- Dryml::DrymlDoc::TagDef
- 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
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#taglib ⇒ Object
readonly
Returns the value of attribute taglib.
Instance Method Summary collapse
-
#attributes ⇒ Object
An array of the arrtibute names defined by this tag.
-
#comment ⇒ Object
The contents of the XML or ERB comment, if any, immediately above the tag definition.
-
#extension? ⇒ Boolean
Is this an <extend>?.
- #filename ⇒ Object
-
#for_type ⇒ Object
The definition’s ‘for’ attribute.
-
#initialize(taglib, node) ⇒ TagDef
constructor
A new instance of TagDef.
-
#merge_attrs ⇒ Object
The name of the tag, if any, that this definition merges its attributes into That is, the tag with ‘merge’ or ‘merge-attrs’ declared.
-
#merge_params ⇒ Object
The name of the tag, if any, that this definition merges its parameters into That is, the tag with ‘merge’ or ‘merge-params’ declared.
- #name ⇒ Object
- #no_doc? ⇒ Boolean
-
#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).
-
#polymorphic? ⇒ Boolean
Is this the base definition of a polymorphic tag.
- #source ⇒ Object
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
#node ⇒ Object (readonly)
Returns the value of attribute node.
79 80 81 |
# File 'lib/dryml/dryml_doc.rb', line 79 def node @node end |
#taglib ⇒ Object (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
#attributes ⇒ Object
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 |
#comment ⇒ Object
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>?
151 152 153 |
# File 'lib/dryml/dryml_doc.rb', line 151 def extension? node.name == "extend" end |
#filename ⇒ Object
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_type ⇒ Object
The definition’s ‘for’ attribute
157 158 159 |
# File 'lib/dryml/dryml_doc.rb', line 157 def for_type node.attributes['for'] end |
#merge_attrs ⇒ Object
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_params ⇒ Object
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 |
#name ⇒ Object
83 84 85 |
# File 'lib/dryml/dryml_doc.rb', line 83 def name node.attributes['tag'] end |
#no_doc? ⇒ 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
146 147 148 |
# File 'lib/dryml/dryml_doc.rb', line 146 def polymorphic? node.attributes['polymorphic'].present? end |
#source ⇒ Object
87 88 89 |
# File 'lib/dryml/dryml_doc.rb', line 87 def source doc.restore_erb_scriptlets(node.to_s).strip end |