Class: Doct::Template

Inherits:
Array
  • Object
show all
Defined in:
lib/doct/template.rb

Constant Summary collapse

FORMATS =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, format = nil) ⇒ Template

Returns a new instance of Template.



9
10
11
12
13
# File 'lib/doct/template.rb', line 9

def initialize(filename, format = nil)
  format ||= File.extname(filename)[1..-1].to_s.downcase
  raise "Unrecognized format '#{format}'" unless FORMATS[format]
  @format = FORMATS[format].new(filename)
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format.



3
4
5
# File 'lib/doct/template.rb', line 3

def format
  @format
end

Class Method Details

.register_format(format, *extensions) ⇒ Object



6
7
8
# File 'lib/doct/template.rb', line 6

def self.register_format(format, *extensions)
  extensions.each {|ext| FORMATS[ext] = format}
end

Instance Method Details

#placeholdersObject



14
15
16
# File 'lib/doct/template.rb', line 14

def placeholders
  @format.placeholders.map(&:to_sym)
end

#renderObject



20
21
22
# File 'lib/doct/template.rb', line 20

def render
  @format.render self
end

#save_as(filename) ⇒ Object



17
18
19
# File 'lib/doct/template.rb', line 17

def save_as filename
  open(filename, "wb") { |io| io << render }
end