set template_root for dust template using jasmine.yml

This commit is contained in:
Sungwon Lee 2012-01-12 15:47:39 +09:00
parent aa40010fbd
commit bf60c276b9
3 changed files with 23 additions and 17 deletions

View File

@ -4,33 +4,27 @@ require 'fileutils'
module Jasmine
module Headless
class DustCache < CacheableAction
class << self
def cache_type
"dust"
end
end
module Source
def self.path
@path ||= File.expand_path('../../../../vendor/assets/javascripts/dust-full-for-compile.js', __FILE__)
end
def self.contents
@contents ||= File.read(path)
end
def self.context
@context ||= ExecJS.compile(contents)
end
end
def action
template_root = "app/assets/javascripts/templates/"
@path ||= File.expand_path('../../../../vendor/assets/javascripts/dust-full-for-compile.js', __FILE__)
@contents ||= File.read(@path)
@context ||= ExecJS.compile(@contents)
template_root = DustTemplate.template_root
template_root = template_root + '/' if template_root[ template_root.length - 1 ].chr != '/'
template_name = file.split(template_root).last.split('.',2).first
Source.context.call("dust.compile", File.read(file), template_name)
@context.call("dust.compile", File.read(file), template_name)
end
end
end
end

View File

@ -5,6 +5,15 @@ module Jasmine::Headless
class DustTemplate < Tilt::Template
include Jasmine::Headless::FileChecker
class << self
def template_root=(root)
@template_root = root
end
def template_root
@template_root || "app/assets/javascripts/templates/"
end
end
self.default_mime_type = 'application/javascript'
def prepare; end

View File

@ -225,6 +225,9 @@ module Jasmine::Headless
add_files(@searches[type] = data.flatten, type, send(SEARCH_ROOTS[type]))
end
end
# config dust template
Jasmine::Headless::DustTemplate.template_root = @config['template_dir']
end
def add_files(patterns, type, dirs)