Class: Rmobio::Rxml::XformsTransformer

Inherits:
BaseTransformer
  • Object
show all
Includes:
Singleton
Defined in:
lib/rmobio/rxml/xforms_transformer.rb

Overview

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:

<html id="root" xmlns="http://www.w3.org/1999/xhtml"

xmlns:xf=“www.w3.org/2002/xforms” xmlns:m=“www.mobio.com/ext

xmlns:xsd="http://www.w3.org/2001/XMLSchema"

xmlns:ev=“www.w3.org/2001/xml-events”>

<head>
<xf:model></xf:model></head>

<body">
<m:image height="5ex" width="100%">http://localhost:3000/images/rails.png</m:image>
<m:hstack height="1ex"/>
<m:output height="1ex">My test app</m:output></body></html>

A rails icon and some text will be displayed on Mobio runner when you load the rxml page.

Instance Attribute Summary

Attributes inherited from BaseTransformer

#model_buffer, #view_buffer

Instance Method Summary collapse

Methods inherited from BaseTransformer

#initialize, #transform

Constructor Details

This class inherits a constructor from Rmobio::Rxml::BaseTransformer

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *options, &block) ⇒ Object

Override builder method_missing method to send output to model buffer so we can create arbitrary xml tags in the model. Typically combine with instance_tag to create model instance that can be used in any of the action tag (link, submit_tag, etc.)

Examples

@xml.instance_tag(body, "user") do |y| 
  @xml.fname 
  @xml.lname("Doe")
  @xml.info("Basic", :zip=>"95014", :phone=>"415-1111111")  
end

generates an instance data in the model:

<xf:instance id="user">
  <data xmlns="">
    <fname/>
    <lname>Doe</lname>
    <info phone="415-1111111" zip="95014">Basic</info>
  </data>
</xf:instance>


1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 1245

def method_missing(sym, *options, &block)  
  text = nil
  attrs = nil
  sym = "#{sym}:#{options.shift}" if options.first.kind_of?(Symbol)
  options.each do |arg|
    case arg
    when Hash
      attrs ||= {}
      attrs.merge!(arg)
    else
      text ||= ''
      text << arg.to_s
    end
  end
  if block
    unless text.nil?
      raise ArgumentError, "XmlMarkup cannot mix a text argument with a block"
    end
    _indent
    _start_tag(sym, attrs)
    _newline
    _nested_structures(block)
    _indent
    _end_tag(sym)
    _newline
  elsif text.nil?
    _indent
    _start_tag(sym, attrs, true)
    _newline
  else
    _indent
    _start_tag(sym, attrs)
    text! text
    _end_tag(sym)
    _newline
  end 
end

Instance Method Details

#action_tag(doc, event = "DOMActivate") {|doc| ... } ⇒ Object

Create Action control. Default event is “DOMActivate” if event argument is not defined.

  1. event: the name of DOM event to trigger the action. Refer to Mobio client\

user manual for all event types.

Examples

@xf.action_tag(body) do |a| 
end

generates an action control with default DOM event:

<xf:action ev:event="DOMActivate">
</xf:action>

@xf.action_tag(body, "xforms-ready") do |a| 
end

generates an action control with “xforms-ready” event:

<xf:action ev:event="xforms-ready">
</xf:action>

Yields:

  • (doc)


1175
1176
1177
1178
1179
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 1175

def action_tag(doc, event="DOMActivate")
  @view_buffer << "\n<xf:action ev:event=\"#{event}\">"
  yield doc
  @view_buffer << "\n</xf:action>"
end

#back_tag(doc) ⇒ Object

Create back control to go back to previous page.

Examples

@xml.softkey(body, "3", "back") do |soft1|
  @xml.back_tag(soft1)
end

generates a right softkey that go back to previous page:

<m:softkey position="3">
  <m:label>back</m:label>
  <m:back ev:event="DOMActivate"/>
</m:softkey>


1204
1205
1206
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 1204

def back_tag(doc)
  @view_buffer << "\n<m:back ev:event=\"DOMActivate\"/>"
end

#body(doc, title = "", style = nil) {|doc| ... } ⇒ Object

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:

<style xmlns="http://www.mobio.com/ext" src="default_style.xml"/>

Please note, by default when client sees the src attribute, it is expecting the response content to be sent as ‘application/xml’ not ‘application/mform’ (for complete xforms document). For the styles to work, you will need to handle the url so it sends back the xml content with http content-type header set to ‘application/xml’.

An easier way to include external styles is to output the styles using builder xml (not transformer @xml) variable:

Examples

@xml.body(x, 'mobio') do |body| 
xml << render(:partial=> 'default_style.xml')

The content in the style xml (note, it will be _default_style.xml) will

then be embeded in the final document.

Yields:

  • (doc)


113
114
115
116
117
118
119
120
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 113

def body(doc, title="", style=nil)
  # xforms style is external style 
  @view_buffer << '<style xmlns="http://www.mobio.com/ext" src="' << style << '"/>' if style  
  @view_buffer << "\n<body>" 
  yield doc
  @view_buffer << '<m:footer/>'
  @view_buffer << "</body>" 
end

#button(doc, url, label, options = {}, &block) ⇒ Object

Create button control. If there’s no call block, <xf:load> will be used to invoke the url. Otherwise, the call block will be executed and template can provide specifal action using any of the action tags or view_tag. Default event type is ev:event=“DOMActivate” for the button.

  1. url: the http get url when user press the button, only valid if there’s\

no call block

  1. label: label displayed on the button

Options

  • :xstyle – specifies xforms style attributes like height, width, style, \

etc. as string.

Examples

  • Simple link: @xml.button(body, “m.twitter.com”, “Twitter”)

generate the following xforms:

<m:button height="1ex"><m:label>Twitter</m:label>
  <xf:load ev:event="DOMActivate" resource="http://m.twitter.com"/>
</m:button>
  • Customize action: @xml.button(body, “m.twitter.com”, “Twitter”) do |link|

    @xml.view_tag(link, '<xf:toggle case="page2" ev:event="DOMActivate"/>')
    

    end

generates the following xforms:

