# # Copyright (C) 2007 Mobio Networks, Inc. # # This program is free software: you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation, either version 3 of the License, or (at your option) any later # version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program. If not, see . # require 'builder/xmlmarkup' require 'rmobio/rxml/base_transformer' require 'singleton' module Rmobio module Rxml =begin rdoc Provide a transformer to translate rxml document to xforms markup for Mobio client. It subclasses BaseTransformer class and overwirtes the tag methods to produce the proper xforms markup. To get xforms transformer, pass the client type 'xf' to TransformerFactory get_transformer method: require 'rmobio/rxml/transformer_factory' @xml = TransformerFactory.get_transformer('xf') or call the instance method to get the instance: require 'rmobio/rxml/xforms_transformer' @xml = XformsTransformer.instance Here is an example rxml view that uses the transformer methods to output xforms document: img = {:alt=>"Rails", :xstyle=>'height="5ex" width="100%"'} @xml.doctimgype(xml) do |x| @xml.body(x, 'mobio') do|body| @xml.image(body, "img1", 'http://localhost:3000/images/rails.png',img) @xml.softBr(body) @xml.text(body, 'My test app') end end The above code generates the following xforms for Mobio runner: http://localhost:3000/images/rails.png My test app A rails icon and some text will be displayed on Mobio runner when you load the rxml page. =end class XformsTransformer < BaseTransformer include Singleton #Generate standdard xforms document header. The model output goes to #instance variable @model_buffer and view output goes to instance variable #@view_buffer. Any tag methods in the call block will be directed to either #view or model buffer (depending on the tag method) and combined to produce #the final document. def doctype(xml) xml << '' @model_buffer = '' @model_buffer << "\n" # basic_styles yield xml @model_buffer << "\n\n" xml << @model_buffer << @view_buffer xml << "" @view_buffer = "" @model_buffer = "" end #Generate xthml head and body tag. The title argument is not used for xforms #client. The style is optional. If style is specified, #it will be added to the xforms style tag with src attribute: # #In rxml: # @xml.body(x, 'mobio', 'default_style.xml') # #generates the following xforms markup: #