class Stitch::CoffeeScriptTemplate
Public Class Methods
default_bare()
click to toggle source
# File lib/stitch/coffee_script_template.rb, line 9 def self.default_bare @@default_bare end
default_bare=(value)
click to toggle source
# File lib/stitch/coffee_script_template.rb, line 13 def self.default_bare=(value) @@default_bare = value end
engine_initialized?()
click to toggle source
# File lib/stitch/coffee_script_template.rb, line 19 def self.engine_initialized? defined? ::CoffeeScript end
excludes=(excludes)
click to toggle source
# File lib/stitch/coffee_script_template.rb, line 23 def self.excludes=(excludes) @@excludes = excludes end
javascripts_path()
click to toggle source
# File lib/stitch/coffee_script_template.rb, line 27 def self.javascripts_path File.expand_path('../../assets/javascripts', __FILE__) end
Public Instance Methods
evaluate(scope, locals, &block)
click to toggle source
# File lib/stitch/coffee_script_template.rb, line 41 def evaluate(scope, locals, &block) name = module_name(scope) if (name == 'stitch_rails') || excluded?(name) @output ||= CoffeeScript.compile(data, options) else @output ||= <<JS require.define({ #{name.inspect}: function(exports, require, module) { #{indent_lines(CoffeeScript.compile(data, options.merge(:bare => true)), 4)} } }); JS end end
initialize_engine()
click to toggle source
# File lib/stitch/coffee_script_template.rb, line 31 def initialize_engine require_template_library 'coffee_script' end
prepare()
click to toggle source
# File lib/stitch/coffee_script_template.rb, line 35 def prepare if !options.key?(:bare) options[:bare] = self.class.default_bare end end
Private Instance Methods
excluded?(name)
click to toggle source
# File lib/stitch/coffee_script_template.rb, line 57 def excluded?(name) @@excludes.any? { |pattern| File.fnmatch(pattern, name) } end
indent_lines(content, indention)
click to toggle source
# File lib/stitch/coffee_script_template.rb, line 61 def indent_lines(content, indention) content.gsub(/^/, ' ' * indention) end
module_name(scope)
click to toggle source
this might need to be customisable to generate the desired module names this implementation lops off the first segment of the path
# File lib/stitch/coffee_script_template.rb, line 66 def module_name(scope) scope.logical_path end