<m:button height="1ex"><m:label>Twitter</m:label>
  <xf:toggle case="page2" ev:event="DOMActivate"/>
</m:button>


563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 563

def button(doc, url, label, options={}, &block)  
  @view_buffer << "\n<m:button"
  if options[:xstyle]
    @view_buffer << ' ' << options[:xstyle]
  else 
    @view_buffer << " height=\"1ex\""
  end         
  @view_buffer << '><m:label>' << label << '</m:label>'
    
  # If no action provided, use <xf:load> to load the url
  if block
    yield doc
  else
    @view_buffer << '<xf:load ev:event="DOMActivate" resource="' << url << '"/>'
  end
  @view_buffer << '</m:button>' 
end

#cell(doc, options = {}) {|doc| ... } ⇒ Object

Create <m:item> control.

Options

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

  • :xstyle – specifies xforms style attributes as a string

Yields:

  • (doc)


821
822
823
824
825
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 821

def cell(doc, options={})  
  @view_buffer << "\n<m:item #{options[:xstyle]}>"
  yield doc
  @view_buffer << "\n</m:item>"
end

#click2call(doc, phone) ⇒ Object

Generate a click2call syscall control to a phone number

  1. phone: the phone number for the click2call control

Examples

  • Create a button that triggers a call to the phone number:

    @xml.button(body,"", "btn1") do |btn|
      @xml.click2call(btn, "4085551212")
    end
    

generates the following:

<m:button height="1ex">
  <m:label>btn1</m:label>
  <m:syscall name="click2call" ev:event="DOMActivate">
    <m:param name="address">tel:4085551212</m:param>
  </m:syscall>


1154
1155
1156
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 1154

def click2call(doc, phone)
  @view_buffer << "\n<m:syscall name=\"click2call\" ev:event=\"DOMActivate\">\n\t<m:param name=\"address\">tel:#{phone}</m:param>\n</m:syscall>" 
end

#doctype(xml) {|xml| ... } ⇒ Object

Generate standdard xforms document header. The model output goes to instance variable @model_buffer and view output goes to instance variable view or model buffer (depending on the tag method) and combined to produce the final document.

Yields:

  • (xml)


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 69

def doctype(xml) 
  xml << '<html id="root" xmlns="http://www.w3.org/1999/xhtml"
	xmlns:xf="http://www.w3.org/2002/xforms"
	xmlns:m="http://www.mobio.com/ext"
	xmlns:ext="http://www.mobio.com/ext"
	xmlns:ev="http://www.w3.org/2001/xml-events">'  
    
  @model_buffer = '<head>' 
  @model_buffer << "\n<xf:model>"
  
  # basic_styles
  yield xml 
 
  @model_buffer << "\n</xf:model></head>\n" 
  xml << @model_buffer << @view_buffer  
  xml << "</html>" 
  @view_buffer = ""
  @model_buffer = ""
end

#exit_tag(doc) ⇒ Object

Create exit control to exit the client.

Examples

@xml.softkey(body, "1", "exit") do |soft1|
  @xml.exit_tag(soft1)
end

generates a left softkey that exits the client:

<m:softkey position="1">
  <m:label>exit</m:label>
  <m:exit ev:event="DOMActivate"/>
</m:softkey>


1190
1191
1192
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 1190

def exit_tag(doc)
  @view_buffer << "\n<m:exit ev:event=\"DOMActivate\"/>"
end

#form(doc, id, action, method) {|doc| ... } ⇒ Object

Not supported for xforms client. Just pass the block. Xforsm client should use instance_tag, submit_tag for form submission.

Yields:

  • (doc)


483
484
485
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 483

def form(doc, id, action, method)  
  yield doc  
end

#hstack(doc, xstyle = 'height="0"') {|doc| ... } ⇒ Object

Yields:

  • (doc)


722
723
724
725
726
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 722

def hstack(doc, xstyle='height="0"')
  @view_buffer << "<m:hstack #{xstyle}>" 
  yield doc
  @view_buffer << "</m:hstack>"
end

#image(doc, src = nil, options = {}) ⇒ Object

Create image widget. There are two types of image control: icon and image. See Mobio client user manual for details.

  1. src: the url of the image

  2. options: all other attributes

Options

  • :xstyle – specifies xforms style attributes like height, width, style, \

etc. as string.

  • :widget – specifies the widget to use, “icon” or “image”. Default\

is <image>.

  • :xpath – specifies the xpath of the data instancen that contains \

the image url.

Examples (

  • Create a simple image control\

Note, define the style options outside the doctype block):

img = {:alt=>"Rails", :xstyle=>'height="5ex" width="100%"'} 
@xml.doctype(xml) do |x|
  @xml.body(x, 'default_style.xml') do|body|   
    @xml.image(body, "img1", 'http://localhost:3000/images/rails.png',img)  
  end
end

generates the following xforms:

<m:image height="5ex" width="100%">http://localhost:3000/images/rails.png</m:image>

The image will be scaled to 5 character high on the screen when the page is loaded.

  • This example creates an icon widget which takes the image url from an \

instance variable:

@xml.image(body, 'http://localhost:3000/images/rails.png',
   {:xstyle=>'height="3ex" width="20em"', 
    :xpath=>"instance('img1')/images/url",
    :widget=>"icon"})

generates the following xforms:

<m:icon height="3ex" width="20em" ref="instance('img1')/images/url"></m:icon>

The icon takes the url from an instance named “img1” with xpath /images/url. The instance data has to be defined for the image to be displayed.



629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 629

def image(doc, src=nil, options={}) 
  widget = "image"
  widget = options[:widget] if options[:widget] 
  @view_buffer << "\n<m:#{widget} #{options[:xstyle]}"   
   
  # if id, get the image from predefined instance data, otherwise, just 
  # use the src path
  if options[:xpath]
    @view_buffer << " ref=\"#{options[:xpath]}\">" 
  else 
    @view_buffer << '>' << src 
  end 
     
  @view_buffer << "</m:#{widget}>"
end

#input(doc, id, value, type, options = {}) ⇒ Object

Create user input field.

  1. id: The instance id that will be associated with this input field. An instance data \

will be created automatically in the model if options is not specified. \ The instance is created with only one tag: ‘txt’.

  1. value: initial value that will be displayed when ui is loaded

  2. type: not used for xforms client

