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.



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

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

#nom!Object



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

def nom!
  unless decorators(Nokogiri::XML::Node).include? Nom::XML::Decorators::Terminology
    decorators(Nokogiri::XML::Node) << Nom::XML::Decorators::Terminology
  end

  unless decorators(Nokogiri::XML::NodeSet).include? Nom::XML::Decorators::NodeSet
    decorators(Nokogiri::XML::NodeSet) << Nom::XML::Decorators::NodeSet
  end

  unless decorators(Nokogiri::XML::Document).include? Nom::XML::Decorators::TemplateRegistry
    decorators(Nokogiri::XML::Document) << Nom::XML::Decorators::TemplateRegistry
  end

  decorate!
  self
end

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



23
24
25
26
# File 'lib/nom/xml/nokogiri_extension.rb', line 23

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

#template_registryObject



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

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

#terminologyObject



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

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

#terminology_namespacesObject



28
29
30
# File 'lib/nom/xml/nokogiri_extension.rb', line 28

def terminology_namespaces
  @terminology_namespaces ||= {}
end