class DotjsSprockets::Engine
The engine class is in charge to handle the template compilation via ExecJS, provides a clean interface to be used by the TiltDot
class
@since 0.1.0
Public Class Methods
precompile(full_path)
click to toggle source
Given a path to a template it returns the compiled version
@param full_path [String] the template full path
@return [String] JavaScript function that may be directly executed client-side
@example Compiling a Template
DotjsSprockets::Engine.precompile("/my/template.jst.djs") # => "function()...."
@since 0.1.0
# File lib/dotjs_sprockets/engine.rb, line 23 def precompile(full_path) template = open(full_path).read context.eval("doT.compile(#{template.inspect}).toString()") end
Private Class Methods
context()
click to toggle source
Stores a ExecJS context instance
@return [ExecJS::ExternalRuntime::Context]
@since 0.1.0
# File lib/dotjs_sprockets/engine.rb, line 35 def context @context ||= ExecJS.compile(source) end
path()
click to toggle source
Stores the full path of the library source (doT.js)
@return [String] full path of the doT.js library
@since 0.1.0
# File lib/dotjs_sprockets/engine.rb, line 44 def path @path ||= File.expand_path(DotjsSprockets::ASSETS_PATH, __FILE__) end
source()
click to toggle source
Stores the contents of the library source (doT.js)
@return [String] full content of the doT.js library
@since 0.1.0
# File lib/dotjs_sprockets/engine.rb, line 53 def source @source ||= open("#{path}/doT.js").read end