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
Returns a Template runner for the given filename.
-
.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
Registers the methods defined in a module to use them in templates.
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:
Template.basename("/home/rene/github/sample_project/tmp/build/chapter-01/contents.md.erb")
# => "/home/rene/github/sample_project/tmp/build/chapter-01/contents"
64 65 66 67 68 69 70 |
# File 'lib/texas/template.rb', line 64 def basename(filename) value = filename known_extensions.each do |str| value = value.gsub(/\.#{str}$/, '') end value end |
.create(filename, build) ⇒ Object
Returns a Template runner for the given filename
Example:
Template.create("some_file.tex.erb", build)
# => #<Template::Runner::TeX ...>
54 55 56 |
# File 'lib/texas/template.rb', line 54 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 |
.register_helper(klass) ⇒ Object
Registers the methods defined in a module to use them in templates.
Example:
module Foo
def bar; "foobar"; end
end
Template.register_helper Foo
# afterwards, this prints "foobar" in any template:
<%= bar %>
44 45 46 |
# File 'lib/texas/template.rb', line 44 def register_helper(klass) Template::Runner::Base.__send__ :include, klass end |