coffee.rb 1020 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. require 'tilt/template'
  2. module Tilt
  3. # CoffeeScript template implementation. See:
  4. # http://coffeescript.org/
  5. #
  6. # CoffeeScript templates do not support object scopes, locals, or yield.
  7. class CoffeeScriptTemplate < Template
  8. self.default_mime_type = 'application/javascript'
  9. @@default_bare = false
  10. def self.default_bare
  11. @@default_bare
  12. end
  13. def self.default_bare=(value)
  14. @@default_bare = value
  15. end
  16. # DEPRECATED
  17. def self.default_no_wrap
  18. @@default_bare
  19. end
  20. # DEPRECATED
  21. def self.default_no_wrap=(value)
  22. @@default_bare = value
  23. end
  24. def self.engine_initialized?
  25. defined? ::CoffeeScript
  26. end
  27. def initialize_engine
  28. require_template_library 'coffee_script'
  29. end
  30. def prepare
  31. if !options.key?(:bare) and !options.key?(:no_wrap)
  32. options[:bare] = self.class.default_bare
  33. end
  34. end
  35. def evaluate(scope, locals, &block)
  36. @output ||= CoffeeScript.compile(data, options)
  37. end
  38. end
  39. end