2012-05-28 22:19:40 +02:00
|
|
|
# Require gem
|
2013-12-28 01:26:31 +01:00
|
|
|
require 'coffee_script'
|
2012-08-14 00:39:06 +02:00
|
|
|
|
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)
|
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)
|
2013-02-18 04:40:17 +01:00
|
|
|
|
|
|
|
app.before_configuration do
|
|
|
|
DebuggingCoffeeScriptTemplate.middleman_app = self
|
|
|
|
end
|
2012-04-27 01:39:26 +02:00
|
|
|
end
|
2014-04-29 19:50:21 +02:00
|
|
|
alias_method :included, :registered
|
2012-04-27 01:39:26 +02:00
|
|
|
end
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2012-05-24 23:29:29 +02:00
|
|
|
# A Template for Tilt which outputs debug messages
|
|
|
|
class DebuggingCoffeeScriptTemplate < ::Tilt::CoffeeScriptTemplate
|
2013-02-18 04:40:17 +01:00
|
|
|
# Make the current Middleman app accessible to the template
|
|
|
|
cattr_accessor :middleman_app
|
|
|
|
|
2012-05-24 23:29:29 +02:00
|
|
|
# Add exception messaging
|
|
|
|
# @param [Class] context
|
|
|
|
# @param [Hash] locals
|
|
|
|
# @return [String]
|
|
|
|
def evaluate(context, locals, &block)
|
2014-06-07 00:32:00 +02:00
|
|
|
return super unless middleman_app.server?
|
2012-08-14 00:39:06 +02:00
|
|
|
|
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
|
2012-08-14 00:39:06 +02:00
|
|
|
end
|