Class | Rmobio::Rxml::BaseTransformer |
In: |
rxml/base_transformer.rb
|
Parent: | Builder::XmlMarkup |
Provide a base transformer to translate rxml document to xhtml markup. It subclasses the builder library XmlMarkup class so method not defined in this transformer class will inherit methods or method missing from XmlMarkup class. See XmlMarkup for documentation.
Example: In the controller, get the proper transformer class by passing a client type, See TransformerFactory class for supported client types:
require 'rmobio/rxml/transformer_factory' @xml = TransformerFactory.get_transformer('xhtml')
Here is the view that uses methods to output xhtml document header, an image and some text:
@xml.doctype(xml) do |x| @xml.body(x, 'mobio') do|body| @xml.image(body, "img1", 'http://localhost:3000/images/rails.png') @xml.softBr(body) body.b do |y| @xml.text(y, 'My test app') end end end
The above code generates the following xhtml in Firefox:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head><title>mobio</title></head><body> <img id="img1" src="http://localhost:3000/images/rails.png" /><br/> <b> My test app</b> </body></html>
Create a base rxml transformer to transform rxml document to xhtml markup
out: | Object receiving the markup in xhtml |
@view_buffer: | buffer to hold the view part of the document |
@model_buffer: | buffer to hold the model data of the document |
Final document is view_buffer + model_buffer for some subclass transformer (XformsTransformer)
Generate xthml head and body tag. The document title and style src are optional.
@xml.body(x, 'mobio', "../stylesheets/css/mobio_twitter.css")
Xhtml output:
<head><meta http-equiv="Content-Type" content="text/xhtml; charset=UTF-8" /> <link href="../stylesheets/css/mobio_twitter.css" rel="stylesheet" type="text/css" /> <title>mobio</title></head><body> </body>
Create html img tag.
Create user input field.
generates the xhtml:
<input type="text" name="name" value="john"/>
@xml.input(f, "password", "", "password")
generates the xhtml:
<input type="password" name="password" value=""/>
@xml.input(f, "submit", "Login", "submit")
generates a submit button:
<input type="submit" name="submit" value="Login"/>
Create table tag
Create a text box. To apply style for text, wrap the tag with xml tag. Extra html style (cols, rows, etc.) can be specified in the hash variable options.
@xml.textare(body, "some text", :style=>'class="white"', :xstyle=>'height="3ex" style="white"')
generates the following xhtml code:
<textarea class="white" name="">some text</textarea>