Class: Mato::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/mato/config.rb

Constant Summary collapse

DEFAULT_MARKDOWN_PARSE_OPTIONS =
%i[
  DEFAULT
  VALIDATE_UTF8
  FOOTNOTES
].freeze
DEFAULT_MARKDOWN_RENDER_OPTIONS =
[
  :DEFAULT,
  :HARDBREAKS, # convert "\n" as <br/>
  :TABLE_PREFER_STYLE_ATTRIBUTES,
  :UNSAFE,
  # :SOURCEPOS, // TODO: enable it after assertions are supported
].freeze
DEFAULT_MARKDOWN_EXTENSIONS =
%i[
  table
  strikethrough
  autolink
  tagfilter
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/mato/config.rb', line 60

def initialize
  @text_filters = []
  @markdown_filters = []
  @html_filters = []

  @markdown_parser = CommonMarker
  @html_parser = Nokogiri::HTML::DocumentFragment

  @document_factory = Document

  @markdown_extensions = DEFAULT_MARKDOWN_EXTENSIONS
  @markdown_parse_options = DEFAULT_MARKDOWN_PARSE_OPTIONS
  @markdown_render_options = DEFAULT_MARKDOWN_RENDER_OPTIONS
end

Instance Attribute Details

#document_factoryClass<Mato::Document>

Returns:



49
50
51
# File 'lib/mato/config.rb', line 49

def document_factory
  @document_factory
end

#html_filtersArray<Proc>

Returns:

  • (Array<Proc>)


40
41
42
# File 'lib/mato/config.rb', line 40

def html_filters
  @html_filters
end

#html_parserCass<Nokogiri::HTML::DocumentFragment>

Returns:

  • (Cass<Nokogiri::HTML::DocumentFragment>)


46
47
48
# File 'lib/mato/config.rb', line 46

def html_parser
  @html_parser
end

#markdown_extensionsArray<Symbol>

Returns CommonMarker’s parse extensions.

Returns:

  • (Array<Symbol>)

    CommonMarker’s parse extensions



52
53
54
# File 'lib/mato/config.rb', line 52

def markdown_extensions
  @markdown_extensions
end

#markdown_filtersArray<Proc>

Returns:

  • (Array<Proc>)


37
38
39
# File 'lib/mato/config.rb', line 37

def markdown_filters
  @markdown_filters
end

#markdown_parse_optionsArray<Symbol>

Returns CommonMarker’s pars options.

Returns:

  • (Array<Symbol>)

    CommonMarker’s pars options



55
56
57
# File 'lib/mato/config.rb', line 55

def markdown_parse_options
  @markdown_parse_options
end

#markdown_parserClass<CommonMarker]

Returns Class<CommonMarker].

Returns:

  • (Class<CommonMarker])

    Class<CommonMarker]



43
44
45
# File 'lib/mato/config.rb', line 43

def markdown_parser
  @markdown_parser
end

#markdown_render_optionsArray<Symbol>

Returns CommonMarker’s HTML rendering options.

Returns:

  • (Array<Symbol>)

    CommonMarker’s HTML rendering options



58
59
60
# File 'lib/mato/config.rb', line 58

def markdown_render_options
  @markdown_render_options
end

#text_filtersArray<Proc>

Returns:

  • (Array<Proc>)


34
35
36
# File 'lib/mato/config.rb', line 34

def text_filters
  @text_filters
end

Instance Method Details

#append_html_filter(html_filter, timeout: nil, on_timeout: nil, on_error: nil) ⇒ Object



93
94
95
96
97
# File 'lib/mato/config.rb', line 93

def append_html_filter(html_filter, timeout: nil, on_timeout: nil, on_error: nil)
  raise "html_filter must respond to call()" unless html_filter.respond_to?(:call)

  html_filters.push(wrap(html_filter, timeout: timeout, on_timeout: on_timeout, on_error: on_error))
end

#append_markdown_filter(markdown_filter, timeout: nil, on_timeout: nil, on_error: nil) ⇒ Object



87
88
89
90
91
# File 'lib/mato/config.rb', line 87

def append_markdown_filter(markdown_filter, timeout: nil, on_timeout: nil, on_error: nil)
  raise "markdown_filter must respond to call()" unless markdown_filter.respond_to?(:call)

  markdown_filters.push(wrap(markdown_filter, timeout: timeout, on_timeout: on_timeout, on_error: on_error))
end

#append_text_filter(text_filter, timeout: nil, on_timeout: nil, on_error: nil) ⇒ Object



81
82
83
84
85
# File 'lib/mato/config.rb', line 81

def append_text_filter(text_filter, timeout: nil, on_timeout: nil, on_error: nil)
  raise "text_filter must respond to call()" unless text_filter.respond_to?(:call)

  text_filters.push(wrap(text_filter, timeout: timeout, on_timeout: on_timeout, on_error: on_error))
end

#configure(&block) {|config| ... } ⇒ Object

Parameters:

  • block (Proc)

Yield Parameters:



77
78
79
# File 'lib/mato/config.rb', line 77

def configure(&block)
  block.call(self)
end