Module: Quarto::TransformationHelper
- Defined in:
- lib/quarto/transformation_helper.rb
Instance Method Summary collapse
-
#transform_xml(element, transformer_class = Quarto::HtmlTransformer, raise_on_unrecognized_element = true) ⇒ Object
Tranforms the children of
elementusing an instance oftransformer_classand returns a string representation of the result.
Instance Method Details
#transform_xml(element, transformer_class = Quarto::HtmlTransformer, raise_on_unrecognized_element = true) ⇒ Object
Tranforms the children of element using an instance of transformer_class and returns a string representation of the result.
transformer_class must be a subclass of Quarto::Transformer or nil. If it’s nil (which is the default), the default subclass will be used. The default subclass is set in generate.rb as follows:
config(:default_transformer_class, YourSubclass)
If you do not specify a default class, HtmlTransformer will be used.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/quarto/transformation_helper.rb', line 17 def transform_xml(element, transformer_class = Quarto::HtmlTransformer, raise_on_unrecognized_element = true) raise ArgumentError, "Expected REXML::Element but got #{element.inspect}" unless element.is_a?(REXML::Element) class_error = "Expected subclass of Tranformer but got #{transformer_class.inspect}" raise ArgumentError, class_error unless transformer_class.is_a?(Class) klass = transformer_class while klass != Quarto::Transformer and klass != Object klass = klass.superclass end raise ArgumentError, class_error unless Quarto::Transformer == klass transformer_class.new.transform(element, raise_on_unrecognized_element) end |