module Mbrao::ParserInterface::ClassMethods
Class methods.
@attribute locale
@return [String] The mbrao default locale.
@attribute parsing_engine
@return [String] The default parsing engine.
@attribute rendering_engine
@return [String] The default rendering engine.
Attributes
Public Instance Methods
Returns an object as a JSON compatible hash
@param target [Object] The target to serialize. @param keys [Array] The attributes to include in the serialization. @param options [Hash] Options to modify behavior of the serialization.
The only supported value are: * `:exclude`, an array of attributes to skip. * `:exclude_empty`, if to exclude nil values. Default is `false`.
@return [Hash] An hash with all attributes.
# File lib/mbrao/parser_interface.rb, line 76 def as_json(target, keys, options = {}) include_empty = !options[:exclude_empty].to_boolean exclude = options[:exclude].ensure_array(no_duplicates: true, compact: true, flatten: true, sanitizer: :ensure_string) keys = keys.ensure_array(no_duplicates: true, compact: true, flatten: true, sanitizer: :ensure_string) map_to_json(target, (keys - exclude), include_empty) end
Instantiates a new engine for rendering or parsing.
@param cls [String|Symbol|Object] If a `String` or a `Symbol`, then it will be the class of the engine. @param type [Symbol] The type or engine. Can be `:parsing` or `:rendering`. @return [Object] A new engine.
# File lib/mbrao/parser_interface.rb, line 89 def create_engine(cls, type = :parsing) type = :parsing if type != :rendering ::Lazier.find_class(cls, "::Mbrao::#{type.to_s.classify}Engines::%CLASS%").new rescue NameError raise Mbrao::Exceptions::UnknownEngine end
Returns a unique (singleton) instance of the parser.
@param force [Boolean] If to force recreation of the instance. @return [Parser] The unique (singleton) instance of the parser.
# File lib/mbrao/parser_interface.rb, line 100 def instance(force = false) @instance = nil if force @instance ||= Mbrao::Parser.new end
Parses a source text.
@param content [Object] The content to parse. @param options [Hash] A list of options for parsing. @return [Content] The parsed data.
# File lib/mbrao/parser_interface.rb, line 52 def parse(content, options = {}) instance.parse(content, options) end
Renders a content.
@param content [Content] The content to parse. @param options [Hash] A list of options for renderer. @param context [Hash] A context for rendering. @return [String] The rendered content.
# File lib/mbrao/parser_interface.rb, line 62 def render(content, options = {}, context = {}) instance.render(content, options, context) end