Module: Nom::XML::NokogiriExtension

Defined in:
lib/nom/xml/nokogiri_extension.rb

Instance Method Summary collapse

Instance Method Details

#define_template(name, &block) ⇒ Object

Define a new node template with the Nom::XML::TemplateRegistry.

  • name is a Symbol indicating the name of the new template.

  • The block does the work of creating the new node, and will receive a Nokogiri::XML::Builder and any other args passed to one of the node instantiation methods.


51
52
53
# File 'lib/nom/xml/nokogiri_extension.rb', line 51

def define_template name, &block
  self.template_registry.define name, &block
end

#nom!Object

Apply NOM decorators to Nokogiri classes


8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/nom/xml/nokogiri_extension.rb', line 8

def nom!
  decorations = {
    Nokogiri::XML::Node => Nom::XML::Decorators::Terminology,
    Nokogiri::XML::Attr => Nom::XML::Decorators::Terminology,
    Nokogiri::XML::NodeSet => Nom::XML::Decorators::NodeSet,
    Nokogiri::XML::Document => Nom::XML::Decorators::TemplateRegistry
  }
  decorations.each_pair do |host, decorator|
    decorators(host) << decorator unless decorators(host).include? decorator
  end

  decorate!
  self
end

#set_terminology(options = {}, &block) ⇒ Object

Set the terminology accessors for this document


25
26
27
28
29
# File 'lib/nom/xml/nokogiri_extension.rb', line 25

def set_terminology options = {}, &block
  @terminology = Nom::XML::Terminology.new(self, options, &block)
  
  self
end

#template_registryObject


43
44
45
# File 'lib/nom/xml/nokogiri_extension.rb', line 43

def template_registry
  @template_registry ||= Nom::XML::TemplateRegistry.new
end

#terminologyObject


35
36
37
# File 'lib/nom/xml/nokogiri_extension.rb', line 35

def terminology
  @terminology ||= Nom::XML::Terminology.new self
end

#terminology=(terminology) ⇒ Object


39
40
41
# File 'lib/nom/xml/nokogiri_extension.rb', line 39

def terminology= terminology
  @terminology = terminology
end

#terminology_namespacesObject


31
32
33
# File 'lib/nom/xml/nokogiri_extension.rb', line 31

def terminology_namespaces
  @terminology.namespaces
end