Class: Awestruct::Tilt::AsciidoctorTemplate
- Inherits:
-
Tilt::Template
- Object
- Tilt::Template
- Awestruct::Tilt::AsciidoctorTemplate
- Defined in:
- lib/awestruct/handlers/template/asciidoc.rb
Class Method Summary collapse
Instance Method Summary collapse
- #allows_script? ⇒ Boolean
- #evaluate(scope, locals, &block) ⇒ Object
- #initialize_engine ⇒ Object
- #parse_headers(content, filter = /.*/) ⇒ Object
- #prepare ⇒ Object
Class Method Details
.engine_initialized? ⇒ Boolean
9 10 11 |
# File 'lib/awestruct/handlers/template/asciidoc.rb', line 9 def self.engine_initialized? defined? ::Asciidoctor::Document end |
Instance Method Details
#allows_script? ⇒ Boolean
25 26 27 |
# File 'lib/awestruct/handlers/template/asciidoc.rb', line 25 def allows_script? false end |
#evaluate(scope, locals, &block) ⇒ Object
21 22 23 |
# File 'lib/awestruct/handlers/template/asciidoc.rb', line 21 def evaluate(scope, locals, &block) @output ||= ::Asciidoctor.render(data, , &block) end |
#initialize_engine ⇒ Object
13 14 15 |
# File 'lib/awestruct/handlers/template/asciidoc.rb', line 13 def initialize_engine require_template_library 'asciidoctor' end |
#parse_headers(content, filter = /.*/) ⇒ Object
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 54 55 56 57 58 59 60 61 62 |
# File 'lib/awestruct/handlers/template/asciidoc.rb', line 29 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? if (cnt = doc.attributes['authorcount'].to_i) > 1 = [] (1..cnt).each do |idx| = {} [:name] = doc.attributes["author_#{idx}"] if doc.attributes.has_key? "email_#{idx}" [:email] = doc.attributes["email_#{idx}"] end << end filtered['author'] = .first[:name] filtered['email'] = .first[:email] if .first.has_key? :email filtered['authors'] = .to_yaml elsif !doc.attributes['author'].nil? = {} [:name] = doc.attributes['author'] if doc.attributes.has_key? 'email' [:email] = doc.attributes['email'] end filtered['author'] = [:name] filtered['authors'] = [].to_yaml end filtered end |
#prepare ⇒ Object
17 18 19 |
# File 'lib/awestruct/handlers/template/asciidoc.rb', line 17 def prepare [:header_footer] = false if [:header_footer].nil? end |