Class: DatoDast::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/dato_dast/configuration.rb

Constant Summary collapse

TYPE_CONFIG =
{
  Nodes::Block.type => { "node" => Nodes::Block },
  Nodes::Blockquote.type => { "tag" => "blockquote", "node" => Nodes::AttributedQuote },
  Nodes::Code.type => { "tag" => "code", "node" => Nodes::Code, "wrappers" => ["pre"] },
  Nodes::Generic.type => { "node" => Nodes::Generic },
  Nodes::Heading.type => { "tag" => ->(node) { "h#{node.level}" }, "node" => Nodes::Heading },
  Nodes::InlineItem.type => { "node" => Nodes::InlineItem },
  Nodes::ItemLink.type => { "tag" => "a", "node" => Nodes::ItemLink, "url_key" => :slug },
  Nodes::Link.type => { "tag" => "a", "node" => Nodes::Link },
  Nodes::List.type => { "tag" => ->(node) { node.style == "bulleted" ? "ul" : "ol" }, "node" => Nodes::List },
  Nodes::ListItem.type => { "tag" => "li", "node" => Nodes::ListItem },
  Nodes::Paragraph.type => { "tag" => "p", "node" => Nodes::Paragraph },
  Nodes::Root.type => { "tag" => "div", "node" => Nodes::Root },
  Nodes::Span.type => { "node" => Nodes::Span },
  Nodes::ThematicBreak.type => { "tag" => "hr", "node" => Nodes::ThematicBreak },
}.freeze
MARK_CONFIG =
{
  Marks::CODE => { "tag" => "code" },
  Marks::EMPHASIS => { "tag" => "em" },
  Marks::HIGHLIGHT => { "tag" => "mark" },
  Marks::STRIKETHROUGH => { "tag" => "strike" },
  Marks::STRONG => { "tag" => "strong" },
  Marks::UNDERLINE => { "tag" => "u" },
}.freeze
ITEM_RENDER_KEYS =
["node", "render_value", "structure"].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



36
37
38
39
40
41
42
43
44
45
# File 'lib/dato_dast/configuration.rb', line 36

def initialize
  @blocks = {}
  @inline_items = {}
  @highlight = true
  @host = nil
  @item_links = {}
  @marks = MARK_CONFIG.transform_values { |value| value.dup }
  @smart_links = true
  @types = TYPE_CONFIG.transform_values { |value| value.dup }
end

Instance Attribute Details

#blocksObject

Returns the value of attribute blocks.



33
34
35
# File 'lib/dato_dast/configuration.rb', line 33

def blocks
  @blocks
end

#highlightObject

Returns the value of attribute highlight.



34
35
36
# File 'lib/dato_dast/configuration.rb', line 34

def highlight
  @highlight
end

#hostObject

Returns the value of attribute host.



33
34
35
# File 'lib/dato_dast/configuration.rb', line 33

def host
  @host
end

#inline_itemsObject

Returns the value of attribute inline_items.



33
34
35
# File 'lib/dato_dast/configuration.rb', line 33

def inline_items
  @inline_items
end

Returns the value of attribute item_links.



34
35
36
# File 'lib/dato_dast/configuration.rb', line 34

def item_links
  @item_links
end

#marksObject

Returns the value of attribute marks.



33
34
35
# File 'lib/dato_dast/configuration.rb', line 33

def marks
  @marks
end

Returns the value of attribute smart_links.



34
35
36
# File 'lib/dato_dast/configuration.rb', line 34

def smart_links
  @smart_links
end

#typesObject

Returns the value of attribute types.



33
34
35
# File 'lib/dato_dast/configuration.rb', line 33

def types
  @types
end

Instance Method Details

#add_wrapper(type, wrapper) ⇒ Object



95
96
97
98
99
# File 'lib/dato_dast/configuration.rb', line 95

def add_wrapper(type, wrapper)
  wrappers = Array.wrap(@types[type]["wrappers"])
  wrappers << wrapper
  @types[type]["wrappers"] = wrappers
end

#duplicate {|config| ... } ⇒ Object

Yields:

  • (config)


47
48
49
50
51
52
53
54
55
56
57
# File 'lib/dato_dast/configuration.rb', line 47

def duplicate(&blk)
  config = DatoDast::Configuration.new

  %w(blocks inline_items highlight host item_links marks smart_links types).each do |method|
    config.send("#{method}=", send(method))
  end

  yield config if blk

  config
end