Class: Rind::Document
Instance Attribute Summary collapse
-
#base_namespace ⇒ Object
readonly
Returns the value of attribute base_namespace.
-
#dom ⇒ Object
readonly
Returns the value of attribute dom.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(template, options = {}) ⇒ Document
constructor
Parameter template = file system path to the template.
-
#render! ⇒ Object
Renders the Document in place.
-
#root ⇒ Object
Return the root node of the Document.
-
#s(path) ⇒ Object
Xpath search of the root node that returns a list of matching nodes.
-
#sf(path) ⇒ Object
Xpath search returning only the first matching node in the list.
- #to_s ⇒ Object
Methods included from Equality
Constructor Details
#initialize(template, options = {}) ⇒ Document
Parameter
template = file system path to the template
Options
-
base_namespace = namespace
Allows you to provide a namespace to check before falling back to the default Rind namespace.
-
require = array of namespaces
All namespaces that should be rendered must be listed.
-
type = “xml” or “html”
This can be automatically detect based on the file extension. Unknown extensions will default to “xml”.
Example
Rind::Document.new( "template.tpl", {
:type => "html",
:base_namespace => "core",
:require => ["forms","photos"]
})
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rind/document.rb', line 30 def initialize(template, = {}) @template = template raise 'No such template.' if not File.file? @template if [:type] @type = [:type] else @type = case File.extname(@template) when '.html', '.htm' 'html' else 'xml' end end if [:base_namespace] @base_namespace = [:base_namespace] else @base_namespace = ['rind', @type].join(':') end @dom = Rind.parse(@template, @type, @base_namespace, [:require]) end |
Instance Attribute Details
#base_namespace ⇒ Object (readonly)
Returns the value of attribute base_namespace.
5 6 7 |
# File 'lib/rind/document.rb', line 5 def base_namespace @base_namespace end |
#dom ⇒ Object (readonly)
Returns the value of attribute dom.
5 6 7 |
# File 'lib/rind/document.rb', line 5 def dom @dom end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
5 6 7 |
# File 'lib/rind/document.rb', line 5 def template @template end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/rind/document.rb', line 5 def type @type end |
Instance Method Details
#render! ⇒ Object
Renders the Document in place. This will recursively call render!
on all the Document contents.
56 57 58 |
# File 'lib/rind/document.rb', line 56 def render! @dom.collect{|node| node.respond_to?(:render!) ? node.render! : node}.join('') end |
#root ⇒ Object
Return the root node of the Document.
61 62 63 64 65 |
# File 'lib/rind/document.rb', line 61 def root @dom.each do |node| return node if not node.is_a? Rind::DocType end end |
#s(path) ⇒ Object
Xpath search of the root node that returns a list of matching nodes.
72 73 74 |
# File 'lib/rind/document.rb', line 72 def s(path) root.s(path) end |
#sf(path) ⇒ Object
Xpath search returning only the first matching node in the list.
77 78 79 |
# File 'lib/rind/document.rb', line 77 def sf(path) root.sf(path) end |
#to_s ⇒ Object
67 68 69 |
# File 'lib/rind/document.rb', line 67 def to_s @dom.to_s end |