Options

  • :xstyle – specifies xforms style attributes as a string

  • :xpath – specifies the xpath of the input data in the model

Examples

  • Create a simple input box: @xml.input(body, “name”, “john”, “text”)

generates the following xforms:

In Model section of the form:

<xf:instance id="name">
  <data xmlns=""><txt>john</txt></data>
</xf:instance>

In View section of the form:

<m:input  height="1ex" ref="instance('name')/txt"/>

Notice the instance data is created automatically because the rxml tag didn’t specify the :xpath argument. Mobio runner will display an input box with default value “john” in the box when the page is launched. User can edit the string in the box and the value will be assinged to the model instance(‘name’)/txt.

  • The next example shows how to create an input tag with predefined instance data:

Note, create the options hash before the beginning of the document) options =

:style=> 'style="white"', 
:xstyle=>'maxlength="10" style="white"',
:xpath=>"images/id"
 @xml.doctype(xml) do |x|
   @xml.body(x, 'mobio', 'default_style.xml') do|body|  
     @xml.input(body, "img", "", "text", options) 
   end
 end

The above rxml generates only the view part in the xforms:

<m:input maxlength="10" style="white" height="1ex" ref="instance('img')/images/id/>

It assumes you already defined an instance ‘img’ in the model with tag /images/id. If the instance data is not defined, you will see a blank input box but you can’t move focus to the box and you can’t enter any text. If the instance model is defined, the input box will come up blank and user can only enter up to 10 characters (defined in maxlength attribute) in the field.



316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 316

def input(doc, id, value, type, options={}) 
  # Create model instance only when there's no xpath
  if options[:xpath].nil?
    @model_buffer << "\n" << '<xf:instance id="' << id << '"><data xmlns=""><txt>' << value << "</txt></data></xf:instance>\n"     
  end 
  @view_buffer << "\n<m:input #{options[:xstyle]} height=\"1ex\" ref=" << "\"instance('" << id << "')/"
  if options[:xpath].nil?
    @view_buffer << "txt\"/>"
  else 
    @view_buffer << options[:xpath] << "\"/>"
  end 
end

#instance_tag(doc, id, src = nil, &block) ⇒ Object

Create an instance in the model

  1. id: the name of the instance that will be created

  2. src: the src of the instance data. If src is specified, the call block

will not be executed.

Examples

  • Create a blank instance:

    @xml.instance_tag(body, "foo")
    

generates the following xforms in the model:

<xf:instance id="foo"><data xmlns=""></data></xf:instance>
  • Combine instance_tag with any xml tag to create a useful instance model:

    @xml.instance_tag(body, "name") do |y| 
      @xml.fname 
      @xml.lname("Doe")
      @xml.info("Basic", :zip=>"95014", :phone=>"415-1111111")  
    end
    

generates the instance data in the model:

<xf:instance id="name">
  <data xmlns="">
    <fname/>
    <lname>Doe</lname>
    <info phone="415-1111111" zip="95014">Basic</info>
  </data>
</xf:instance>
  • Create an instance from a src url. The src url should return the instance \

data with HTTP content-type set to ‘application/xml’. The instance data is \ RELOADED every time the page is requested no matter it’s cached or not. \ This is useful when you want the whole xforms UI cached but a small \ set of instance data be refreshed every time user reloads the page.

@xml.instance_tag(body, "", "get_data")

The rxml generates the following xforms in the model:

<xf:instance id="emails" src="get_data"/>

and the template for url “get_data” returns this: (note the content-type header)

<% headers['Content-Type']='application/xml' %>
<data xmlns="">
  <email id ="1" date="4/3" read="0" check="" from="richard H.">Lunch?</email>
  <email id ="2" date="4/2" read="0" check="" from="[email protected]">Meeting reminder</email>
  <email id ="3" date="4/2" read="1" check="" from="[email protected]">Your account activities</email>
</data>
  • Create an instance with multiple layers:

    @xml.instance_tag(body, “photos”) do |x|

    @xml.items do |y|
      @xml.item("image1")
      @xml.item("image2")
    end
    

    end

generates the following instance in xforms model:

<xf:instance id="photos">
  <data xmlns="">
    <items>
      <item>image1</item>
      <item>image2</item>
    </items>
  </data>
  </xf:instance>


706
707
708
709
710
711
712
713
714
715
716
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 706

def instance_tag(doc, id, src=nil, &block)
  if src.nil?
    @model_buffer << "\n<xf:instance id=\"#{id}\">\n<data xmlns=\"\">\n"
    if block
      yield doc
    end
    @model_buffer << "\n</data></xf:instance>"
  else
    @model_buffer << "\n<xf:instance src=\"#{src}\"/>"
  end
end

#itemlist(doc, id, options = {}) {|doc| ... } ⇒ Object

Create <m:itemlist> control with static data.

  1. id - the widget id

Options

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

  • :xstyle – specifies xforms style attributes as a string

Yields:

  • (doc)


812
813
814
815
816
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 812

def itemlist(doc, id, options={}) 
  @view_buffer << "\n<m:itemlist id=\"#{id}\" #{options[:xstyle]}>"
  yield doc 
  @view_buffer << "\n</m:itemlist>"
end

#itemset(doc, id, nodeset, options = {}) {|doc| ... } ⇒ Object

Create <m:itemset> control which takes a nodeset attribute and iterates

items in the nodese

  1. id - the widget id

  2. nodset - the xpath to the instance data

Options

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

  • :xstyle – specifies xforms style attributes as a string

Yields:

  • (doc)


802
803
804
805
806
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 802

def itemset(doc, id, nodeset, options={})
  @view_buffer << "\n<m:itemset id=\"#{id}\" nodeset=\"#{nodeset}\" #{options[:xstyle]}>"
  yield doc 
  @view_buffer << "\n</m:itemset>"
end

There’s no link widget in Mobio client so use a button widget to provide the same feature for html link. If url is provided and there’s no call block, <xf:load> will be used to invoke the url. Otherwise, the call block will be executed and template can provide specifal action using the action tag. or view_tag. Default event type is ev:event=“DOMActivate” for the button.

  1. url: the http get url when user press the button, only valid if there’s\

