Class: MagLove::Tilt::CoffeeTemplate
- Inherits:
-
Tilt::Template
- Object
- Tilt::Template
- MagLove::Tilt::CoffeeTemplate
- Defined in:
- lib/maglove/tilt/coffee_template.rb
Class Method Summary collapse
Instance Method Summary collapse
- #allows_script? ⇒ Boolean
- #evaluate(scope, locals, &block) ⇒ Object
- #initialize_engine ⇒ Object
- #prepare ⇒ Object
Class Method Details
.engine_initialized? ⇒ Boolean
6 7 8 |
# File 'lib/maglove/tilt/coffee_template.rb', line 6 def self.engine_initialized? defined? ::CoffeeScript end |
Instance Method Details
#allows_script? ⇒ Boolean
43 44 45 |
# File 'lib/maglove/tilt/coffee_template.rb', line 43 def allows_script? false end |
#evaluate(scope, locals, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/maglove/tilt/coffee_template.rb', line 18 def evaluate(scope, locals, &block) @output = CoffeeScript.compile(@data, ) # handle includes @output.gsub!(/^include\("([^"]+)"\);$/) do |match| path = Regexp.last_match[1] path = "#{path}.coffee" if File.extname(path).empty? include_path = File.absolute_path(path, File.dirname(file)) # check if base path exists unless File.exist?(include_path) include_path = File.absolute_path(path, locals[:base_path]) end if File.exist?(include_path) include_template = ::Tilt.new(include_path) include_template.render(Object.new, locals) else raise "Path not found: #{include_path}" end end @output end |
#initialize_engine ⇒ Object
10 11 12 |
# File 'lib/maglove/tilt/coffee_template.rb', line 10 def initialize_engine require_template_library 'coffee_script' end |
#prepare ⇒ Object
14 15 16 |
# File 'lib/maglove/tilt/coffee_template.rb', line 14 def prepare [:bare] = true end |