Class: Velocity::Instance::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/acceleration/velocity.rb

Overview

Document wraps the XML for an individual Velocity document in order to provide several convenience methods.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Document

Create a new document XML element wrapper



439
440
441
# File 'lib/acceleration/velocity.rb', line 439

def initialize(node)
  @doc = node
end

Instance Attribute Details

#docObject

A handle on the XML of the document



434
435
436
# File 'lib/acceleration/velocity.rb', line 434

def doc
  @doc
end

Instance Method Details

#attribute(name) ⇒ Object

Retrieve a single attribute from the document.

document.attribute "url"


469
470
471
# File 'lib/acceleration/velocity.rb', line 469

def attribute(name)
  doc.attribute name
end

#attributesObject

Retrieve all document attributes



476
477
478
# File 'lib/acceleration/velocity.rb', line 476

def attributes
  doc.attributes
end

#content(name) ⇒ Object

Retrieve a single content.

Warning: This will actually return an array and that array may contain multiple elements if there are multiple contents with the same name attribute.

document.content 'author'
document.content("title").first


460
461
462
# File 'lib/acceleration/velocity.rb', line 460

def content(name)
  doc.xpath "content[@name='#{name}']"
end

#contentsObject

Retrieve all contents



446
447
448
# File 'lib/acceleration/velocity.rb', line 446

def contents
  doc.xpath 'content'
end

#xpath(xpath) ⇒ Object

Direct passthrough of the xpath in order to execute more complex XPath queries on the source document XML.



484
485
486
# File 'lib/acceleration/velocity.rb', line 484

def xpath(xpath)
  doc.xpath xpath
end