Class: Tilt::AsciidoctorTemplate

Inherits:
Template
  • Object
show all
Defined in:
lib/awestruct/handlers/template/asciidoc.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.engine_initialized?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/awestruct/handlers/template/asciidoc.rb', line 7

def self.engine_initialized?
  defined? ::Asciidoctor::Document
end

Instance Method Details

#allows_script?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/awestruct/handlers/template/asciidoc.rb', line 23

def allows_script?
  false
end

#evaluate(scope, locals, &block) ⇒ Object



19
20
21
# File 'lib/awestruct/handlers/template/asciidoc.rb', line 19

def evaluate(scope, locals, &block)
  @output ||= Asciidoctor.render(data, options, &block)
end

#initialize_engineObject



11
12
13
# File 'lib/awestruct/handlers/template/asciidoc.rb', line 11

def initialize_engine
  require_template_library 'asciidoctor'
end

#parse_headers(content, filter = /.*/) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/awestruct/handlers/template/asciidoc.rb', line 27

def parse_headers(content, filter = /.*/)
  doc = Asciidoctor.load(content, {:parse_header_only => true})
  filtered = doc.attributes.select{|k,v| k =~ filter}.inject({}) do |hash, (k,v)|
    hash[k.gsub(filter, '')] = v
    hash
  end

  filtered['title'] = filtered['doctitle'] = doc.doctitle
  filtered['date'] ||= doc.attributes['revdate'] unless doc.attributes['revdate'].nil?
  filtered['author'] = doc.attributes['author'] unless doc.attributes['author'].nil?

  filtered
end

#prepareObject



15
16
17
# File 'lib/awestruct/handlers/template/asciidoc.rb', line 15

def prepare
  options[:header_footer] = false if options[:header_footer].nil?
end