Class: Doct::Template
- Inherits:
-
Array
- Object
- Array
- Doct::Template
- Defined in:
- lib/doct/template.rb
Constant Summary collapse
- FORMATS =
{}
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(filename, format = nil) ⇒ Template
constructor
A new instance of Template.
- #placeholders ⇒ Object
- #render ⇒ Object
- #save_as(filename) ⇒ Object
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
#format ⇒ Object (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
#placeholders ⇒ Object
14 15 16 |
# File 'lib/doct/template.rb', line 14 def placeholders @format.placeholders.map(&:to_sym) end |
#render ⇒ Object
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 |