Class: Snp::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/snp/compiler.rb

Overview

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)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, extra_options) ⇒ Compiler

Public: creates a new Snp::Compiler instance.

template - the template name. extra_options - options to override default data to build the template.



22
23
24
25
# File 'lib/snp/compiler.rb', line 22

def initialize(template, extra_options)
  @template = template
  @options  = extra_options
end

Class Method Details

.build(template_name, extra_options) ⇒ Object



14
15
16
# File 'lib/snp/compiler.rb', line 14

def self.build(template_name, extra_options)
  new(template_name, extra_options).compile
end

Instance Method Details

#compileObject

Public: actually compiles the template.

Returns a string with the compiled version of the snippet.



30
31
32
# File 'lib/snp/compiler.rb', line 30

def compile
  template.compile(compilation_context)
end