0.0
No commit activity in last 3 years
No release in over 3 years
a gem that lets you add overwriteable values and attributes to the xmls you build
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.0.0
~> 1.8.3
~> 3.12
~> 2.8.0

Runtime

~> 1.5.0
 Project Readme

NokoBuilder¶ ↑

NokoBuilder is a gem that makes building out xml using nokogiri even easier! It makes each tag value and attributes act as a default value that is easily overwritable and extendable, while still maintaining all the stuff you get from the normal nokogiri xml builder.

Examples¶ ↑

VALUES¶ ↑

The values for xml tags can be overwritten by passing the value as an option when creating the xml document.

builder = NokoBuilder.new(options) do |xml|
  xml.Docu do
    xml.One "default value"
    xml.Two
  end
end

If options = {} then builder.to_xml would produce:

<?xml version="1.0"?>
<Docu>
  <One>default value</One>
</Docu>

If options = {:One => "BOOM", :Two => "BAMO"} then builder.to_xml would produce:

<?xml version="1.0"?>
<Docu>
  <One>BOOM</One>
  <Two>BAMO</Two>
</Docu>

ATTRIBUTES¶ ↑

You can pass in attributes to the nokobuilder the same way you would with nokogiri builder.

builder = NokoBuilder.new(options) do |xml|
  xml.One('xmlns' => 'http://stuff') do
    xml.Inside "namey", :attribute => "me"
    xml.Another(:one => "one", :two => "two")
  end
end

If options = {} then builder.to_xml Would produce:

<?xml version="1.0"?>
<One xmlns="http://stuff">
  <Inside attribute="me">namey</Inside>
  <Another one="one" two="two"/>
</One>

If options = {:Inside_nattr => {:blamo => "one"}, :Another_nattr => {:one => 'new', :three => "thr"}} then builder.to_xml Would produce:

<?xml version="1.0"?>
<One xmlns="http://stuff">
  <Inside attribute="me" blamo="one">namey</Inside>
  <Another one="new" two="two" three="thr"/>
</One>

NOKOGIRI OPTIONS¶ ↑

You can pass in options to the nokogiri builder as the second argument if you want.

builder = NokoBuilder.new({},{:encoding => 'UTF-8'}) do |xml|
  xml.One do
    xml.Inside "namey"
  end
end

Doing builder.to_xml Would produce:

<?xml version="1.0" encoding="UTF-8"?>
<One>
  <Inside>namey</Inside>
</One>

Contributing to noko_builder¶ ↑

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet.

  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it.

  • Fork the project.

  • Start a feature/bugfix branch.

  • Commit and push until you are happy with your contribution.

  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright © 2012 frausto. See LICENSE.txt for further details.