Class: Evertils::Helper::Xml
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#doc ⇒ Object
Returns the value of attribute doc.
Instance Method Summary collapse
- #a(link, content) ⇒ Object
- #br ⇒ Object
- #create(element, conf = {}) ⇒ Object
- #div(*children) ⇒ Object
-
#initialize(doc) ⇒ Xml
constructor
A new instance of Xml.
- #li(*children) ⇒ Object
- #span(content) ⇒ Object
- #ul(*children) ⇒ Object
Constructor Details
#initialize(doc) ⇒ Xml
Returns a new instance of Xml.
8 9 10 11 12 |
# File 'lib/evertils/helpers/xml.rb', line 8 def initialize(doc) raise ArgumentError, "doc param required" unless doc @doc = doc.first end |
Instance Attribute Details
#doc ⇒ Object
Returns the value of attribute doc.
4 5 6 |
# File 'lib/evertils/helpers/xml.rb', line 4 def doc @doc end |
Instance Method Details
#a(link, content) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/evertils/helpers/xml.rb', line 16 def a(link, content) conf = { href: link, content: content } create(:a, conf) end |
#br ⇒ Object
37 38 39 |
# File 'lib/evertils/helpers/xml.rb', line 37 def br create(:br) end |
#create(element, conf = {}) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/evertils/helpers/xml.rb', line 67 def create(element, conf = {}) el = Nokogiri::XML::Node.new(element.to_s, @doc) return el if conf.empty? conf.each_pair do |k, v| if el.respond_to? "#{k}=" el.send("#{k}=", v) elsif el.respond_to? k el.send(k, v) else el[k] = v end end el end |
#div(*children) ⇒ Object
51 52 53 54 55 |
# File 'lib/evertils/helpers/xml.rb', line 51 def div(*children) el = create(:div) children.each { |child| el.add_child(child) } el end |
#li(*children) ⇒ Object
43 44 45 46 47 |
# File 'lib/evertils/helpers/xml.rb', line 43 def li(*children) el = create(:li) children.each { |child| el.add_child(child) } el end |
#span(content) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/evertils/helpers/xml.rb', line 27 def span(content) conf = { content: content } create(:span, conf) end |
#ul(*children) ⇒ Object
59 60 61 62 63 |
# File 'lib/evertils/helpers/xml.rb', line 59 def ul(*children) el = create(:ul) children.each { |child| el.add_child(child) } el end |