Class: Snp::Template
- Inherits:
-
Object
- Object
- Snp::Template
- Defined in:
- lib/snp/template.rb
Overview
Snp::Template
The Template class represents a snippet definition through an ERB template. Template files are looked in a series of directories that can be defined via the SNP_PATH environment variable. By default, these snippet definitions are searched in the ‘.snp` directory in your home directory.
Examples
t = Snp::Template.new('jquery.erb')
t.compile(binding) # => '<html><head>...'
Instance Method Summary collapse
-
#compile(context) ⇒ Object
Public: compiles the template content to an effective snippet, ready to use.
-
#initialize(template_file, path = Path.new) ⇒ Template
constructor
Public: creates a new template instance.
Constructor Details
Instance Method Details
#compile(context) ⇒ Object
Public: compiles the template content to an effective snippet, ready to use.
context - a ‘Binding` object to be used as context in the template compilation.
Returns a string with the compiled template.
39 40 41 42 43 44 45 |
# File 'lib/snp/template.rb', line 39 def compile(context) if template_content ERB.new(template_content, 0, '-').result(context) else raise TemplateNotFound.new(@file, @path.absolute_paths) end end |