Module: Saxerator::DSL

Included in:
DocumentFragment, FullDocument
Defined in:
lib/saxerator/dsl.rb

Instance Method Summary collapse

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(*tags)
  for_tags(tags)
end

#for_tags(tags) ⇒ Object

Raises:

  • (ArgumentError)


7
8
9
10
# File 'lib/saxerator/dsl.rb', line 7

def for_tags(tags)
  raise ArgumentError.new('#for_tags requires an Array argument') unless tags.is_a? Array
  specify Latches::ForTags.new(tags.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

#within(tag) ⇒ Object



16
17
18
# File 'lib/saxerator/dsl.rb', line 16

def within(tag)
  specify Latches::Within.new(tag.to_s)
end