Module: Texas::Template
- Defined in:
- lib/texas/template.rb,
lib/texas/template/helper.rb,
lib/texas/template/runner.rb,
lib/texas/template/helper/md.rb,
lib/texas/template/helper/tex.rb,
lib/texas/template/helper/base.rb,
lib/texas/template/helper/info.rb
Defined Under Namespace
Class Attribute Summary collapse
-
.handlers ⇒ Object
Returns the value of attribute handlers.
-
.known_extensions ⇒ Object
Returns the value of attribute known_extensions.
Class Method Summary collapse
-
.basename(filename) ⇒ Object
Returns the filename without the template extension.
- .create(filename, build) ⇒ Object
-
.handler(filename) ⇒ Object
Returns a template handler for the given filename.
-
.register_handler(extensions, handler_class) ⇒ Object
Registers a handler for the given template extensions.
- .register_helper(klass) ⇒ Object
Class Attribute Details
.handlers ⇒ Object
Returns the value of attribute handlers.
4 5 6 |
# File 'lib/texas/template.rb', line 4 def handlers @handlers end |
.known_extensions ⇒ Object
Returns the value of attribute known_extensions.
4 5 6 |
# File 'lib/texas/template.rb', line 4 def known_extensions @known_extensions end |
Class Method Details
.basename(filename) ⇒ Object
Returns the filename without the template extension
Example:
input_path("/home/rene/github/sample_project/tmp/build/chapter-01/contents.md.erb")
# => "/home/rene/github/sample_project/tmp/build/chapter-01/contents"
46 47 48 49 50 51 52 |
# File 'lib/texas/template.rb', line 46 def basename(filename) value = filename known_extensions.each do |str| value = value.gsub(/\.#{str}$/, '') end value end |
.create(filename, build) ⇒ Object
36 37 38 |
# File 'lib/texas/template.rb', line 36 def create(filename, build) handler(filename).new(filename, build) end |
.handler(filename) ⇒ Object
Returns a template handler for the given filename
Example:
Template.handler("some_file.tex.erb")
# => Template::Runner::TeX
12 13 14 15 16 17 18 |
# File 'lib/texas/template.rb', line 12 def handler(filename) Template.handlers.each do |pattern, klass| return klass if filename =~ pattern end warning { "No template handler found for: #{filename}" } Template::Runner::Base end |
.register_handler(extensions, handler_class) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/texas/template.rb', line 25 def register_handler(extensions, handler_class) extensions.each do |ext| handlers[/\.#{ext}$/i] = handler_class end known_extensions.concat extensions end |