Method: Mbrao::PublicInterface::ClassMethods#rendering_engine
- Defined in:
-
lib/mbrao/parser.rb,
lib/mbrao/parser.rb,
lib/mbrao/parser.rb
Gets the default rendering engine.
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/mbrao/parser.rb', line 21 module ClassMethods attr_accessor :locale attr_accessor :parsing_engine attr_accessor :rendering_engine # Gets the default locale for mbrao. # # @return [String] The default locale. def locale attribute_or_default(@locale, "en") end # Gets the default parsing engine. # # @return [String] The default parsing engine. def parsing_engine attribute_or_default(@parsing_engine, :plain_text, :to_sym) end # Gets the default rendering engine. # # @return [String] The default rendering engine. def rendering_engine attribute_or_default(@rendering_engine, :html_pipeline, :to_sym) 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. def parse(content, = {}) instance.parse(content, ) 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. def render(content, = {}, context = {}) instance.render(content, , context) end # 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. def as_json(target, keys, = {}) include_empty = ![:exclude_empty].to_boolean exclude = [:exclude].ensure_array(nil, true, true, true, :ensure_string) keys = keys.ensure_array(nil, true, true, true, :ensure_string) (keys - exclude).reduce({}) {|rv, key| value = target.send(key) value = value.as_json if value && value.respond_to?(:as_json) rv[key] = value if include_empty || !value.is_a?(NilClass) rv }.deep_stringify_keys 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. def create_engine(cls, type = :parsing) begin type = :parsing if type != :rendering ::Lazier.find_class(cls, "::Mbrao::#{type.to_s.classify}Engines::%CLASS%").new rescue NameError raise Mbrao::Exceptions::UnknownEngine.new end 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. def instance(force = false) @instance = nil if force @instance ||= Mbrao::Parser.new end private # Returns an attribute or a default value. # # @param attr [Object ]The attribute to return. # @param default_value [Object] The value to return if `attr` is blank. # @param sanitizer [Symbol] An optional method to sanitize the returned value. def attribute_or_default(attr, default_value = nil, sanitizer = :ensure_string) rv = attr.present? ? attr : default_value rv = rv.send(sanitizer) if sanitizer rv end end |