class Snp::Compiler
This class takes a template file name and builds it, using the template definition, default data to be used and extra options that override the default ones.
Example
Compiler.build('js.html', inline: true)
Public Class Methods
build(template_name, extra_options)
click to toggle source
# File lib/snp/compiler.rb, line 14 def self.build(template_name, extra_options) new(template_name, extra_options).compile end
new(template, extra_options)
click to toggle source
Public: creates a new Snp::Compiler
instance.
template - the template name. extra_options - options to override default data to build the template.
# File lib/snp/compiler.rb, line 22 def initialize(template, extra_options) @template = template @options = extra_options end
Public Instance Methods
compile()
click to toggle source
Public: actually compiles the template.
Returns a string with the compiled version of the snippet.
# File lib/snp/compiler.rb, line 30 def compile template.compile(compilation_context) end
Private Instance Methods
compilation_context()
click to toggle source
Internal: builds the ERB context to be used to generate the snippet. Consists of the default for the template plus the extra options passed on initialization.
# File lib/snp/compiler.rb, line 39 def compilation_context TemplateContext.for(default_data.merge(@options)) end
default_data()
click to toggle source
Internal: searches the default data file for the template and parses it.
Returns a hash with the default data if available, or an empty hash otherwise.
# File lib/snp/compiler.rb, line 46 def default_data Data.for(@template) end
path()
click to toggle source
# File lib/snp/compiler.rb, line 54 def path @_path ||= Path.new end
template()
click to toggle source
# File lib/snp/compiler.rb, line 50 def template Template.new(@template, path) end