Module: Ox::Builder::DSL

Included in:
Factory
Defined in:
lib/ox/builder/dsl.rb

Instance Method Summary collapse

Instance Method Details

#cdata!(text) ⇒ Object



14
15
16
# File 'lib/ox/builder/dsl.rb', line 14

def cdata!(text)
  node << Ox::CData.new(text)
end

#comment!(text) ⇒ Object



18
19
20
# File 'lib/ox/builder/dsl.rb', line 18

def comment!(text)
  node << Ox::Comment.new(text)
end

#doctype!(type) ⇒ Object



22
23
24
# File 'lib/ox/builder/dsl.rb', line 22

def doctype!(type)
  node << Ox::DocType.new(type)
end

#instruct!(*args) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/ox/builder/dsl.rb', line 4

def instruct!(*args)
  attributes = args.last.is_a?(Hash) ? args.pop : { version: '1.0', encoding: 'UTF-8' }
  name = args.first || :xml

  with_dsl(Ox::Instruct.new(name)) do |instruct|
    instruct.add_attributes(attributes)
    node << instruct.node
  end
end

#tag!(name, *args, &block) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ox/builder/dsl.rb', line 26

def tag!(name, *args, &block)
  builder = Builder.build(Ox::Element.new(name), &block).tap do |tag|
    attributes = args.last.is_a?(Hash) ? args.pop : {}

    tag.add_attributes(attributes)

    args.each do |text|
      text = text.is_a?(Ox::Node) ? text : text.to_s
      tag.node << text
    end
  end

  node << builder.node
end