Class: Rmobio::Rxml::XformsTransformer
- Inherits:
-
BaseTransformer
- Object
- Builder::XmlMarkup
- BaseTransformer
- Rmobio::Rxml::XformsTransformer
- 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>
<model></model></head>
<body style="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
Instance Method Summary collapse
-
#action_tag(doc, event = "DOMActivate") {|doc| ... } ⇒ Object
Create Action control.
-
#back_tag(doc) ⇒ Object
Create back control to go back to previous page.
-
#body(doc, title = "", style = nil) {|doc| ... } ⇒ Object
Generate xthml head and body tag.
-
#button(doc, url, label, options = {}, &block) ⇒ Object
Create button control.
- #cell(doc, style = nil, xstyle = 'style="item"') {|doc| ... } ⇒ Object
-
#doctype(xml) {|xml| ... } ⇒ Object
Generate standdard xforms document header.
-
#exit_tag(doc) ⇒ Object
Create exit control to exit the client.
-
#form(doc, id, action, method) {|doc| ... } ⇒ Object
Not supported for xforms client.
- #hstack(doc, xstyle = 'height="0"') {|doc| ... } ⇒ Object
-
#image(doc, src = nil, options = {}) ⇒ Object
Create image widget.
-
#input(doc, id, value, type, options = {}) ⇒ Object
Create user input field.
-
#instance_tag(doc, id, src = nil, &block) ⇒ Object
Create an instance in the model 1.
- #itemlist(doc, id, style = nil, xstyle = nil) {|doc| ... } ⇒ Object
- #itemset(doc, id, nodeset, style = "", xstyle = "") {|doc| ... } ⇒ Object
-
#link(doc, url, txt = "", options = {}, &block) ⇒ Object
There’s no link widget in Mobio client so use a button widget to provide the same feature for html link.
-
#list(doc, style = nil, xstyle = 'style="slist"') {|doc| ... } ⇒ Object
Create slist control.
-
#load_tag(doc, resource) ⇒ Object
Create <xf:load> control to do a HTTP get for a new form.
-
#menu(doc, label, accesskey = nil, xstyle = nil, &block) ⇒ Object
Create an action item in a popup menu.
-
#menus(doc, id, label = "Options", xstyle = nil) {|doc| ... } ⇒ Object
A holders for a popup menu.
-
#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.
-
#model_tag(doc, txt) ⇒ Object
Output arbitray stuff in the model buffer.
- #row(doc, id, nodeset, style = nil, xstyle = 'col="auto"') {|doc| ... } ⇒ Object
- #row_list(doc, id, style = "", xstyle = "") {|doc| ... } ⇒ Object
-
#softBr(doc) ⇒ Object
Line break.
-
#softkey(doc, position = "1", label = "", refid = nil, &block) ⇒ Object
Create a softkey menu.
-
#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).
-
#switch(doc) {|doc| ... } ⇒ Object
Create swtich case control, similar to Tab control but without the tab UI.
-
#syscall(doc, name, address = nil, address_ref = nil, message = nil, message_ref = nil) ⇒ Object
Create syscall control.
-
#tab(doc, xstyle = 'width="100%" height="100%" style="tabbody"') {|doc| ... } ⇒ Object
Create a Tab control 1.
-
#table(doc, style = "", xstyle = "") {|doc| ... } ⇒ Object
Create grid control, similar to table in html 1.
-
#text(doc, txt = "", options = {}) ⇒ Object
Produce a text string.
- #text_line(doc, txt = "", options = {}) ⇒ Object
-
#textarea(doc, txt = "", options = {}) ⇒ Object
Produce a textoutput widget (multi line text box).
-
#toggle_tag(doc, name = "main") ⇒ Object
Create toggle control 1.
-
#view_tag(doc, txt) ⇒ Object
Output arbitray stuff in the view buffer.
- #vstack(doc, xstyle = 'height="0"') {|doc| ... } ⇒ Object
-
#xcase(doc, id, label = nil, xstyle = nil) {|doc| ... } ⇒ Object
Create a case control.
Methods inherited from BaseTransformer
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>
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 1077 def method_missing(sym, *, &block) text = nil attrs = nil sym = "#{sym}:#{options.shift}" if .first.kind_of?(Symbol) .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.
-
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>
1007 1008 1009 1010 1011 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 1007 def action_tag(doc, event="DOMActivate") @view_buffer << "<xf:action ev:event=\"#{event}\">" yield doc @view_buffer << '</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>
1036 1037 1038 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 1036 def back_tag(doc) @view_buffer << "<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.
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 style=\"body\">" yield doc @view_buffer << '<m:footer style="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.
-
url: the http get url when user press the button, only valid if there’s\
no call block
-
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: 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: height="1ex"><m:label>Twitter</m:label>
<xf:toggle case="page2" ev:event="DOMActivate"/>
</m:button>
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 496 def (doc, url, label, ={}, &block) @view_buffer << "\n<m:button" if [:xstyle] @view_buffer << ' ' << [: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, style = nil, xstyle = 'style="item"') {|doc| ... } ⇒ Object
672 673 674 675 676 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 672 def cell(doc, style=nil, xstyle='style="item"') @view_buffer << "<m:item #{xstyle}>" yield doc @view_buffer << '</m:item>' 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.
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<model>" # basic_styles yield xml @model_buffer << "</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>
1022 1023 1024 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 1022 def exit_tag(doc) @view_buffer << "<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.
416 417 418 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 416 def form(doc, id, action, method) yield doc end |
#hstack(doc, xstyle = 'height="0"') {|doc| ... } ⇒ Object
638 639 640 641 642 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 638 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.
-
src: the url of the image
-
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.
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 562 def image(doc, src=nil, ={}) = "image" = [:widget] if [:widget] @view_buffer << "\n<m:#{widget} #{options[:xstyle]}" # if id, get the image from predefined instance data, otherwise, just # use the src path if [: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.
-
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’.
-
value: initial value that will be displayed when ui is loaded
-
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", )
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.
306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 306 def input(doc, id, value, type, ={}) # Create model instance only when there's no xpath if [: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 [:xpath].nil? @view_buffer << "txt\"/>" else @view_buffer << [:xpath] << "\"/>" end end |
#instance_tag(doc, id, src = nil, &block) ⇒ Object
Create an instance in the model
-
id: the name of the instance that will be created
-
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="admin@foo.com">Meeting reminder</email>
<email id ="3" date="4/2" read="1" check="" from="customerservice@amazon.com">Your account activities</email>
</data>
622 623 624 625 626 627 628 629 630 631 632 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 622 def instance_tag(doc, id, src=nil, &block) if src.nil? @model_buffer << "\n<xf:instance id=\"#{id}\"><data xmlns=\"\">" if block yield doc end @model_buffer << '</data></xf:instance>' else @model_buffer << "\n<xf:instance src=\"#{src}\"/>" end end |
#itemlist(doc, id, style = nil, xstyle = nil) {|doc| ... } ⇒ Object
667 668 669 670 671 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 667 def itemlist(doc, id, style=nil, xstyle=nil) @view_buffer << "<m:itemlist id=\"#{id}\" #{xstyle}>" yield doc @view_buffer << '</m:itemlist>' end |
#itemset(doc, id, nodeset, style = "", xstyle = "") {|doc| ... } ⇒ Object
662 663 664 665 666 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 662 def itemset(doc, id, nodeset, style="", xstyle="") @view_buffer << "<m:itemset id=\"#{id}\" nodeset=\"#{nodeset}\" #{xstyle}>" yield doc @view_buffer << '</m:itemset>' end |
#link(doc, url, txt = "", options = {}, &block) ⇒ Object
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.
-
url: the http get url when user press the button, only valid if there’s\
no call block
-
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: 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: height="1ex"><m:label>Twitter</m:label>
<xf:toggle case="page2" ev:event="DOMActivate"/>
</m:button>
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 449 def link(doc, url, txt="", ={}, &block) @view_buffer << "\n<m:button" if [:xstyle] @view_buffer << ' ' << [: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, style = nil, xstyle = 'style="slist"') {|doc| ... } ⇒ Object
Create slist control.
678 679 680 681 682 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 678 def list(doc, style=nil, xstyle='style="slist"') @view_buffer << "\n<m:slist #{xstyle}>" yield doc @view_buffer << '</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”.
-
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>
920 921 922 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 920 def load_tag(doc, resource) @view_buffer << "<xf:load resource=\"#{resource}\" ev:event=\"DOMActivate\"/>" end |
#menu(doc, label, accesskey = nil, xstyle = nil, &block) ⇒ Object
Create an action item in a popup menu.
-
label: what is displayed on the title of the popup window. Default label \
is “Options”.
-
accesskey: A short cut key (0-9) that is assigned to this menu item. If \
not specified, it is asssinged a number sequentially.
-
xstyle: the xforms style string for the menu item. If xstyle is not \
specified, default style string “style=‘optionmenu’” is used.
Examples
Refer to softkey examples
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 886 def (doc, label, accesskey=nil, xstyle=nil, &block) @view_buffer << "<m:item height=\"1ex\" accesskey=\"" if accesskey @view_buffer << accesskey else @view_buffer << "#{@accesskey+=1}" end @view_buffer << "\">" if xstyle @view_buffer << " style=\"#{xstyle}\"" else @view_buffer << " style=\"optionmenu\"" end @view_buffer << "<m:output style=\"label\">" << label << "</m:output>" if block yield doc end @view_buffer << "</m:item>" end |
#menus(doc, id, label = "Options", xstyle = nil) {|doc| ... } ⇒ Object
A holders for a popup menu.
-
id: the widget’s reference id. The id is used by softkey to trigger the popup\
action.
-
label: what is displayed on the title of the popup window. Default label \
is “Options”.
-
xstyle: the xforms style string for the popup window. If xstyle is not \
specified, default style string “width=‘40%’ style=‘popup-menu’” is used.
Examples
Refer to softkey examples
856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 856 def (doc, id, label="Options", xstyle=nil) @view_buffer << "<m:menu id=\"#{id}\" height=\"0\"" if xstyle @view_buffer << " #{xstyle}>" else @view_buffer << " width=\"40%\" style=\"popup-menu\">" end @view_buffer << "<m:hstack height=\"1ex\" style=\"title\"><m:icon>jar://img/option.png</m:icon>" @view_buffer << "<m:output style=\"option\">#{label}</m:output></m:hstack>" @accesskey=0 @view_buffer << "<m:itemlist height=\"0\" style=\"menu\"> " yield doc @view_buffer << "</m:itemlist>" @view_buffer << "<m:softkey position=\"3\"/> <m:softkey position=\"1\"><m:hide-popup ev:event=\"DOMActivate\" refid=\"#{id}\" /> <m:label>Close</m:label></m:softkey></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.
515 516 517 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 515 def model_tag(doc, txt) @model_buffer << txt end |
#row(doc, id, nodeset, style = nil, xstyle = 'col="auto"') {|doc| ... } ⇒ Object
651 652 653 654 655 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 651 def row(doc, id, nodeset, style=nil, xstyle='col="auto"') @view_buffer << "<m:rowset id=\"#{id}\" nodeset=\"#{nodeset}\" #{xstyle}>" yield doc @view_buffer << '</m:rowset>' end |
#row_list(doc, id, style = "", xstyle = "") {|doc| ... } ⇒ Object
656 657 658 659 660 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 656 def row_list(doc, id, style="", xstyle="") @view_buffer << "<m:rowlist id=\"#{id}\" #{xstyle}>" yield doc @view_buffer << '</m:rowlist>' end |
#softBr(doc) ⇒ Object
Line break
524 525 526 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 524 def softBr(doc) @view_buffer << '<m:hstack height="1ex"/>' end |
#softkey(doc, position = "1", label = "", refid = nil, &block) ⇒ Object
Create a softkey menu.
-
position: “1” for left softkey and “3” for right softkey
-
label: what is displayed in the tab header (only needed in tab case)
-
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.(body, "menu1", "Options") do ||
@xml.(, "move1") do |item|
@xml.load_tag(item, "foo1.xml")
end
@xml.(, "move2") do |item|
@xml.load_tag(item, 'foo2.xml')
end
@xml.(, "move3")
@xml.(, "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%" style="popup-menu">
<m:hstack height="1ex" style="title"><m:icon>jar://img/option.png</m:icon>
<m:output style="option">Options</m:output>
</m:hstack>
<m:itemlist height="0" style="menu">
<m:item style="optionmenu" height="1ex" accesskey="1">
<m:output style="label">move1</m:output>
<xf:load resource="foo1.xml" ev:event="DOMActivate"/>
</m:item>
<m:item style="optionmenu" height="1ex" accesskey="2">
<m:output style="label">move2</m:output>
<xf:load resource="foo2.xml" ev:event="DOMActivate"/>
</m:item>
<m:item style="optionmenu" height="1ex" accesskey="3">
<m:output style="label">move3</m:output>
</m:item>
<m:item style="optionmenu" height="1ex" accesskey="0">
<m:output style="label">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>
835 836 837 838 839 840 841 842 843 844 845 846 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 835 def softkey(doc, position="1", label="", refid=nil, &block) @view_buffer << "<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 << '</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).
-
id: the name of the model instance that contains the submission defintion
-
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.
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 386 def submit_tag(doc, id, create_instance, ={}, &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 [: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 [:event].nil? @view_buffer << "DOMActivate" else @view_buffer << [: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>
741 742 743 744 745 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 741 def switch(doc) @view_buffer << "<m:switch>" yield doc @view_buffer << '</m:switch>' end |
#syscall(doc, name, address = nil, address_ref = nil, message = nil, message_ref = nil) ⇒ Object
Create syscall control. Refer to mobio client user manual for details usage of sysacll.
-
name: the name of the syscall function. The client supports “click2call”,
“sendSMS”, “audio-playback” and “video-playback” functions.
-
address: specifify the value for param tag in syscall
-
address_ref: specify the xpath for the address param tag in syscall
-
message: specifify the value for param tag in syscall
-
message_ref: specifify the xpath for the message param tag in syscall
Examples
-
Create a button that plays an audio file, the url for the audio file should\
be defined using an instance tag.
@xml.(body,"", "btn1") do |btn|
@xml.syscall(btn, "audio-playback", nil, "instance('audios')/items/item[1]")
end
generates the following:
<m: 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.(body,"", "btn1") do |btn| @xml.syscall(btn, "click2call", nil, "instance('phone')/number") end @xml.(body,"", "btn2") do |btn| @xml.syscall(btn, "click2call", "tel:5551212") end
generates the following:
In model
<xf:instance id="phone">
<data xmlns="">
<number>tel:5551212</number>
</data>
</xf:instance>
In view
<m: 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>
<m:button height="1ex">
<m:label>btn2</m:label>
<m:syscall name="click2call" ev:event="DOMActivate">
<m:param name="address">tel:5551212</m:param>
</m:syscall>
</m:button>
When user selects the button “btn1” or “btn2”, it places a phone call to the number. The syscall for btn1 uses the phone number from instance data.
982 983 984 985 986 987 988 989 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 982 def syscall(doc, name, address=nil, address_ref=nil, =nil, =nil) @view_buffer << "<m:syscall name=\"#{name}\" ev:event=\"DOMActivate\">" @view_buffer << "<m:param name=\"address\">#{address}</m:param>" if address @view_buffer << "<m:param name=\"address\" ref=\"#{address_ref}\"/>" if address_ref @view_buffer << "<m:param name=\"message\">#{message}</m:param>" if @view_buffer << "<m:param name=\"message\" ref=\"#{message_ref}\"/>" if @view_buffer << '</m:syscall>' end |
#tab(doc, xstyle = 'width="100%" height="100%" style="tabbody"') {|doc| ... } ⇒ Object
Create a Tab control
-
xstyle: the xforms style string. If xstyle is not specified, the default\
value ‘height=“100% width=”100% style=“tabbody”’ will be used. You need to \ define a style class “tabbody” if you want to style the widget. \ 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%" style="tabbody">
<m:case id="first" label="Current Match" >
<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>
711 712 713 714 715 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 711 def tab(doc, xstyle='width="100%" height="100%" style="tabbody"') @view_buffer << "<m:tab #{xstyle}>" yield doc @view_buffer << '</m:tab>' end |
#table(doc, style = "", xstyle = "") {|doc| ... } ⇒ Object
Create grid control, similar to table in html
-
style: html styles
-
xstyle: xforms styles
646 647 648 649 650 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 646 def table(doc, style="", xstyle="") @view_buffer << "\n<m:grid #{xstyle}>" yield doc @view_buffer << '</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.
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') endend
generates the following xforms:
<m:itemset id="tb1" nodeset="instance('audios')/items/item" >
<m:item style="item">
<m:output style="label" ref="@name"/>
</m:item>
</m:itemset>
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 170 def text(doc, txt="", ={}) # If there's id but no xpath, we will create a default instance data for # the textoutput. if [:id] and [:xpath].nil? @model_buffer << "\n" << '<xf:instance id="' << [:id] << '"><data xmlns=""><text>' << txt << "</text></data></xf:instance>\n" end if [:xstyle] @view_buffer << "\n<m:output #{options[:xstyle]}" else # Default one line text @view_buffer << "\n<m:output height=\"1ex\"" end if [:id] xpath = "text" xpath = [:xpath] if [:xpath] @view_buffer << " ref=\"instance('" << [:id] << "')/#{xpath}\"/>" else # If there's an xpath but no id, this is a relative pace, don't create any instance. if [:xpath] @view_buffer << ' ref="' << [:xpath] << '"/>' else @view_buffer << ">" << txt << "</m:output>" end end end |
#text_line(doc, txt = "", options = {}) ⇒ Object
195 196 197 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 195 def text_line(doc, txt="", ={}) text(doc, txt, ) end |
#textarea(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.textarea(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.textarea(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.textarea(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.textarea(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"/>
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 240 def textarea(doc, txt="", ={}) # If there's id but no xpath, we will create a default instance data for # the textoutput. if [:id] and [:xpath].nil? @model_buffer << "\n" << '<xf:instance id="' << [:id] << '"><data xmlns=""><text>' << txt << "</text></data></xf:instance>\n" end @view_buffer << "\n<m:textoutput #{options[:xstyle]}" if [:id] @view_buffer << " ref=\"instance('" << [:id] << "')/" if [:xpath] @view_buffer << [: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
-
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"/>
1054 1055 1056 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 1054 def toggle_tag(doc, name="main") @view_buffer << "<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.
520 521 522 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 520 def view_tag(doc, txt) @view_buffer << txt end |
#vstack(doc, xstyle = 'height="0"') {|doc| ... } ⇒ Object
633 634 635 636 637 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 633 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.
-
id: the case reference id
-
label: what is displayed in the tab header (only needed in tab case)
-
xstyle: the xforms style string for the case (only needed in tab case).\
if not defined, default style=“tab” will be applied.
754 755 756 757 758 759 760 761 762 763 764 |
# File 'lib/rmobio/rxml/xforms_transformer.rb', line 754 def xcase(doc, id, label=nil, xstyle=nil) @view_buffer << "<m:case id=\"#{id}\" label=\"#{label}\"" if xstyle @view_buffer << " #{xstyle}" else @view_buffer << ' style="tab"' end @view_buffer << '>' yield doc @view_buffer << '</m:case>' end |