Module: ConDuxml
- Defined in:
- lib/con_duxml.rb,
lib/con_duxml/link.rb,
lib/con_duxml/instance.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#src_doc ⇒ Object
readonly
Returns the value of attribute src_doc.
-
#src_ns ⇒ Object
readonly
Returns the value of attribute src_ns.
Attributes included from Transform
Instance Method Summary collapse
-
#instantiate(doc_or_node, opts = {}) ⇒ Doc
instantiation takes a static design file and constructs a dynamic model by identifying certain keyword elements, executing their method on child nodes, then removing the interpolating keyword element.
-
#transform(transforms, doc_or_path, opts = {}) ⇒ Doc
Result of transform; automatically saved to @doc.
Methods included from Transform
#content, #copy, #element, #find_source, #find_transform, #find_xform_event
Methods included from Private
#activate, #add_name_space_prefix, #get_args, #get_method, #get_sources, #normalize_arg, #separate_enumerables
Instance Attribute Details
#src_doc ⇒ Object (readonly)
Returns the value of attribute src_doc.
31 32 33 |
# File 'lib/con_duxml.rb', line 31 def src_doc @src_doc end |
#src_ns ⇒ Object (readonly)
Returns the value of attribute src_ns.
11 12 13 |
# File 'lib/con_duxml.rb', line 11 def src_ns @src_ns end |
Instance Method Details
#instantiate(doc_or_node, opts = {}) ⇒ Doc
instantiation takes a static design file and constructs a dynamic model by identifying certain keyword elements, executing their method on child nodes, then removing the interpolating keyword element. these are:
<instance> - when it contains design elements, it is removed but its reference ID is given to all children creating an XML-invisible arbitrary grouping
when it references an XML file, ID or path to an XML element, the target is copied and inserted in place of this element
<link> - referenced XML file or nodes provides namespace, contents, and notification of changes to any direct children of this node @see ConDuxml::Link
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/con_duxml.rb', line 42 def instantiate(doc_or_node, opts={}) if doc_or_node.is_a?(Element) new_node = doc_or_node.stub new_children = doc_or_node.nodes.collect do |src_node| if src_node.respond_to?(:nodes) src_node.activate.collect do |inst| inst.name.match(/con_duxml:/) ? instantiate(src_node) : instantiate(inst) end else src_node.clone end end.flatten if new_children.any? new_node << new_children end new_node else @src_doc = get_doc doc_or_node instance = instantiate(src_doc.root) @doc = Doc.new << instance end end |
#transform(transforms, doc_or_path, opts = {}) ⇒ Doc
Returns result of transform; automatically saved to @doc.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/con_duxml.rb', line 19 def transform(transforms, doc_or_path, opts={}) @doc = Doc.new transforms = get_doc(transforms).root @src_doc = get_doc doc_or_path @src_ns = transforms[:src_ns] src_node = src_doc.locate(add_name_space_prefix(transforms[:source])).first doc.grammar = transforms[:grammar] if transforms[:grammar] doc.history.strict?(false) if opts[:strict].is_a?(FalseClass) add_observer doc.history @doc << activate(transforms.first, src_node).first end |