no call block

  1. txt: label displayed on the button

Options

  • :xstyle – specifies xforms style attributes like height, width, style, \

etc. as string.

Examples

  • Simple link: @xml.link(body, “m.twitter.com”, “Twitter”)

generate the following xforms:

<m:button height="1ex"><m:label>Twitter</m:label>
  <xf:load ev:event="DOMActivate" resource="http://m.twitter.com"/>
</m:button>
  • Customize action: @xml.link(body, “m.twitter.com”, “Twitter”) do |link|

    @xml.view_tag(link, '<xf:toggle case="page2" ev:event="DOMActivate"/>')
    

    end

generates the following xforms:

<m:button height="1ex"><m:label>Twitter</m:label>
  <xf:toggle case="page2" ev:event="DOMActivate"/>
</m:button>


516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 516

def link(doc, url, txt="", options={}, &block)  
  @view_buffer << "\n<m:button"
  if options[:xstyle]
    @view_buffer << ' ' << options[:xstyle]
  else 
    @view_buffer << " height=\"1ex\""
  end         
  @view_buffer << '><m:label>' << txt << '</m:label>'
    
  # If no action provided, use <xf:load> to load the url
  if block
    yield doc
  else
    @view_buffer << '<xf:load ev:event="DOMActivate" resource="' << url << '"/>'
  end
  @view_buffer << '</m:button>' 
   
end

#list(doc, options = {}) {|doc| ... } ⇒ Object

Create <m:slist> control.

Options

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

  • :xstyle – specifies xforms style attributes as a string

Yields:

  • (doc)


830
831
832
833
834
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 830

def list(doc, options={})  
  @view_buffer << "\n<m:slist #{options[:xstyle]}>"
  yield doc 
  @view_buffer << "\n</m:slist>"
end

#load_tag(doc, resource) ⇒ Object

Create <xf:load> control to do a HTTP get for a new form. Default event is “DOMActivate”.

  1. resource: the resource url that will be loaded.

Examples

@xml.softkey(body, “1”, “GO”) do |soft1|

@xml.load_tag(soft1, "foo2.xml")

end generates the following:

<m:softkey position="1">
 <m:label>GO</m:label>
 <xf:load resource="foo2.xml" ev:event="DOMActivate"/>
</m:softkey>


1056
1057
1058
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 1056

def load_tag(doc, resource)
  @view_buffer << "\n<xf:load resource=\"#{resource}\" ev:event=\"DOMActivate\"/>"
end

Create an action item in a popup menu.

  1. label: what is displayed on the title of the popup window. Default label \

is “Options”.

  1. accesskey: A short cut key (0-9) that is assigned to this menu item. If \

not specified, it is asssinged a number sequentially.

  1. xstyle: the xforms style string for the menu item.

Examples

Refer to softkey examples



1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 1026

def menu(doc, label, accesskey=nil, xstyle=nil, &block) 
  @view_buffer << "\n<m:item height=\"1ex\" accesskey=\""
  if accesskey
    @view_buffer << accesskey
  else 
    @view_buffer << "#{@accesskey+=1}"
  end 
  @view_buffer << " style=\"#{xstyle}\"" if xstyle
  @view_buffer << "\">"
  @view_buffer << "\n<m:output style=\"label\">" << label << "</m:output>"
  if block
    yield doc
  end
  @view_buffer << "\n</m:item>"
end

A holders for a popup menu.

  1. id: the widget’s reference id. The id is used by softkey to trigger the popup\

action.

  1. label: what is displayed on the title of the popup window. Default label \

is “Options”.

  1. xstyle: the xforms style string for the popup window. If xstyle is not \

specified, default style string “width=‘40%’” is used.

Examples

Refer to softkey examples

Yields:

  • (doc)


999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 999

def menus(doc, id, label="Options", xstyle=nil) 
  @view_buffer << "\n<m:menu id=\"#{id}\" height=\"0\""
  if xstyle
    @view_buffer << " #{xstyle}>" if xstyle
  else
    @view_buffer << " width=\"40%\">"
  end
   
  @view_buffer << "\n<m:hstack height=\"1ex\" style=\"title\"><m:icon>jar://img/option.png</m:icon>"
  @view_buffer <<  "\n<m:output style=\"option\">#{label}</m:output></m:hstack>"
  @accesskey=0
 
  @view_buffer << "\n<m:itemlist height=\"0\" style=\"menu\"> "
  yield doc
  @view_buffer << "\n</m:itemlist>"
  @view_buffer << "\n<m:softkey position=\"3\"/>\n<m:softkey position=\"1\">\n\t<m:hide-popup ev:event=\"DOMActivate\" refid=\"#{id}\" />\n\t<m:label>Close</m:label>\n</m:softkey>\n</m:menu>"       
         
end

#model_tag(doc, txt) ⇒ Object

Output arbitray stuff in the model buffer. A workaround for any special xforms tags that are not supported yet in the transformer.



582
583
584
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 582

def model_tag(doc, txt)
  @model_buffer << txt
end

#row(doc, id = nil, nodeset = nil, options = {}) {|doc| ... } ⇒ Object

Create grid rowset control, similar to <tr> in html.

  1. id - the widget id

  2. nodeset - the xpath to the instance data

Options

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

  • :xstyle – specifies xforms style attributes as a string

Yields:

  • (doc)


778
779
780
781
782
783
784
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 778

def row(doc, id=nil, nodeset=nil, options={}) 
  @view_buffer << "<m:rowset id=\"#{id}\" nodeset=\"#{nodeset}\" "
  options[:xstyle] = 'col="auto"' if #{options[:xstyle]}.nil?
  @view_buffer << " #{options[:xstyle]}>"
  yield doc 
  @view_buffer << '</m:rowset>'
end

#row_list(doc, id, options = {}) {|doc| ... } ⇒ Object

Create grid rowlist control. similar to <tr> in html.

  1. id - the widget id

Options

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

  • :xstyle – specifies xforms style attributes as a string

Yields:

  • (doc)


790
791
792
793
794
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 790

