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, style = nil, xstyle = nil) {|doc| ... } ⇒ 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, style = nil, xstyle = nil) {|doc| ... } ⇒ Object
- #itemset(doc, id, nodeset, style = "", xstyle = "") {|doc| ... } ⇒ Object
-
#link(doc, url, txt = "", options = {}, &block) ⇒ Object
Create a html link 1.
- #list(doc, style = nil, xstyle = nil) {|doc| ... } ⇒ Object
- #load_tag(doc, resource) ⇒ Object
- #menu(doc, label, accesskey = nil, &block) ⇒ Object
-
#menus(doc, id, label = "Options", &block) ⇒ Object
Implement menus with links.
-
#model_tag(doc, txt) ⇒ Object
Not implemented for xhtml client.
- #row(doc, id = nil, nodeset = nil, style = "", xstyle = "") {|doc| ... } ⇒ Object
- #row_list(doc, id = nil, style = "", xstyle = "") {|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, address = nil, address_ref = nil, message = nil, message_ref = nil) ⇒ Object
-
#tab(doc, xstyle = "") {|doc| ... } ⇒ Object
The following tags are only supported by xforms client.
-
#table(doc, style = "", xstyle = "") {|doc| ... } ⇒ Object
Create table tag 1.
-
#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, 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
368 369 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 368 def action_tag(doc, event="DOMActivate") end |
#back_tag(doc) ⇒ Object
374 375 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 374 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
255 256 257 258 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 255 def (doc, url, label, ={}, &block) doc << "\n<a href=\"#{url}\" #{[:style]}" doc << ">" << label << '</a>' end |
#cell(doc, style = nil, xstyle = nil) {|doc| ... } ⇒ Object
324 325 326 327 328 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 324 def cell(doc, style=nil, xstyle=nil) doc << "<td #{style}>" yield doc doc << '</td>' 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
372 373 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 372 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>
233 234 235 236 237 238 239 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 233 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
297 298 299 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 297 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"/>
283 284 285 286 287 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 283 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
289 290 291 292 293 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 289 def instance_tag(doc, id, src=nil, &block) if block yield doc end end |
#itemlist(doc, id, style = nil, xstyle = nil) {|doc| ... } ⇒ Object
321 322 323 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 321 def itemlist(doc, id, style=nil, xstyle=nil) yield doc end |
#itemset(doc, id, nodeset, style = "", xstyle = "") {|doc| ... } ⇒ Object
318 319 320 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 318 def itemset(doc, id, nodeset, style="", xstyle="") 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>
250 251 252 253 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 250 def link(doc, url, txt="", ={}, &block) doc << "\n<a href=\"#{url}\" #{[:style]}" doc << ">" << txt << '</a>' end |
#list(doc, style = nil, xstyle = nil) {|doc| ... } ⇒ Object
329 330 331 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 329 def list(doc, style=nil, xstyle=nil) yield doc end |
#load_tag(doc, resource) ⇒ Object
363 364 365 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 363 def load_tag(doc, resource) doc << resource end |
#menu(doc, label, accesskey = nil, &block) ⇒ Object
356 357 358 359 360 361 362 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 356 def (doc, label, accesskey=nil, &block) doc << "<a href=\"" if block yield doc end doc << "\">" << label << '</a> ' end |
#menus(doc, id, label = "Options", &block) ⇒ Object
Implement menus with links
348 349 350 351 352 353 354 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 348 def (doc, id, label="Options", &block) doc << "<br/>" if block yield doc end doc << "<br/>" end |
#model_tag(doc, txt) ⇒ Object
Not implemented for xhtml client
260 261 262 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 260 def model_tag(doc, txt) # do nothing end |
#row(doc, id = nil, nodeset = nil, style = "", xstyle = "") {|doc| ... } ⇒ Object
308 309 310 311 312 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 308 def row(doc, id=nil, nodeset=nil, style="", xstyle="") doc << "<tr #{style}>" yield doc doc << '</tr>' end |
#row_list(doc, id = nil, style = "", xstyle = "") {|doc| ... } ⇒ Object
313 314 315 316 317 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 313 def row_list(doc, id=nil, style="", xstyle="") doc << "<tr #{style}>" yield doc doc << '</tr>' end |
#softBr(doc) ⇒ Object
Line break
268 269 270 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 268 def softBr(doc) doc.br end |
#softkey(doc, position = "1", label = "", refid = nil, &block) ⇒ Object
342 343 344 345 346 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 342 def softkey(doc, position="1", label="", refid=nil, &block) if block yield doc end end |
#submit_tag ⇒ Object
221 222 223 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 221 def submit_tag() # do nothing, only implemented in xforms end |
#switch(doc) {|doc| ... } ⇒ Object
336 337 338 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 336 def switch(doc) yield doc end |
#syscall(doc, name, address = nil, address_ref = nil, message = nil, message_ref = nil) ⇒ Object
366 367 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 366 def syscall(doc, name, address=nil, address_ref=nil, =nil, =nil) end |
#tab(doc, xstyle = "") {|doc| ... } ⇒ Object
The following tags are only supported by xforms client
333 334 335 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 333 def tab(doc, xstyle="") yield doc end |
#table(doc, style = "", xstyle = "") {|doc| ... } ⇒ Object
Create table tag
-
style: html styles
-
xstyle: xforms styles
303 304 305 306 307 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 303 def table(doc, style="", xstyle="") 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, 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.textare(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 textarea(doc, txt="", ={}) doc << "\n<textarea #{[:style]} name=\"#{[:id]}\">" << txt << "</textarea>" end |
#toggle_tag(doc, name = "main") ⇒ Object
370 371 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 370 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
264 265 266 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 264 def view_tag(doc, txt) # do nothing end |
#vstack(doc, xstyle = 'height="0"') {|doc| ... } ⇒ Object
294 295 296 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 294 def vstack(doc, xstyle='height="0"') yield doc end |
#xcase(doc, id, label = nil, xstyle = nil) {|doc| ... } ⇒ Object
339 340 341 |
# File 'lib/rmobio/rxml/base_transformer.rb', line 339 def xcase(doc, id, label=nil, xstyle=nil) yield doc end |