2012-05-28 22:19:40 +02:00
|
|
|
# Require gem
|
|
|
|
require "coffee_script"
|
|
|
|
|
2012-04-27 01:39:26 +02:00
|
|
|
module Middleman
|
|
|
|
module Renderers
|
|
|
|
|
|
|
|
# CoffeeScript Renderer
|
|
|
|
module CoffeeScript
|
|
|
|
|
|
|
|
# Setup extension
|
|
|
|
class << self
|
|
|
|
# Once registered
|
|
|
|
def registered(app)
|
|
|
|
app.before_configuration do
|
|
|
|
template_extensions :coffee => :js
|
|
|
|
end
|
2012-05-28 22:19:40 +02:00
|
|
|
|
2012-05-24 23:29:29 +02:00
|
|
|
# Tell Tilt to use it as well (for inline scss blocks)
|
|
|
|
::Tilt.register 'coffee', DebuggingCoffeeScriptTemplate
|
|
|
|
::Tilt.prefer(DebuggingCoffeeScriptTemplate)
|
2012-04-27 01:39:26 +02:00
|
|
|
end
|
|
|
|
alias :included :registered
|
|
|
|
end
|
2012-05-24 23:29:29 +02:00
|
|
|
|
|
|
|
# A Template for Tilt which outputs debug messages
|
|
|
|
class DebuggingCoffeeScriptTemplate < ::Tilt::CoffeeScriptTemplate
|
|
|
|
# Add exception messaging
|
|
|
|
# @param [Class] context
|
|
|
|
# @param [Hash] locals
|
|
|
|
# @return [String]
|
|
|
|
def evaluate(context, locals, &block)
|
2012-07-25 20:21:07 +02:00
|
|
|
return super if context.build?
|
|
|
|
|
2012-05-24 23:29:29 +02:00
|
|
|
begin
|
|
|
|
super
|
2012-07-08 02:29:31 +02:00
|
|
|
rescue ::ExecJS::RuntimeError => e
|
|
|
|
e.to_s
|
|
|
|
rescue => e
|
2012-05-24 23:29:29 +02:00
|
|
|
e.to_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-04-27 01:39:26 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|