def row_list(doc, id, options={})
  @view_buffer << "<m:rowlist id=\"#{id}\" #{options[:xstyle]}>"
  yield doc 
  @view_buffer << '</m:rowlist>'
end

#softBr(doc) ⇒ Object

Line break



591
592
593
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 591

def softBr(doc)
  @view_buffer << '<m:hstack height="1ex"/>'
end

#softkey(doc, position = "1", label = "", refid = nil, &block) ⇒ Object

Create a softkey menu.

  1. position: “1” for left softkey and “3” for right softkey

  2. label: what is displayed in the tab header (only needed in tab case)

  3. xstyle: the xforms style string for the case (only needed in tab case)

Examples

  • Softkey with a load action. The left softkey is created with label “GO” \

and will load page foo2.xml when the softkey is pressed. @xml.softkey(body, “1”, “GO”) do |soft1|

@xml.load_tag(soft1, "foo2.xml")

end generates the following:

<m:softkey position="1">
 <m:label>GO</m:label>
 <xf:load resource="foo2.xml" ev:event="DOMActivate"/>
</m:softkey>
  • Softkey that pops up an Options menu. When right softkey is pressed, a popup\

menu “Options” will display 4 menu items. The first 3 menu items are assigned\ a default accesskey. The last menu item defines its own access key “0” \ which is reserved for exit action. @xml.softkey(body, “3”, “Options”, “menu1”)

@xml.menus(body, "menu1", "Options") do |menus| 
  @xml.menu(menus, "move1") do |item|
    @xml.load_tag(item, "foo1.xml")
  end 
  @xml.menu(menus, "move2") do |item|
    @xml.load_tag(item, 'foo2.xml')
  end 
  @xml.menu(menus, "move3")  
  @xml.menu(menus, "exit", "0") do |item|
    @xml.view_tag(item, '<m:exit ev:event="DOMActivate"/>')
  end 
end

end genereates the following:

<m:softkey position="3">
 <m:label>Options</m:label>
 <m:show-popup refid="menu1" ev:event="DOMActivate" />
</m:softkey>

<m:menu id="menu1" height="0" width="40%">
 <m:hstack height="1ex"><m:icon>jar://img/option.png</m:icon>
   <m:output>Options</m:output>
 </m:hstack>
 <m:itemlist height="0"> 
   <m:item height="1ex" accesskey="1">
     <m:output>move1</m:output>
     <xf:load resource="foo1.xml" ev:event="DOMActivate"/>
   </m:item>
   <m:item height="1ex" accesskey="2">
     <m:output>move2</m:output>
     <xf:load resource="foo2.xml" ev:event="DOMActivate"/>
   </m:item>
   <m:item height="1ex" accesskey="3">
     <m:output>move3</m:output>
   </m:item>
   <m:item height="1ex" accesskey="0">
     <m:output>exit</m:output>
     <m:exit ev:event="DOMActivate"/>
   </m:item>
 </m:itemlist>

 <m:softkey position="3"/>
 <m:softkey position="1">
   <m:hide-popup ev:event="DOMActivate" refid="menu1" />
   <m:label>Close</m:label>
 </m:softkey>
</m:menu>


978
979
980
981
982
983
984
985
986
987
988
989
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 978

def softkey(doc, position="1", label="", refid=nil, &block)
  @view_buffer << "\n<m:softkey position=\"#{position}\"><m:label>#{label}</m:label>"
  
  # If we have a refid, setup a popup for the child menus; otherwise, execute
  # the proc to take action.
  if refid.nil? and block
    yield doc
  else
    @view_buffer << "<m:show-popup refid=\"#{refid}\" ev:event=\"DOMActivate\" />" 
  end 
  @view_buffer << "\n</m:softkey>"
end

#submit_tag(doc, id, create_instance, options = {}, &block) ⇒ Object

Implement xforms <xf:send> in view buffer and <xf:submission> tag in model buffer If argument ‘create_instance’ is set to true, it will create an <xf:submission> instance based on the attributes (see options). Otherwise, it assumes an instance is already defined in the model. The submit_tag can not act along, it has to be associated with a tag with UI (like link tag, button or menu item where user can click on).

  1. id: the name of the model instance that contains the submission defintion

  2. create_instance: true or false, create submission model instance or not.

If set to true, a new model instance will be created.

Options

To create submission model, the following attributes should be specified in options:

  • :action – specifies the url for the action

  • :req_id – specifies the instance id to hold the submission data

  • :replace_id – if specified, the submission replace attribute is\

set to “instance”; otherwise, the submission replace attribute is set to “all”. \ In case of “all”, the client is expecting a complete xforms document in \ response. If it’s “instance”, only the request_id instance data is updated \ with the response data. Note the response header should be set to \ “application/xml” instead of “application/xforms” for “instance” replace.\ See Mobio client user manual for defails.\

  • :event – specifies event type to trigger the <xf:send> action. \

If not defined, “DOMActivate” will be used.

Examples

  • First example demonstrates a submit tag (wrapped in link widget) that \

creates a submit action and submission instance. When user clicks on the link, \ the response will replace only the instance data in “results”. The UI \ doesn’t change.

Create two instances for the submission to hold the request and replace data:

(Request data)
@xml.instance_tag(body, "name") do |y| 
  @xml.fname 
end

(Instance to hold the response data)
@xml.instance_tag(body, "results")

Use link to provide a UI for user to activate the submission, specify true for create_instance argument so a new submission instance data can be created:

@xml.link(body, "http://m.twitter.com", "m.twitter.com")  do |link|
  @xml.submit_tag(link, "login", true, 
   :action=>'login', :req_id=>'name', :replace_id=>'results')
end

generates the following xforms:

In the model:

<xf:submission action="login" method="post" id="login" includenamespaceprefixes="" 
  ref="instance('name')" replace="instance" instance="results"/>

In the view:

<xf:send submission="login" ev:event="DOMActivate"></xf:send>
  • In this example, we will create a submit tag that creates just the submit button\

and use an existing submission instance to invoke the action. The response \ is a complete xforms document which replaces the whole UI:

@xml.link(body, "http://m.twitter.com", "m.twitter.com")  do |link|
  @xml.submit_tag(link, "login", false, 
    :action=>'login', :req_id=>'name', :replace_id=>'results')
