NAME xx SYNOPSIS require "xx" include XX::XHTML doc = xhtml_{ html_{ head_{ title_{ " go xx! " } } body_{ " one more and it would be illegal " } } } DESCRIPTION xx is a library designed to extend ruby objects with html, xhtml, and xml generation methods. the approach of extending objects allows extremely natural document generation while preserving access to instance data. in essence it provides ruby objects (including the 'main' object) an intuitive means to generate various markup views of their data. SAMPLES <========< sample/a.rb >========> ~ > cat sample/a.rb require "xx" include XX::XHTML # # xx modules extend the current object to allow natural document markup # doc = xhtml_{ html_{ head_{ title_{ " go xx! " } } body_{ " one more and it would be illegal " } } } puts doc.pretty ~ > ruby sample/a.rb go xx! one more and it would be illegal <========< sample/b.rb >========> ~ > cat sample/b.rb require "xx" # # xml is as easy as html. xx extends your object very carefully, adding an # one method that is not prefaced with 'xx_' : 'method_missing'. the # method_missing defined is conservatively, recognizing only methods that end # with underscore ('_') as 'tag' methods intended to generate markup. as with # html, attributes may be passed to any tag method as either symbol or string. # class Table < ::Array include XX::XML attr "fields" def initialize *a, &b @fields = a.shift replace a end def self::[] *a, &b new *a, &b end def to_xml xml_{ table_{ each do |row| row_{ fields.zip(row) do |field, value| field_(:name => field, 'width' => value.size){ value } end } end } } end end table = Table[ %w( first_name last_name ssn ), %w( jane doe 424-24-2424 ), %w( john buck 574-86-4242 ), ] puts table.to_xml.pretty ~ > ruby sample/b.rb jane doe 424-24-2424 john buck 574-86-4242
<========< sample/c.rb >========> ~ > cat sample/c.rb require "xx" # # xx makes it impossible to generate invalid (syntactically) invalid documents # - unless to instruct it in insert raw html or xml using the 'h_' or 'x_' # methods. text inserted with 't_' is automatically escaped. like all xx # methods these can have one or more underscores after them in case there is a # collision with another method or the tag 'h', 'x', or 't' needs to be # generated. # include XX::XML doc = xml_{ root_{ div_{ t_ "this is escaped < > & text" } div_{ h_ "this is raw . & is not escaped" } div_{ x_ " xml " } div_{ x_{ even_{ entire_{ documents_{ "nest" } } } } } } } puts doc.pretty ~ > ruby sample/c.rb
this is escaped < > & text
this is raw . & is not escaped
xml
nest
AUTHORS Dan Fitzpatrick Ara.T.Howard HISTORY 0.0.0: - initial version BUGS please send bug reports to /dev/null. patches to addresses above. ;-)