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

Modules: Helper, Runner

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.handlersObject

Returns the value of attribute handlers.



4
5
6
# File 'lib/texas/template.rb', line 4

def handlers
  @handlers
end

.known_extensionsObject

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

Registers a handler for the given template extensions

Example:

Template.register_handler %w(tex tex.erb), Template::Runner::TeX


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



32
33
34
# File 'lib/texas/template.rb', line 32

def register_helper(klass)
  Template::Runner::Base.__send__ :include, klass
end