Module: Middleman::Renderers::AsciiDoc

Defined in:
lib/middleman-core/renderers/asciidoc.rb

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object Also known as: included



8
9
10
11
12
13
14
15
16
17
18
19
20
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
# File 'lib/middleman-core/renderers/asciidoc.rb', line 8

def registered(app)
  app.config.define_setting :asciidoc, {
    :safe => :safe,
    :backend => :html5,
    :attributes => %W(showtitle env=middleman env-middleman middleman-version=#{::Middleman::VERSION})
  }, 'AsciiDoc engine options (Hash)'
  app.config.define_setting :asciidoc_attributes, [], 'AsciiDoc custom attributes (Array)'
  app.before_configuration do
    template_extensions :adoc => :html
  end

  app.after_configuration do
    # QUESTION should base_dir be equal to docdir instead?
    config[:asciidoc][:base_dir] = source_dir
    config[:asciidoc][:attributes].concat(config[:asciidoc_attributes] || [])
    config[:asciidoc][:attributes] << %(imagesdir=#{File.join((config[:http_prefix] || '/').chomp('/'), config[:images_dir])})
    sitemap.(/\.adoc$/) do |path|
      # read the AsciiDoc header only to set page options and data
      # header values can be accessed via app.data.page.<name> in the layout
      doc = Asciidoctor.load_file path, :safe => :safe, :parse_header_only => true

      opts = {}
      if doc.attr? 'page-layout'
        case (layout = (doc.attr 'page-layout'))
        when '', 'false'
          opts[:layout] = false
        else
          opts[:layout] = layout
        end
      end
      opts[:layout_engine] = (doc.attr 'page-layout-engine') if (doc.attr? 'page-layout-engine')
      # TODO override attributes to set docfile, docdir, docname, etc
      # alternative is to set :renderer_options, which get merged into options by the rendering extension
      #opts[:attributes] = config[:asciidoc][:attributes].dup
      #opts[:attributes].concat %W(docfile=#{path} docdir=#{File.dirname path} docname=#{(File.basename path).sub(/\.adoc$/, '')})

      page = {}
      page[:title] = doc.doctitle
      page[:date] = (doc.attr 'date') unless (doc.attr 'date').nil?
      # TODO grab all the author information
      page[:author] = (doc.attr 'author') unless (doc.attr 'author').nil?

      {:options => opts, :page => ::Middleman::Util.recursively_enhance(page)}
    end
  end
end