Module: Moxml

Defined in:
lib/moxml/adapter/customized_oga/xml_generator.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/xpath/ruby/node.rb,
lib/moxml/adapter/nokogiri.rb,
lib/moxml/document_builder.rb,
lib/moxml/xpath/conversion.rb,
lib/moxml/adapter/headed_ox.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/processing_instruction.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/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/customized_libxml/declaration.rb,
lib/moxml/adapter/customized_oga/xml_declaration.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, Error, Namespace, NamespaceError, Node, NodeSet, NotImplementedError, ParseError, ProcessingInstruction, SerializationError, Text, ValidationError, XPathError

Constant Summary collapse

VERSION =
"0.1.9"

Class Method Summary collapse

Class Method Details

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

Yields:



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

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

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



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/moxml.rb', line 15

def with_config(adapter_name = nil, strict_parsing = nil,
                default_encoding = nil)
  original_config = Config.default.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?

  # restore the original config
  configure do |config|
    config.adapter = original_config.adapter_name
    config.strict_parsing = original_config.strict_parsing
    config.default_encoding = original_config.default_encoding
  end
  original_config = nil
end