end

generates only a view:

<xf:send submission="login" ev:event="DOMActivate"></xf:send>

The submission instance with id “login” must exist for the button to work.



453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 453

def submit_tag(doc, id, create_instance, options={}, &block)
  # The model 
  if create_instance 
    @model_buffer << "\n<xf:submission action=\"#{options[:action]}\" method=\"post\" #{options[:xstyle]}" <<
      " id=\"#{id}\" includenamespaceprefixes=\"\" ref=\"instance('#{options[:req_id]}')\"" 
     
    if options[:replace_id]
      @model_buffer << " replace=\"instance\" instance=\"#{options[:replace_id]}\"" 
    else 
      @model_buffer << ' replace="all"'
    end
    @model_buffer << '/>'
  end
  
  # The view
  @view_buffer << "\n<xf:send submission=\"#{id}\" ev:event=\"" 
  if options[:event].nil?
    @view_buffer <<  "DOMActivate"
  else 
    @view_buffer << options[:event]
  end
  @view_buffer << "\">"  
  if block
    yield doc
  end
  @view_buffer << "</xf:send>"
end

#switch(doc) {|doc| ... } ⇒ Object

Create swtich case control, similar to Tab control but without the tab UI. This tag and xcase tag can create muliple switch case for xforms client to provide multiple UIs in a form that can be toggled back and forth using the xf:toggle command. Refer to client user manual for the usage.

Examples

@xml.switch(body) do |tab|
  @xml.xcase(tab, "b") do |c1|
    @xml.text(c1, "hello world!") 
  end   
  @xml.xcase(tab, "a") do |xcase|
    @xml.text(body, "hello world!") 
  end

end generates the following:

<m:switch>
  <m:case id="b" label="" >
    <m:output height="1ex">hello world!</m:output>
  </m:case>
  <m:case id="a" label="" >
    <m:output height="1ex">hello world!</m:output>
  </m:case>
</m:switch>

Yields:

  • (doc)


891
892
893
894
895
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 891

def switch(doc)
  @view_buffer << "\n<m:switch>"
  yield doc
  @view_buffer << "\n</m:switch>"
end

#syscall(doc, name, params = {}) ⇒ Object

Create syscall control. Refer to mobio client user manual for details usage of sysacll.

  1. name: the name of the syscall function. The client supports “click2call”,

“sendSMS”, “audio-playback”, “video-playback” and saveToPhone functions. \ See Client User Manual for details.

Params

One or more parameters can be added to build the syscall by passing the param \ name and value as a Hash. Avaliable params are:

  • :address – specifies the phone number for click2call and sendSMS \

or the instance data for audio and video url.

  • :message – specifies the text message instance for sms.

  • wallpaper – specifies the wallpaper instance.

  • ringtone – specifies the ringtone instance.

Examples

  • Create a button that plays an audio file, the url for the audio file should\

be defined using an instance tag.

@xml.button(body,"", "btn1") do |btn|
  @xml.syscall(btn, "audio-playback", :address => "instance('audios')/items/item[1]")
end

generates the following:

<m:button height="1ex">
  <m:label>btn1</m:label>
  <m:syscall name="audio-playback" ev:event="DOMActivate">
    <m:param name="address" ref="instance('audios')/items/item[1]"/>
  </m:syscall>
</m:button>

When user selects the button ‘btn1’, the audio file will be loaded and played.

  • Create a button that places a phone call:

    @xml.instance_tag(body, "phone") do |x|
      @xml.number("tel:5551212")
    end
    @xml.button(body,"", "btn1") do |btn|
      @xml.syscall(btn, "click2call", :address => "instance('phone')/number")
    end
    

generates the following:

In model

<xf:instance id="phone">
  <data xmlns="">
    <number>tel:5551212</number>
  </data>
</xf:instance>

In view

<m:button height="1ex">
  <m:label>btn1</m:label>
  <m:syscall name="click2call" ev:event="DOMActivate">
    <m:param name="address" ref="instance('phone')/number"/>
  </m:syscall>
</m:button>

When user selects the button “btn1”, it places a phone call to the number. The syscall for btn1 uses the phone number from instance data.

  • Create a button that saves a ringtone to the device:

    @xml.button(body,"", "btn1") do |btn|
      @xml.syscall(btn, "saveToPhone", :ringtone => "instance('store')/ringtone")
    end
    

generates the following:

<m:button height="1ex">
  <m:label>btn1</m:label>
  <m:syscall name="saveToPhone" ev:event="DOMActivate">
    <m:param name="ringtone" ref="instance('store')/ringtone"/>
  </m:syscall>
</m:button>


1130
1131
1132
1133
1134
1135
1136
1137
1138
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 1130

def syscall(doc, name, params={})
  @view_buffer << "\n<m:syscall name=\"#{name}\" ev:event=\"DOMActivate\">"
  if not params.nil?
    params.keys.each do |x|
      @view_buffer << "\n\t<m:param name=\"#{x}\" ref=\"#{params[x.to_sym]}\"/>"
    end
  end
  @view_buffer << "\n</m:syscall>"
end

#tab(doc, xstyle = 'width="100%" height="100%"') {|doc| ... } ⇒ Object

Create a Tab control

  1. xstyle: the xforms style string.

The tag is always followed by several xcase tags to create a complete UI \ for Tabs.

Examples

Create a tab control that contains 2 case in the tab body and header:

@xml.tab(body) do |tab|
  @xml.xcase(tab, "first", "Current Match", 'style="tab"') do |xcase|
    @xml.text(body, "hello world!")
  end
   @xml.xcase(tab, "2nd", "future", 'style="tab"') do |xcase|
    @xml.text(body, "hello world!")
  end
end

generates the following xforms in the view:

<m:tab width="100%" height="100%">
  <m:case id="first" label="Current Match" style="tab">
    <m:output height="1ex">hello world!</m:output>
  </m:case>
  <m:case id="2nd" label="future" style="tab">
    <m:output height="1ex">Second Page</m:output>
  </m:case> 
</m:tab>

Yields:

  • (doc)


861
862
863
864
865
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 861

