Class: Rmobio::Rxml::BaseTransformer
- Inherits:
-
Builder::XmlMarkup
- Object
- Builder::XmlMarkup
- Rmobio::Rxml::BaseTransformer
- Includes:
- Singleton
- Defined in:
- lib/rmobio/rxml/base_transformer.rb
Overview
Provide a base transformer to translate rxml document to xhtml markup. It subclasses the builder library XmlMarkup class so method not defined in this transformer class will inherit methods or method missing from XmlMarkup class. See XmlMarkup for documentation.
Example: In the controller, get the proper transformer class by passing a client type, See TransformerFactory class for supported client types:
require 'rmobio/rxml/transformer_factory'
@xml = TransformerFactory.get_transformer('xhtml')
Here is the view that uses methods to output xhtml document header, an image and some text:
@xml.doctype(xml) do |x|
@xml.body(x, 'mobio') do|body|
@xml.image(body, "img1", 'http://localhost:3000/images/rails.png')
@xml.softBr(body)
body.b do |y|
@xml.text(y, 'My test app')
end
end
end
The above code generates the following xhtml in Firefox:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title>mobio</title></head><body>
<img id="img1" src="http://localhost:3000/images/rails.png" /><br/>
<b>
My test app</b>
</body></html>
Direct Known Subclasses
Instance Attribute Summary collapse
-
#model_buffer ⇒ Object
Returns the value of attribute model_buffer.
-
#view_buffer ⇒ Object
Returns the value of attribute view_buffer.
Instance Method Summary collapse
- #action_tag(doc, event = "DOMActivate") ⇒ Object
- #back_tag(doc) ⇒ Object
-
#body(doc, title = "", style = nil) {|doc| ... } ⇒ Object
Generate xthml head and body tag.
-
#button(doc, url, label, options = {}, &block) ⇒ Object
To be implemented.
- #cell(doc, options = {}) {|doc| ... } ⇒ Object
- #click2call(doc, phone) ⇒ Object
-
#doctype(xml) {|xml| ... } ⇒ Object
Generate standdard xhtml document header.
- #exit_tag(doc) ⇒ Object
-
#form(doc, id, action, method) {|doc| ... } ⇒ Object
Create form tag for submission 1.
- #hstack(doc, xstyle = 'height="0"') {|doc| ... } ⇒ Object
-
#image(doc, src, options = {}) ⇒ Object
Create html img tag.
-
#initialize ⇒ BaseTransformer
constructor
Create a base rxml transformer to transform rxml document to xhtml markup.
-
#input(doc, id, value, type, options = {}) ⇒ Object
Create user input field.
-
#instance_tag(doc, id, src = nil, &block) ⇒ Object
Not implemented for html client, only impemented for xforms client.
- #itemlist(doc, id, options = {}) {|doc| ... } ⇒ Object
- #itemset(doc, id, nodeset, options = {}) {|doc| ... } ⇒ Object
-
#link(doc, url, txt = "", options = {}, &block) ⇒ Object
Create a html link 1.
- #list(doc, options = {}) {|doc| ... } ⇒ Object
- #load_tag(doc, resource) ⇒ Object
- #menu(doc, label, accesskey = nil, &block) ⇒ Object
-
#menus(doc, id, label = "Options", xstyle = nil) ⇒ Object
Implement menus with links.
-
#model_tag(doc, txt) ⇒ Object
Not implemented for xhtml client.
- #row(doc, id = nil, nodeset = nil, options = {}) {|doc| ... } ⇒ Object
- #row_list(doc, id = nil, options = {}) {|doc| ... } ⇒ Object
-
#softBr(doc) ⇒ Object
Line break.
- #softkey(doc, position = "1", label = "", refid = nil, &block) ⇒ Object
- #submit_tag ⇒ Object
- #switch(doc) {|doc| ... } ⇒ Object
- #syscall(doc, name, params = {}) ⇒ Object
-
#tab(doc, xstyle = "") {|doc| ... } ⇒ Object
The following tags are only supported by xforms client.
-
#table(doc, options = {}) {|doc| ... } ⇒ Object
Create table tag ==== Options *
:style
– specifies html, xhtml style attributes as a string *:xstyle
– specifies xforms style attributes as a string. -
#text(doc, txt = "", options = {}) ⇒ Object
Produce a text string.
-
#text_line(doc, txt = "", options = {}) ⇒ Object
Itentical to text except a line break at the end of the text.
-
#textarea(doc, id, value, type, options = {}) ⇒ Object
Create a multi-line textarea, same as textoutput tag.
-
#textoutput(doc, txt = "", options = {}) ⇒ Object
Create a text box.
- #toggle_tag(doc, name = "main") ⇒ Object
-
#transform(xml, client = nil) ⇒ Object
To be implemented.
-
#view_tag(doc, txt) ⇒ Object
Not implemented for xhtml client.
- #vstack(doc, xstyle = 'height="0"') {|doc| ... } ⇒ Object
- #xcase(doc, id, label = nil, xstyle = nil) {|doc| ... } ⇒ Object
Constructor Details
#initialize ⇒ BaseTransformer
Create a base rxml transformer to transform rxml document to xhtml markup
- out
-
Object receiving the markup in xhtml
- @view_buffer
-
buffer to hold the view part of the document
- @model_buffer
-
buffer to hold the model data of the document
Final document is view_buffer + model_buffer for some subclass transformer (XformsTransformer)
69 70 71 72 73 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 69 def initialize @view_buffer = "" @model_buffer = "" super end |
Instance Attribute Details
#model_buffer ⇒ Object
Returns the value of attribute model_buffer.
59 60 61 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 59 def model_buffer @model_buffer end |
#view_buffer ⇒ Object
Returns the value of attribute view_buffer.
59 60 61 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 59 def view_buffer @view_buffer end |
Instance Method Details
#action_tag(doc, event = "DOMActivate") ⇒ Object
374 375 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 374 def action_tag(doc, event="DOMActivate") end |
#back_tag(doc) ⇒ Object
380 381 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 380 def back_tag(doc) end |
#body(doc, title = "", style = nil) {|doc| ... } ⇒ Object
Generate xthml head and body tag. The document title and style src are optional and style path is relative to public/stylesheets.
Examples
@xml.body(x, 'mobio', "css/mobio_twitter.css")
Xhtml output:
<head><meta http-equiv="Content-Type" content="text/xhtml; charset=UTF-8" />
<style>some internal styles are included from mobio_twitter.css
</style>
<title>mobio</title></head><body>
</body>
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 141 def body(doc, title="",style=nil) doc << "\n<head>" if style #doc << "<meta http-equiv=\"Content-Type\" content=\"text/xhtml; charset=UTF-8\" /><link href=\"" + style + "\" rel=\"stylesheet\" type=\"text/css\" />" # user internal style sheet doc << "<style type=\"text/css\">" styles = File::join RAILS_ROOT, 'public/stylesheets/', style if File.file?(styles) file = File.new(styles,"r") doc << file.read(File.size(styles)) file.close() end doc << '</style>' end doc << "<title>#{title}</title></head><body>" yield doc doc << "</body>" end |
#button(doc, url, label, options = {}, &block) ⇒ Object
To be implemented
258 259 260 261 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 258 def (doc, url, label, ={}, &block) doc << "\n<a href=\"#{url}\" #{[:style]}" doc << ">" << label << '</a>' end |
#cell(doc, options = {}) {|doc| ... } ⇒ Object
328 329 330 331 332 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 328 def cell(doc, ={}) doc << "<td #{[:style]}>" yield doc doc << '</td>' end |
#click2call(doc, phone) ⇒ Object
372 373 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 372 def click2call(doc, phone) end |
#doctype(xml) {|xml| ... } ⇒ Object
Generate standdard xhtml document header
121 122 123 124 125 126 127 128 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 121 def doctype(xml) xml << '<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">' yield xml xml << "</html>" end |
#exit_tag(doc) ⇒ Object
378 379 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 378 def exit_tag(doc) end |
#form(doc, id, action, method) {|doc| ... } ⇒ Object
Create form tag for submission
-
id: name of the form
-
action: the action url that is invoked
-
method: http ‘get’ or ‘post’
Examples
@xml.form(@doc, "f1", "login", "post") {}
generates the following xhtml:
<form method="post" action="login" id="f1" >
</form>
236 237 238 239 240 241 242 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 236 def form(doc, id, action, method) doc << "\n<form method=\"" << method.downcase << "\" action=\"" << action << "\" id=\"#{id}\" #{[:style]}>" yield doc doc << '</form>' end |
#hstack(doc, xstyle = 'height="0"') {|doc| ... } ⇒ Object
300 301 302 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 300 def hstack(doc, xstyle='height="0"') yield doc end |
#image(doc, src, options = {}) ⇒ Object
Create html img tag.
-
src: the url of the image
Options
-
:style
– specifies html, xhtml style attributes as a string -
:alt
– html alt attribute
Examples
img = {:alt=>"Rails", :xstyle=>'height="5ex" width="100%"'}
@xml.image(body, 'http://homer.qa.mobiolabs.com/cms/images/default/glp/bn/til/top-wcric.png', img)
generates the following xhtml:
<img
src="http://homer.qa.mobiolabs.com/cms/images/default/glp/bn/til/top-wcric.png"
alt="Rails"/>
286 287 288 289 290 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 286 def image(doc, src, ={}) doc << "\n<img src=\"#{src}\" #{[:style]}" doc << " alt=\"" << [:alt] << "\"" if [:alt] doc << '/>' end |
#input(doc, id, value, type, options = {}) ⇒ Object
Create user input field.
-
id: not used in xhtml client
-
value: initial value that will be displayed when ui is loaded
-
type: html input type attriute, “text”, “password”, “submit”, etc.
Options
-
:style
– specifies html, xhtml style attributes like cols, rows, etc. as a string -
:xstyle
– specifies xforms style attributes like height, width, etc. as a string. -
:xpath
– specifies the xpath of the input data in the model, xforms only.
Examples
-
a text input box
@xml.input(f, "name", "john", "text")
generates the xhtml:
<input type="text" name="name" value="john"/>
-
a password input box
@xml.input(f, "password", "", "password")
generates the xhtml:
<input type="password" name="password" value=""/>
-
a submit button
@xml.input(f, "submit", "Login", "submit")
generates a submit button:
<input type="submit" name="submit" value="Login"/>
217 218 219 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 217 def input(doc, id, value, type, ={}) doc << "\n<input #{[:style]} type=\"" << type << "\" name=\"" << id << "\" value=\"" << value << "\"/>\n" end |
#instance_tag(doc, id, src = nil, &block) ⇒ Object
Not implemented for html client, only impemented for xforms client
292 293 294 295 296 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 292 def instance_tag(doc, id, src=nil, &block) if block yield doc end end |
#itemlist(doc, id, options = {}) {|doc| ... } ⇒ Object
325 326 327 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 325 def itemlist(doc, id, ={}) yield doc end |
#itemset(doc, id, nodeset, options = {}) {|doc| ... } ⇒ Object
322 323 324 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 322 def itemset(doc, id, nodeset, ={}) yield doc end |
#link(doc, url, txt = "", options = {}, &block) ⇒ Object
Create a html link
-
url: the link url
-
txt: text displayed in the link
Options
-
:style
– specifies html, xhtml style attributes as a string
Examples
args= {:xstyle=>'height="1ex" width="20em"', :style=>'class="btm-menu"'}
@xml.link(@doc, "index", "Friends", args)
generates the following xhtml:
<a href="index" class="btm-menu">Friends</a>
253 254 255 256 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 253 def link(doc, url, txt="", ={}, &block) doc << "\n<a href=\"#{url}\" #{[:style]}" doc << ">" << txt << '</a>' end |
#list(doc, options = {}) {|doc| ... } ⇒ Object
333 334 335 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 333 def list(doc, ={}) yield doc end |
#load_tag(doc, resource) ⇒ Object
367 368 369 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 367 def load_tag(doc, resource) doc << resource end |
#menu(doc, label, accesskey = nil, &block) ⇒ Object
360 361 362 363 364 365 366 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 360 def (doc, label, accesskey=nil, &block) doc << "<a href=\"" if block yield doc end doc << "\">" << label << '</a> ' end |
#menus(doc, id, label = "Options", xstyle = nil) ⇒ Object
Implement menus with links
352 353 354 355 356 357 358 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 352 def (doc, id, label="Options", xstyle=nil) doc << "<br/>" if block yield doc end doc << "<br/>" end |
#model_tag(doc, txt) ⇒ Object
Not implemented for xhtml client
263 264 265 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 263 def model_tag(doc, txt) # do nothing end |
#row(doc, id = nil, nodeset = nil, options = {}) {|doc| ... } ⇒ Object
312 313 314 315 316 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 312 def row(doc, id=nil, nodeset=nil, ={}) doc << "<tr #{[:style]}>" yield doc doc << '</tr>' end |
#row_list(doc, id = nil, options = {}) {|doc| ... } ⇒ Object
317 318 319 320 321 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 317 def row_list(doc, id=nil, ={}) doc << "<tr #{[:style]}>" yield doc doc << '</tr>' end |
#softBr(doc) ⇒ Object
Line break
271 272 273 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 271 def softBr(doc) doc.br end |
#softkey(doc, position = "1", label = "", refid = nil, &block) ⇒ Object
346 347 348 349 350 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 346 def softkey(doc, position="1", label="", refid=nil, &block) if block yield doc end end |
#submit_tag ⇒ Object
224 225 226 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 224 def submit_tag() # do nothing, only implemented in xforms end |
#switch(doc) {|doc| ... } ⇒ Object
340 341 342 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 340 def switch(doc) yield doc end |
#syscall(doc, name, params = {}) ⇒ Object
370 371 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 370 def syscall(doc, name, params={}) end |
#tab(doc, xstyle = "") {|doc| ... } ⇒ Object
The following tags are only supported by xforms client
337 338 339 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 337 def tab(doc, xstyle="") yield doc end |
#table(doc, options = {}) {|doc| ... } ⇒ Object
Create table tag
Options
-
:style
– specifies html, xhtml style attributes as a string -
:xstyle
– specifies xforms style attributes as a string
307 308 309 310 311 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 307 def table(doc, ={}) doc << "\n<table #{[:style]}>" yield doc doc << '</table>' end |
#text(doc, txt = "", options = {}) ⇒ Object
Produce a text string. To apply style for text, wrap the tag with xml tag:
Examples
xml.i do |y|
@xml.text(y, "my italic example")
end
Generates the following xhtml code: my italic example
171 172 173 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 171 def text(doc, txt="", ={}) doc << txt end |
#text_line(doc, txt = "", options = {}) ⇒ Object
Itentical to text except a line break at the end of the text
175 176 177 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 175 def text_line(doc, txt="", ={}) doc << txt << "<br/>" end |
#textarea(doc, id, value, type, options = {}) ⇒ Object
Create a multi-line textarea, same as textoutput tag
221 222 223 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 221 def textarea(doc, id, value, type, ={}) doc << "\n<textarea #{[:style]} name=\"#{id}\">" << value << "</textarea>" end |
#textoutput(doc, txt = "", options = {}) ⇒ Object
Create a text box. To apply style for text, wrap the tag with xml tag. Extra html style (cols, rows, etc.) can be specified in the hash variable options.
Options
-
:style
– specifies html, xhtml style attributes like cols, rows, etc. as a string -
:xstyle
– specifies xforms style attributes like height, width, etc. as a string.
Examples
@xml.output(body, "some text",
:style=>'class="white"', :xstyle=>'height="3ex" style="white"')
generates the following xhtml code:
<textarea class="white" name="">some text</textarea>
191 192 193 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 191 def textoutput(doc, txt="", ={}) doc << "\n<textarea #{[:style]} name=\"#{[:id]}\">" << txt << "</textarea>" end |
#toggle_tag(doc, name = "main") ⇒ Object
376 377 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 376 def toggle_tag(doc, name="main") end |
#transform(xml, client = nil) ⇒ Object
To be implemented.
117 118 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 117 def transform(xml, client=nil) end |
#view_tag(doc, txt) ⇒ Object
Not implemented for xhtml client
267 268 269 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 267 def view_tag(doc, txt) # do nothing end |
#vstack(doc, xstyle = 'height="0"') {|doc| ... } ⇒ Object
297 298 299 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 297 def vstack(doc, xstyle='height="0"') yield doc end |
#xcase(doc, id, label = nil, xstyle = nil) {|doc| ... } ⇒ Object
343 344 345 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 343 def xcase(doc, id, label=nil, xstyle=nil) yield doc end |