Module: Duxml::RngAttrsRule

Includes:
LazyOx, Ox
Included in:
AttrsRuleClass
Defined in:
lib/duxml/meta/grammar/relax_ng/attrs_rule.rb,
lib/duxml/meta/grammar/relax_ng/attrs_rule.rb

Instance Method Summary collapse

Methods included from LazyOx

#method_missing

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Duxml::LazyOx

Instance Method Details

#relaxng(parent) ⇒ Nokogiri::XML::Node

Returns parent, but with additions of <define><attribute> to parent if does not already exist and <ref> to respective <define><doc>.

Parameters:

  • parent (Nokogiri::XML::Node)

    should be <grammar>

Returns:

  • (Nokogiri::XML::Node)

    parent, but with additions of <define><attribute> to parent if does not already exist and <ref> to respective <define><doc>



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/duxml/meta/grammar/relax_ng/attrs_rule.rb', line 20

def relaxng(parent)
  # TODO this is here just to skip generation from namespaced attributes - fix later!!!
  return parent if attr_name.include?(':')
  # TODO

  # if new attribute declaration needed
  unless parent.Define(name: attr_name).any?
    new_def = Element.new('define')
    new_def[:name] = attr_name
    new_attr_def = Element.new('attribute')
    new_attr_def[:name] = attr_name
    new_def << new_attr_def
    parent << new_def
  end

  # update doc with ref, updating previous <optional> if available
  parent.nodes.reverse.each do |define|
    if define[:name] == subject
      element_def = define.nodes.first
      if requirement == '#REQUIRED'
        cur_element = element_def
      else
        if element_def.nodes.any? and element_def.nodes.last.name == 'optional'
          cur_element = element_def.nodes.last
        else
          cur_element = Element.new('optional')
          element_def << cur_element
        end
      end # if self[:requirement]=='#REQUIRED'
      new_ref = Element.new('ref')
      new_ref[:name] = attr_name
      cur_element << new_ref
      break
    end # if define[:name] == subject
  end # parent.element_children.any?
  parent
end