Module: Saxerator::DSL
- Included in:
- DocumentFragment, FullDocument
- Defined in:
- lib/saxerator/dsl.rb
Instance Method Summary collapse
- #at_depth(depth) ⇒ Object
- #child_of(tag) ⇒ Object
- #for_tag(*tags) ⇒ Object
- #for_tags(tags) ⇒ Object
- #with_attribute(name, value = nil) ⇒ Object
- #with_attributes(attrs) ⇒ Object
- #within(tag) ⇒ Object
Instance Method Details
#at_depth(depth) ⇒ Object
12 13 14 |
# File 'lib/saxerator/dsl.rb', line 12 def at_depth(depth) specify Latches::AtDepth.new(depth.to_i) end |
#child_of(tag) ⇒ Object
20 21 22 |
# File 'lib/saxerator/dsl.rb', line 20 def child_of(tag) specify Latches::ChildOf.new(tag.to_s) end |
#for_tag(*tags) ⇒ Object
3 4 5 |
# File 'lib/saxerator/dsl.rb', line 3 def for_tag(*) () end |
#for_tags(tags) ⇒ Object
7 8 9 10 |
# File 'lib/saxerator/dsl.rb', line 7 def () raise ArgumentError.new('#for_tags requires an Array argument') unless .is_a? Array specify Latches::ForTags.new(.map(&:to_s)) end |
#with_attribute(name, value = nil) ⇒ Object
24 25 26 |
# File 'lib/saxerator/dsl.rb', line 24 def with_attribute(name, value = nil) specify Latches::WithAttributes.new({name.to_s => !!value ? value.to_s : nil }) end |
#with_attributes(attrs) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/saxerator/dsl.rb', line 28 def with_attributes(attrs) if attrs.is_a? Array attrs = Hash[attrs.map { |k| [k, nil]}] elsif attrs.is_a? Hash attrs = Hash[attrs.map{ |k, v| [k.to_s, v ? v.to_s : v]}] else raise ArgumentError.new("attributes should be a Hash or Array") end specify Latches::WithAttributes.new(attrs) end |