Module: Moxml::Adapter::CustomizedOga::RawValueOverride

Defined in:
lib/moxml/adapter/customized_oga/raw_value_override.rb

Overview

Bypass Oga's lazy decoder for user-authored values.

Oga::XML::Attribute#value and Oga::XML::Text#text decode @value / @text on first read via Oga::EntityDecoder. EntityDecoderOverride makes that decode single-pass for parsed input. But user-authored values are already data — running them through the decoder again would re-interpret any literal & / &#NN; substrings as entity references. So we route the read through the NativeAttachment sidecar first; if the adapter stored the verbatim value there, we return it as-is, otherwise we fall through to Oga's normal read.

Instance Method Summary collapse

Instance Method Details

#textObject



31
32
33
34
35
36
# File 'lib/moxml/adapter/customized_oga/raw_value_override.rb', line 31

def text
  cached = ::Moxml::Adapter::Oga.attachments.get(self, :raw_text)
  return cached unless cached.nil?

  super
end

#text=(new_value) ⇒ Object



38
39
40
41
# File 'lib/moxml/adapter/customized_oga/raw_value_override.rb', line 38

def text=(new_value)
  ::Moxml::Adapter::Oga.attachments.set(self, :raw_text, new_value)
  super
end

#valueObject



19
20
21
22
23
24
# File 'lib/moxml/adapter/customized_oga/raw_value_override.rb', line 19

def value
  cached = ::Moxml::Adapter::Oga.attachments.get(self, :raw_value)
  return cached unless cached.nil?

  super
end

#value=(new_value) ⇒ Object



26
27
28
29
# File 'lib/moxml/adapter/customized_oga/raw_value_override.rb', line 26

def value=(new_value)
  ::Moxml::Adapter::Oga.attachments.set(self, :raw_value, new_value)
  super
end