Class: NoraMark::Html::FrontmatterWriter

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/nora_mark/html/frontmatter_writer.rb

Instance Method Summary collapse

Methods included from Util

#escape_html

Constructor Details

#initialize(generator) ⇒ FrontmatterWriter

Returns a new instance of FrontmatterWriter.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/nora_mark/html/frontmatter_writer.rb', line 5

def initialize(generator)
  @generator = generator
  @context = generator.context
  @writers = {
    stylesheets: proc do |value|
      value = [value] if value.is_a? String
      @context.stylesheets.concat value
    end,
    title: proc do |value|
      @context.title = escape_html value
    end,
    lang: proc do |value|
      @context.lang = escape_html value.strip
    end,
    paragraph_style: proc do |value|
      @context.paragraph_style = value.strip.to_sym
    end,
    namespace: proc do |value|
      @context.namespaces.merge! value
    end,
    meta: proc do |value|
      @context.metas << value
    end
  }
end

Instance Method Details

#write(node) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/nora_mark/html/frontmatter_writer.rb', line 31

def write(node)
  if node.yaml.keys.map(&:to_sym).include? :stylesheets
    @context.stylesheets = []
  end
  if node.yaml.keys.map(&:to_sym).include? :meta
    @context.metas = []
  end
  node.yaml.each { |k, v|
    writer = @writers[k.to_sym]
    writer.call(v) unless writer.nil?
  }
end