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>

Methods

body   button   doctype   form   image   input   instance_tag   link   load_tag   menu   menus   model_tag   new   softBr   softkey   submit_tag   switch   tab   table   table_cell   table_row   text   textarea   transform   view_tag   xcase  

Included Modules

Singleton

Attributes

model_buffer  [RW] 
view_buffer  [RW] 

Public Class methods

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)

Public Instance methods

Generate xthml head and body tag. The document title and style src are optional and style path is relative to public/stylesheets.

Examples

  @xml.body(x, 'mobio', "css/mobio_twitter.css")

Xhtml output:

  <head><meta http-equiv="Content-Type" content="text/xhtml; charset=UTF-8" />
  <style>some internal styles are included from mobio_twitter.css
  </style>
  <title>mobio</title></head><body>
  </body>

Generate standdard xhtml document header

Create form tag for submission

  1. id: name of the form
  2. action: the action url that is invoked
  3. method: http ‘get’ or ‘post‘

Examples

       @xml.form(@doc, "f1", "login", "post") {}

generates the following xhtml:

       <form method="post" action="login" id="f1" >
       </form>

Create html img tag.

  1. id: name of the widget
  2. src: the url of the image

Options

  • :style — specifies html, xhtml style attributes as a string
  • :alt — html alt attribute

Examples

     img = {:alt=>"Rails", :xstyle=>'height="5ex" width="100%"'}
     @xml.image(body, "img1", 'http://homer.qa.mobiolabs.com/cms/images/default/glp/bn/til/top-wcric.png', img)

generates the following xhtml:

     <img id="img1"
       src="http://homer.qa.mobiolabs.com/cms/images/default/glp/bn/til/top-wcric.png"
       alt="Rails"/>

Create user input field.

  1. id: not used in xhtml client
  2. value: initial value that will be displayed when ui is loaded
  3. type: html input type attriute, "text", "password", "submit", etc.

Options

  • :style — specifies html, xhtml style attributes like cols, rows, etc. as a string
  • :xstyle — specifies xforms style attributes like height, width, etc. as a string.
  • :xpath — specifies the xpath of the input data in the model, xforms only.

Examples

  • a text input box
       @xml.input(f, "name", "john", "text")
    

generates the xhtml:

     <input  type="text" name="name" value="john"/>
  • a password input box
       @xml.input(f, "password", "", "password")
    

generates the xhtml:

     <input  type="password" name="password" value=""/>
  • a submit button
       @xml.input(f, "submit", "Login", "submit")
    

generates a submit button:

     <input  type="submit" name="submit" value="Login"/>

Not implemented for html client

Create a html link

  1. url: the link url
  2. txt: text displayed in the link

Options

  • :style — specifies html, xhtml style attributes as a string

Examples

     args= {:xstyle=>'height="1ex" width="20em"', :style=>'class="btm-menu"'}
     @xml.link(@doc, "index", "Friends", args)

generates the following xhtml:

     <a href="index" class="btm-menu">Friends</a>

Not implemented for xhtml client

Line break

The following tags are only supported by xforms client

Create table tag

  1. style: html styles
  2. xstyle: xforms styles

Produce a text string. To apply style for text, wrap the tag with xml tag:

Examples

  xml.i do |y|
      @xml.text(y, "my italic example")
  end

Generates the following xhtml code:

 <i>
 my italic example
 </i>

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.

Options
  • :style — specifies html, xhtml style attributes like cols, rows, etc. as a string
  • :xstyle — specifies xforms style attributes like height, width, etc. as a string.

Examples

  @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>

To be implemented.

Not implemented for xhtml client

[Validate]