Class: HammerBuilder::StubBuilderForDocumentation::AbstractTag
- Inherits:
-
Object
- Object
- HammerBuilder::StubBuilderForDocumentation::AbstractTag
- Defined in:
- lib/hammer_builder/doc.rb
Direct Known Subclasses
Constant Summary collapse
- METHOD_MISSING_REGEXP =
/#{data_attribute}|#{id_class}/
Instance Attribute Summary collapse
-
#builder ⇒ Object
readonly
Returns the value of attribute builder.
Class Method Summary collapse
-
.attributes ⇒ Array<String>
Array of available attributes for the tag.
-
.tag_name ⇒ String
Tag’s name.
Instance Method Summary collapse
-
#attribute(name, value) ⇒ Object
it renders attribute using defined attribute method or by rendering attribute directly.
-
#attributes(attrs) ⇒ Object
attribute`s methods are called on background (in this case #id is called).
-
#class(*classes) ⇒ Object
adds classes to the tag by joining
classes
with ‘ ’ and skipping non-true classes. -
#data(hash) ⇒ Object
renders data-* attributes by
hash
. -
#id(*values) ⇒ Object
adds id to the tag by joining
values
with ‘_’. -
#initialize(builder) ⇒ AbstractTag
constructor
private
A new instance of AbstractTag.
-
#mimic(obj) ⇒ Object
(also: #[])
adds id and class to a tag by an object To determine the class it looks for .hammer_builder_ref or it uses class.to_s.underscore.tr(‘/’, ‘-’).
- #open(attributes = nil) ⇒ Object private
-
#rclass ⇒ Object
original Ruby method for class, class is used for html classes.
Constructor Details
#initialize(builder) ⇒ AbstractTag
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of AbstractTag.
84 85 86 87 88 89 90 |
# File 'lib/hammer_builder/doc.rb', line 84 def initialize(builder) @builder = builder @output = builder.instance_eval { @_output } @stack = builder.instance_eval { @_stack } @classes = [] @tag_name = self.rclass.tag_name end |
Instance Attribute Details
#builder ⇒ Object (readonly)
Returns the value of attribute builder.
81 82 83 |
# File 'lib/hammer_builder/doc.rb', line 81 def builder @builder end |
Class Method Details
.attributes ⇒ Array<String>
Returns array of available attributes for the tag.
10 11 12 |
# File 'lib/hammer_builder/doc.rb', line 10 def self.attributes _attributes end |
.tag_name ⇒ String
Returns tag’s name.
15 16 17 |
# File 'lib/hammer_builder/doc.rb', line 15 def self.tag_name @tag || superclass.tag_name end |
Instance Method Details
#attribute(name, value) ⇒ Object
it renders attribute using defined attribute method or by rendering attribute directly
104 105 106 107 108 |
# File 'lib/hammer_builder/doc.rb', line 104 def attribute(name, value) return __send__(name, value) if respond_to?(name) @output << Strings::SPACE << name.to_s << Strings::EQL_QUOTE << CGI.escapeHTML(value.to_s) << Strings::QUOTE self end |
#attributes(attrs) ⇒ Object
attribute`s methods are called on background (in this case #id is called)
115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/hammer_builder/doc.rb', line 115 def attributes(attrs) return self unless attrs attrs.each do |attr, value| if value.kind_of?(Array) __send__(attr, *value) else __send__(attr, value) end end self end |
#class(*classes) ⇒ Object
adds classes to the tag by joining classes
with ‘ ’ and skipping non-true classes
160 161 162 163 |
# File 'lib/hammer_builder/doc.rb', line 160 def class(*classes) @classes.push(*classes.select { |c| c }) self end |
#data(hash) ⇒ Object
renders data-* attributes by hash
208 209 210 211 |
# File 'lib/hammer_builder/doc.rb', line 208 def data(hash) hash.each { |k, v| __send__ "data_#{k}", v } self end |
#id(*values) ⇒ Object
adds id to the tag by joining values
with ‘_’
170 171 172 173 174 |
# File 'lib/hammer_builder/doc.rb', line 170 def id(*values) @output << Strings::ATTR_ID << CGI.escapeHTML(values.select { |v| v }.join(Strings::UNDERSCORE)) << Strings::QUOTE self end |
#mimic(obj) ⇒ Object Also known as: []
adds id and class to a tag by an object To determine the class it looks for .hammer_builder_ref or it uses class.to_s.underscore.tr(‘/’, ‘-’). To determine id it looks for #hammer_builder_ref or it takes class and #id or #object_id.
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/hammer_builder/doc.rb', line 183 def mimic(obj) klass = if obj.class.respond_to? :hammer_builder_ref obj.class.hammer_builder_ref else ActiveSupport::Inflector.underscore(obj.class.to_s).tr('/', '-') end id = case when obj.respond_to?(:hammer_builder_ref) obj.hammer_builder_ref when obj.respond_to?(:id) [klass, obj.id] else [klass, obj.object_id] end #noinspection RubyArgCount self.class(klass).id(id) end |
#open(attributes = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
93 94 95 96 97 98 99 |
# File 'lib/hammer_builder/doc.rb', line 93 def open(attributes = nil) @output << Strings::LT << @tag_name @builder.current = self attributes(attributes) default self end |
#rclass ⇒ Object
original Ruby method for class, class is used for html classes
128 |
# File 'lib/hammer_builder/doc.rb', line 128 alias_method(:rclass, :class) |