module Timl
Constants
- ROOTDIR
- SPECDIR
- VERSION
Public Class Methods
method_missing(name, *args, &block)
click to toggle source
# File lib/timl/timl.rb, line 54 def self.method_missing name, *args, &block define_tags name method(name).call args, &block end
start(format = :pretty, &block)
click to toggle source
Start a Timl
XML string. This is the main method for creating XML with Timl
. It accepts a format as its first parameter, which can either be :flat or :pretty (defaults to :pretty). The :flat parameter gives you back XML that has no indentation. The :pretty option runs the generated XML through the REXML document formatter, which is a little slower but gives great readability.
Timl.start
then takes a block, which kicks off the DSL. Here's a simple example:
Timl.start :flat do p { "This is a paragraph." } end #=> <p>This is a paragraph.</p>
For more example please refer to the README.
# File lib/timl/timl.rb, line 38 def self.start format = :pretty, &block @@out = "" module_eval &block case format when :pretty doc = REXML::Document.new(@@out) doc.write(xml = '', 2) when :flat xml = @@out else end @@out = "" xml end
Private Class Methods
html5_doctype()
click to toggle source
Appends:
<!DOCTYPE html>
To the resulting XML file.
# File lib/timl/timl.rb, line 84 def self.html5_doctype @@out << '<!DOCTYPE html>' end
parameterize(hash)
click to toggle source
# File lib/timl/timl.rb, line 61 def self.parameterize hash return "" unless hash.is_a? Hash hash.inject("") do |memo, entry| memo += " #{entry.first.to_s}=\"#{entry.last.to_s}\"" end end
xml_header(options = {})
click to toggle source
Appends:
<?xml version="1.0" encoding="UTF-8" ?>
To the resulting XML file.
# File lib/timl/timl.rb, line 73 def self.xml_header options = {} options[:version] = "1.0" unless options[:version] options[:encoding] = "UTF-8" unless options[:encoding] @@out << "<?xml #{parameterize(options)} ?>" end