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

Included Modules

Singleton

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.

Examples

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

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‘
  4. req_id: not used in html client
  5. replace_id: not used in html client

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

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

  • :xstyle — specifies xforms style attributes as a string
  • :xpath — specifies the xpath of the input data in the model

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. href: the link url
  2. txt: text displayed in the link

Options

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

Not implemented for xhtml client

Line break

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]