def tab(doc, xstyle='width="100%" height="100%"')
  @view_buffer << "\n<m:tab #{xstyle}>"
  yield doc
  @view_buffer << "\n</m:tab>"
end

#table(doc, options = {}) {|doc| ... } ⇒ Object

Create grid control, similar to table in html.

Options

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

  • :xstyle – specifies xforms style attributes as a string

Examples

Create photos instance:
@xml.instance_tag(body, "photos") do |x|
  @xml.items do |y|
    @xml.item("image1", :val=>'1')
    @xml.item("image2", :val=>'2')
  end
end 

Create grid widget:
@xml.table(body) do |tbl|
  @xml.row(tbl, "mylist", "instance('photos')/items/item", :xstyle=>'col="auto"') do |row|
    @xml.cell(row) do |td| 
      @xml.text(td, "", :xpath=>'.')  
      @xml.text(td, "", :xpath=>'@val') 
    end  
  end  
end

Generates the following xforms: In the model:

<xf:instance id="photos">
  <data xmlns="">
    <items><item val="1">image1</item><item val="2">image2</item></items>
  </data>
  </xf:instance>

In the view:

<m:grid>
  <m:rowset id="mylist" nodeset="instance('photos')/items/item"  col="auto">
    <m:item>
      <m:output height="1ex" ref="."/>
      <m:output height="1ex" ref="@val"/>
    </m:item>
  </m:rowset>
</m:grid>

The UI is a table with 2 columns and 2 rows of text data.

Yields:

  • (doc)


767
768
769
770
771
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 767

def table(doc, options={}) 
  @view_buffer << "\n<m:grid #{options[:xstyle]}>"
  yield doc 
  @view_buffer << "\n</m:grid>"
end

#text(doc, txt = "", options = {}) ⇒ Object

Produce a text string. The text displayed can be the txt argument if there’s no :id and :xpath options or it can be the data from model instance specified in :id and :xpath.

Options

  • :xstyle – specifies xforms style attributes like height, width, style,\

etc. as string.

  • :id – specifies the instance id of string. \

If :id is specified but nso :xpath, the method creates an instance data in \ If :id and :xpath are both specified, the method doesn’t create any model instance,\ instead, it assumes there’s an instance with the id and xpath already defined\ and the text widget displays the data in that xpath.

  • :xpath – specifies the xpath of the text string in the instance model.\

If :id is not specified, it assumes a relative path for the text node. \ See the 3rd example. \

  • :value – specifies the value attribute of text widget. \

See the last example

Examples

  • Text widget displays the string of txt argument without creating an instance:

    @xml.text(body, 'My test', :xstyle=>'style="white"')
    

generates the following xforms:

<m:output style="white">My test</m:output>

The outupt is a one line text.

  • Text widget creates a model instance and displays the string from the new instance:

    @xml.text(body, 'My test',
     :id=>'txt1',
     :xstyle=>'style="white"')
    

generates the following xforms: In model:

<xf:instance id="txt1"><data xmlns=""><text>My test</text></data></xf:instance>

In view:

<m:output style="white" ref="instance('txt1')/text"/>
  • Text widget displays string from a pre defined instance:

    @xml.text(body, 'My test', :id=>'txt1', :xpath=>'images/id')
    

generates the following xforms:

<m:output height="1ex" ref="instance('txt1')/images/id"/>
  • Text widget displays string from a pre defined instance in a relative path: @xml.itemset(list, ‘tb1’, “instance(‘audios’)/items/item”) do |row|

    @xml.cell(row)do |cell|
     @xml.text(cell, "", :xpath=>'@name')
    end
    

    end

generates the following xforms:

<m:itemset id="tb1" nodeset="instance('audios')/items/item" >
 <m:item>
  <m:output ref="@name"/>      
 </m:item>
</m:itemset>
  • Text widget displays a string in value attribute:

    @xml.text(cell, "", :value=>"concat('tel:', instance('phones')/number)")
    

generates the following xforms:

<m:output height="1ex" value="concat('tel:', instance('phones')/number)"/>


177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 177

def text(doc, txt="", options={})
  # If there's id but no xpath, we will create a default instance data for 
  # the textoutput.
  if options[:id] and options[:xpath].nil?
    @model_buffer << "\n" << '<xf:instance id="' << options[:id] << '"><data xmlns=""><text>' << txt << "</text></data></xf:instance>\n"           
  end
  if options[:xstyle]    
    @view_buffer << "\n<m:output #{options[:xstyle]}" 
  else 
    # Default one line text
    @view_buffer << "\n<m:output height=\"1ex\""
  end
  if options[:id]
    xpath = "text"
    xpath = options[:xpath] if options[:xpath]
    @view_buffer << " ref=\"instance('" << options[:id] << "')/#{xpath}\"/>" 
  else 
    # If there's an xpath but no id, this is a relative pace, don't create any instance.
    if options[:xpath]
      @view_buffer << ' ref="' << options[:xpath] << '"/>'
    elsif options[:value]
      @view_buffer << " value=\"#{options[:value]}\"/>"
    else 
      @view_buffer << ">" << txt << "</m:output>" 
    end
  end
end

#text_line(doc, txt = "", options = {}) ⇒ Object



204
205
206
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 204

def text_line(doc, txt="", options={})
  text(doc, txt, options)
end

#textarea(doc, id, value, type, options = {}) ⇒ Object

Create multi lines input area. Similar to input tag except input tag only allow a single input line.

  1. id: The instance id that will be associated with this input field. An instance data \

will be created automatically in the model if options is not specified. \ The instance is created with only one tag: ‘txt’.

  1. value: initial value that will be displayed when ui is loaded

  2. type: not used for xforms client

Options

  • :xstyle – specifies xforms style attributes as a string

  • :xpath – specifies the xpath of the input data in the model

Examples

  • Create a simple textarea: @xml.textarea(body, “name”, “john”, “text”)

generates the following xforms:

In Model section of the form:

<xf:instance id="name">
  <data xmlns=""><txt>john</txt></data>
</xf:instance>

In View section of the form:

<m:textarea  height="1ex" ref="instance('name')/txt"/>

