Module: Middleman::AsciiDoc::Template

Defined in:
lib/middleman-asciidoc/template.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{ header_footer: false }

Instance Method Summary collapse

Instance Method Details

#evaluate(scope, locals) ⇒ Object


22
23
24
# File 'lib/middleman-asciidoc/template.rb', line 22

def evaluate scope, locals
  @output ||= @document.convert
end

#middleman_contextObject


26
27
28
29
30
# File 'lib/middleman-asciidoc/template.rb', line 26

def middleman_context
  if ::Middleman::TemplateContext === (ctx = options[:context])
    ctx
  end
end

#prepareObject


8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/middleman-asciidoc/template.rb', line 8

def prepare
  opts = DEFAULT_OPTIONS.merge options
  if (ctx = middleman_context)
    attrs = opts[:attributes]
    attrs['outfile'] = outfile = ::File.join \
        (ctx.app.root_path.join ctx.app.config[:build_dir].to_s),
        ctx.current_page.destination_path
    attrs['outdir'] = opts[:to_dir] = ::File.dirname outfile
  end
  @document = ::Asciidoctor.load data, opts
  ctx.current_page.data.document = @document if ctx
  @output = nil
end