Module: Moxml

Defined in:
lib/moxml/entity_registry_opal_data.rb,
lib/moxml.rb,
lib/moxml/sax.rb,
lib/moxml/node.rb,
lib/moxml/text.rb,
lib/moxml/cdata.rb,
lib/moxml/error.rb,
lib/moxml/xpath.rb,
lib/moxml/config.rb,
lib/moxml/adapter.rb,
lib/moxml/builder.rb,
lib/moxml/comment.rb,
lib/moxml/context.rb,
lib/moxml/doctype.rb,
lib/moxml/element.rb,
lib/moxml/version.rb,
lib/moxml/document.rb,
lib/moxml/node_set.rb,
lib/moxml/attribute.rb,
lib/moxml/namespace.rb,
lib/moxml/xml_utils.rb,
lib/moxml/adapter/ox.rb,
lib/moxml/adapter/oga.rb,
lib/moxml/declaration.rb,
lib/moxml/sax/handler.rb,
lib/moxml/xpath/cache.rb,
lib/moxml/xpath/lexer.rb,
lib/moxml/adapter/base.rb,
lib/moxml/xpath/engine.rb,
lib/moxml/xpath/errors.rb,
lib/moxml/xpath/parser.rb,
lib/moxml/adapter/rexml.rb,
lib/moxml/xpath/context.rb,
lib/moxml/adapter/libxml.rb,
lib/moxml/xpath/ast/node.rb,
lib/moxml/xpath/compiler.rb,
lib/moxml/entity_registry.rb,
lib/moxml/xpath/ruby/node.rb,
lib/moxml/adapter/nokogiri.rb,
lib/moxml/document_builder.rb,
lib/moxml/entity_reference.rb,
lib/moxml/xpath/conversion.rb,
lib/moxml/adapter/headed_ox.rb,
lib/moxml/native_attachment.rb,
lib/moxml/sax/block_handler.rb,
lib/moxml/xml_utils/encoder.rb,
lib/moxml/sax/element_handler.rb,
lib/moxml/xpath/ruby/generator.rb,
lib/moxml/adapter/customized_ox.rb,
lib/moxml/adapter/customized_oga.rb,
lib/moxml/native_attachment/opal.rb,
lib/moxml/processing_instruction.rb,
lib/moxml/sax/namespace_splitter.rb,
lib/moxml/adapter/customized_rexml.rb,
lib/moxml/native_attachment/native.rb,
lib/moxml/adapter/customized_libxml.rb,
lib/moxml/adapter/customized_ox/text.rb,
lib/moxml/adapter/customized_libxml/node.rb,
lib/moxml/adapter/customized_libxml/text.rb,
lib/moxml/adapter/libxml/entity_restorer.rb,
lib/moxml/adapter/customized_libxml/cdata.rb,
lib/moxml/adapter/customized_ox/attribute.rb,
lib/moxml/adapter/customized_ox/namespace.rb,
lib/moxml/adapter/customized_libxml/comment.rb,
lib/moxml/adapter/customized_libxml/element.rb,
lib/moxml/adapter/customized_rexml/formatter.rb,
lib/moxml/adapter/libxml/entity_ref_registry.rb,
lib/moxml/adapter/customized_oga/xml_generator.rb,
lib/moxml/adapter/customized_libxml/declaration.rb,
lib/moxml/adapter/customized_oga/xml_declaration.rb,
lib/moxml/adapter/customized_ox/entity_reference.rb,
lib/moxml/adapter/customized_rexml/entity_reference.rb,
lib/moxml/adapter/customized_libxml/entity_reference.rb,
lib/moxml/adapter/customized_libxml/processing_instruction.rb

Overview

monkey patch the Oga generator because it’s not configurable github.com/yorickpeterse/oga/blob/main/lib/oga/xml/generator.rb

Defined Under Namespace

Modules: Adapter, SAX, XPath, XmlUtils Classes: AdapterError, Attribute, AttributeError, Builder, Cdata, Comment, Config, Context, Declaration, Doctype, Document, DocumentBuilder, DocumentStructureError, Element, EntityReference, EntityRegistry, Error, Namespace, NamespaceError, NativeAttachment, Node, NodeSet, NotImplementedError, ParseError, ProcessingInstruction, SerializationError, Text, ValidationError, XPathError

Constant Summary collapse

VERSION =
"0.1.24"

Class Method Summary collapse

Class Method Details

.configure {|Config.default| ... } ⇒ Object

Yields:



15
16
17
# File 'lib/moxml.rb', line 15

def configure
  yield Config.default if block_given?
end

.new(adapter = nil, &block) ⇒ Object



5
6
7
8
9
# File 'lib/moxml.rb', line 5

def new(adapter = nil, &block)
  context = Context.new(adapter)
  context.config.instance_eval(&block) if block
  context
end

.parse(xml, adapter: nil, **options) ⇒ Object



11
12
13
# File 'lib/moxml.rb', line 11

def parse(xml, adapter: nil, **options)
  Context.new(adapter).parse(xml, options)
end

.preprocess_entities(xml) ⇒ Object



59
60
61
# File 'lib/moxml.rb', line 59

def preprocess_entities(xml)
  Adapter::Base.preprocess_entities(xml)
end

.restore_entities(text) ⇒ Object



63
64
65
# File 'lib/moxml.rb', line 63

def restore_entities(text)
  Adapter::Base.restore_entities(text)
end

.with_config(adapter_name = nil, strict_parsing = nil, default_encoding = nil) ⇒ Object



19
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
57
# File 'lib/moxml.rb', line 19

def with_config(adapter_name = nil, strict_parsing = nil,
                default_encoding = nil)
  original = Config.default
  saved_values = {
    adapter: original.adapter_name,
    strict_parsing: original.strict_parsing,
    default_encoding: original.default_encoding,
    default_indent: original.default_indent,
    default_line_ending: original.default_line_ending,
    entity_load_mode: original.entity_load_mode,
    entity_encoding: original.entity_encoding,
    restore_entities: original.restore_entities,
    namespace_validation_mode: original.namespace_validation_mode,
    entity_restoration_mode: original.entity_restoration_mode,
    preload_entity_sets: original.preload_entity_sets.dup,
  }

  configure do |config|
    config.adapter = adapter_name unless adapter_name.nil?
    config.strict_parsing = strict_parsing unless strict_parsing.nil?
    config.default_encoding = default_encoding unless default_encoding.nil?
  end

  yield if block_given?
ensure
  configure do |config|
    config.adapter = saved_values[:adapter]
    config.strict_parsing = saved_values[:strict_parsing]
    config.default_encoding = saved_values[:default_encoding]
    config.default_indent = saved_values[:default_indent]
    config.default_line_ending = saved_values[:default_line_ending]
    config.entity_load_mode = saved_values[:entity_load_mode]
    config.entity_encoding = saved_values[:entity_encoding]
    config.restore_entities = saved_values[:restore_entities]
    config.namespace_validation_mode = saved_values[:namespace_validation_mode]
    config.entity_restoration_mode = saved_values[:entity_restoration_mode]
    config.preload_entity_sets = saved_values[:preload_entity_sets]
  end
end