Notice the instance data is created automatically because the rxml tag didn’t specify the :xpath argument. Mobio runner will display an input box with default value “john” in the box when the page is launched. User can edit the string in the box and the value will be assinged to the model instance(‘name’)/txt.

  • The next example shows how to create a textarea tag with predefined instance data:

Note, create the options hash before the beginning of the document) options =

:style=> 'style="white"', 
:xstyle=>'height="3ex"',
:xpath=>"images/id"
 @xml.doctype(xml) do |x|
   @xml.body(x, 'mobio', 'default_style.xml') do|body|  
     @xml.textarea(body, "img", "", "text", options) 
   end
 end

The above rxml generates only the view part in the xforms:

<m:textarea height="3ex" ref="instance('img')/images/id/>

It assumes you already defined an instance ‘img’ in the model with tag /images/id. If the instance data is not defined, you will see a blank text box but you can’t move focus to the box and you can’t enter any text. If the instance model is defined, the text box will an initial value set in the instance data.



373
374
375
376
377
378
379
380
381
382
383
384
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 373

def textarea(doc, id, value, type, options={}) 
  # Create model instance only when there's no xpath
  if options[:xpath].nil?
    @model_buffer << "\n" << '<xf:instance id="' << id << '"><data xmlns=""><txt>' << value << "</txt></data></xf:instance>\n"     
  end 
  @view_buffer << "\n<m:textarea #{options[:xstyle]} ref=" << "\"instance('" << id << "')/"
  if options[:xpath].nil?
    @view_buffer << "txt\"/>"
  else 
    @view_buffer << options[:xpath] << "\"/>"
  end 
end

#textoutput(doc, txt = "", options = {}) ⇒ Object

Produce a textoutput widget (multi line text box). The text area is read only for xforms client.

Options

  • :xstyle – specifies xforms style attributes like height, width, style, \

etc. as string.

  • :id – specifies the instance id of string.

If :id is specified but no :xpath, the method creates an instance data in If :id and :xpath are both specified, the method doesn’t create any model instance, instead, it assumes there’s an instance with the id and xpath already defined and the textoutput widget displays the data in that xpath.

  • :xpath – specifies the xpath of the text string in the instance model.

Examples

@xml.textoutput(body, 'My test', {:xstyle=>'style="white" height="2ex"'})

generates the following xforms:

<m:textoutput style="white" height="5ex">My test</m:textoutput>

The output is a 5 character high text box.

Examples

  • Text widget displays the string of txt argument without creating an instance:

    @xml.textoutput(body, 'My test box', :xstyle=>'height="3ex"')
    

generates a 3 line text box:

<m:textoutput height="3ex">My test box</m:textoutput>
  • Text widget creates a model instance and displays the string from the new instance:

    @xml.textoutput(body, 'My test box',
     :id=>'txt1', :xstyle=>'height="3ex"')
    

generates the following xforms: In model:

<xf:instance id="txt1"><data xmlns=""><text>My test</text></data></xf:instance>

In view:

<m:textoutput height="3ex" ref="instance('txt1')/txt"/>
  • Text widget displays string from a pre defined instance:

    @xml.textoutput(body, 'My test', :id=>'txt1', :xpath=>'images/id',
      :xstyle=>'height="5ex" width="50%"')
    

generates the following xforms:

<m:textoutput height="5ex" width="50%" ref="instance('txt1')/images/id"/>


249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 249

def textoutput(doc, txt="", options={})
  # If there's id but no xpath, we will create a default instance data for 
  # the textoutput. 
  if options[:id] and options[:xpath].nil?
    @model_buffer << "\n" << '<xf:instance id="' << options[:id] << '"><data xmlns=""><text>' << txt << "</text></data></xf:instance>\n"
  end
     
  @view_buffer << "\n<m:textoutput #{options[:xstyle]}"   
   
  if options[:id]
    @view_buffer << " ref=\"instance('" << options[:id] << "')/"
    if options[:xpath] 
      @view_buffer << options[:xpath]
    else 
      @view_buffer << "text"
    end  
    @view_buffer << "\"/>" 
  else 
    @view_buffer << ">" << txt << "</m:textoutput>" 
  end 
end

#toggle_tag(doc, name = "main") ⇒ Object

Create toggle control

  1. name: the toggle case name, default is “main” if not defined.

Examples

@xml.softkey(body, "3", "back") do |soft1|
  @xml.toggle_tag(soft1)
end

generates a toggle control to go back to “main” switch case:

<xf:toggle case="main" ev:event="DOMActivate"/> 

@xml.softkey(body, "3", "back") do |soft1|
  @xml.toggle_tag(soft1, "view")
end

generates a toggle control to go back to a switch case named “view”:

<xf:toggle case="view" ev:event="DOMActivate"/>


1222
1223
1224
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 1222

def toggle_tag(doc, name="main")
  @view_buffer << "\n<xf:toggle case=\"#{name}\" ev:event=\"DOMActivate\"/>"
end

#view_tag(doc, txt) ⇒ Object

Output arbitray stuff in the view buffer. A workaround for any special xforms tags that are not supported yet in the transformer.



587
588
589
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 587

def view_tag(doc, txt)
  @view_buffer << txt
end

#vstack(doc, xstyle = 'height="0"') {|doc| ... } ⇒ Object

Yields:

  • (doc)


717
718
719
720
721
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 717

def vstack(doc, xstyle='height="0"')
  @view_buffer << "<m:vstack #{xstyle}>" 
  yield doc
  @view_buffer << "</m:vstack>"
end

#xcase(doc, id, label = nil, xstyle = nil) {|doc| ... } ⇒ Object

Create a case control. This tag cannot act along. It has to be wrapped in either a “switch” tag or a “tab” tag. See the document and examples in tab and switch tag.

  1. id: the case reference id

  2. label: what is displayed in the tab header (only needed in tab case)

  3. xstyle: the xforms style string for the case (only needed in tab case).

Yields:

  • (doc)


903
904
905
906
907
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 903

def xcase(doc, id, label=nil, xstyle=nil)
  @view_buffer << "\n<m:case id=\"#{id}\" label=\"#{label}\" #{xstyle}>"  
  yield doc
  @view_buffer << "\n</m:case>"
end