Permalink
Browse files

Create Sprockets::Template

  • Loading branch information...
1 parent 05d382d commit ec04deb26be303cb7705d69527f7180cd8343eb7 @josh josh committed Dec 19, 2013
View
@@ -14,6 +14,7 @@ module Sprockets
autoload :StaticAsset, "sprockets/static_asset"
# Processing
+ autoload :Template, "sprockets/template"
autoload :Context, "sprockets/context"
autoload :CoffeeScriptTemplate, "sprockets/coffee_script_template"
autoload :EcoTemplate, "sprockets/eco_template"
@@ -90,9 +91,6 @@ module Cache
require 'sprockets/yui_compressor'
register_compressor 'application/javascript', :yui, YUICompressor
- # Cherry pick the default Tilt engines that make sense for
- # Sprockets. We don't need ones that only generate html like HAML.
-
# Mmm, CoffeeScript
register_engine '.coffee', CoffeeScriptTemplate
@@ -1,5 +1,3 @@
-require 'tilt'
-
module Sprockets
# Some browsers have issues with stylesheets that contain multiple
# `@charset` definitions. The issue surfaces while using Sass since
@@ -18,7 +16,7 @@ module Sprockets
#
# environment.unregister_bundle_processor 'text/css', Sprockets::CharsetNormalizer
#
- class CharsetNormalizer < Tilt::Template
+ class CharsetNormalizer < Template
def prepare
end
@@ -1,7 +1,5 @@
-require 'tilt'
-
module Sprockets
- class ClosureCompressor < Tilt::Template
+ class ClosureCompressor < Template
self.default_mime_type = 'application/javascript'
def self.engine_initialized?
@@ -1,7 +1,5 @@
-require 'tilt'
-
module Sprockets
- class CoffeeScriptTemplate < Tilt::Template
+ class CoffeeScriptTemplate < Template
self.default_mime_type = 'application/javascript'
def self.engine_initialized?
@@ -6,7 +6,7 @@
require 'set'
module Sprockets
- # `Context` provides helper methods to all `Tilt` processors. They
+ # `Context` provides helper methods to all `Template` processors. They
# are typically accessed by ERB templates. You can mix in custom
# helpers by injecting them into `Environment#context_class`. Do not
# mix them into `Context` directly.
@@ -1,6 +1,5 @@
require 'pathname'
require 'shellwords'
-require 'tilt'
require 'yaml'
module Sprockets
@@ -20,10 +19,9 @@ module Sprockets
# *= require "baz"
# */
#
- # The Processor is implemented as a `Tilt::Template` and is loosely
- # coupled to Sprockets. This makes it possible to disable or modify
- # the processor to do whatever you'd like. You could add your own
- # custom directives or invent your own directive syntax.
+ # This makes it possible to disable or modify the processor to do whatever
+ # you'd like. You could add your own custom directives or invent your own
+ # directive syntax.
#
# `Environment#processors` includes `DirectiveProcessor` by default.
#
@@ -36,7 +34,7 @@ module Sprockets
#
# env.register_processor('text/css', MyProcessor)
#
- class DirectiveProcessor < Tilt::Template
+ class DirectiveProcessor < Template
# Directives will only be picked up if they are in the header
# of the source file. C style (/* */), JavaScript (//), and
# Ruby (#) comments are supported.
@@ -82,7 +80,7 @@ def prepare
@included_pathnames = []
end
- # Implemented for Tilt#render.
+ # Implemented for Template#render.
#
# `context` is a `Context` instance with methods that allow you to
# access the environment and append to the bundle. See `Context`
@@ -1,20 +1,18 @@
-require 'tilt'
-
module Sprockets
- # Tilt engine class for the Eco compiler. Depends on the `eco` gem.
+ # Template engine class for the Eco compiler. Depends on the `eco` gem.
#
# For more infomation see:
#
# https://github.com/sstephenson/ruby-eco
# https://github.com/sstephenson/eco
#
- class EcoTemplate < Tilt::Template
+ class EcoTemplate < Template
# Check to see if Eco is loaded
def self.engine_initialized?
defined? ::Eco
end
- # Autoload eco library. If the library isn't loaded, Tilt will produce
+ # Autoload eco library. If the library isn't loaded, it will produce
# a thread safetly warning. If you intend to use `.eco` files, you
# should explicitly require it.
def initialize_engine
@@ -1,19 +1,17 @@
-require 'tilt'
-
module Sprockets
- # Tilt engine class for the EJS compiler. Depends on the `ejs` gem.
+ # Template engine class for the EJS compiler. Depends on the `ejs` gem.
#
# For more infomation see:
#
# https://github.com/sstephenson/ruby-ejs
#
- class EjsTemplate < Tilt::Template
+ class EjsTemplate < Template
# Check to see if EJS is loaded
def self.engine_initialized?
defined? ::EJS
end
- # Autoload ejs library. If the library isn't loaded, Tilt will produce
+ # Autoload ejs library. If the library isn't loaded, it will produce
# a thread safetly warning. If you intend to use `.ejs` files, you
# should explicitly require it.
def initialize_engine
@@ -15,8 +15,8 @@ module Sprockets
# left. `application.js.coffee.erb` will first run `ERBTemplate`
# then `CoffeeScriptTemplate`.
#
- # All `Engine`s must follow the `Tilt::Template` interface. It is
- # recommended to subclass `Tilt::Template`.
+ # All `Engine`s must follow the `Template` interface. It is
+ # recommended to subclass `Template`.
#
# Its recommended that you register engine changes on your local
# `Environment` instance.
@@ -5,7 +5,6 @@
require 'hike'
require 'logger'
require 'pathname'
-require 'tilt'
module Sprockets
class Environment < Base
@@ -1,7 +1,5 @@
-require 'tilt'
-
module Sprockets
- class ERBTemplate < Tilt::Template
+ class ERBTemplate < Template
def self.engine_initialized?
defined? ::ERB
end
@@ -1,7 +1,5 @@
-require 'tilt'
-
module Sprockets
- class JstProcessor < Tilt::Template
+ class JstProcessor < Template
self.default_mime_type = 'application/javascript'
def self.default_namespace
@@ -1,7 +1,5 @@
-require 'tilt'
-
module Sprockets
- class LessTemplate < Tilt::Template
+ class LessTemplate < Template
self.default_mime_type = 'text/css'
def self.engine_initialized?
@@ -28,8 +28,8 @@ def processors(*args)
# Preprocessors are ran before Postprocessors and Engine
# processors.
#
- # All `Processor`s must follow the `Tilt::Template` interface. It is
- # recommended to subclass `Tilt::Template`.
+ # All `Processor`s must follow the `Template` interface. It is
+ # recommended to subclass `Template`.
def preprocessors(mime_type = nil)
if mime_type
@preprocessors[mime_type].dup
@@ -44,8 +44,8 @@ def preprocessors(mime_type = nil)
#
# Postprocessors are ran after Preprocessors and Engine processors.
#
- # All `Processor`s must follow the `Tilt::Template` interface. It is
- # recommended to subclass `Tilt::Template`.
+ # All `Processor`s must follow the `Template` interface. It is
+ # recommended to subclass `Template`.
def postprocessors(mime_type = nil)
if mime_type
@postprocessors[mime_type].dup
@@ -127,8 +127,8 @@ def unregister_postprocessor(mime_type, klass)
# Bundle Processors are ran on concatenated assets rather than
# individual files.
#
- # All `Processor`s must follow the `Tilt::Template` interface. It is
- # recommended to subclass `Tilt::Template`.
+ # All `Processor`s must follow the `Template` interface. It is
+ # recommended to subclass `Template`.
def bundle_processors(mime_type = nil)
if mime_type
@bundle_processors[mime_type].dup
@@ -1,13 +1,11 @@
-require 'tilt'
-
module Sprockets
# `Processor` creates an anonymous processor class from a block.
#
# register_preprocessor 'text/css', :my_processor do |context, data|
# # ...
# end
#
- class Processor < Tilt::Template
+ class Processor < Template
def self.make_processor(klass, &block) # :nodoc:
return klass unless block_given?
@@ -1,5 +1,3 @@
-require 'tilt'
-
module Sprockets
# For JS developers who are colonfobic, concatenating JS files using
# the module pattern usually leads to syntax errors.
@@ -11,7 +9,7 @@ module Sprockets
#
# environment.unregister_postprocessor 'application/javascript', Sprockets::SafetyColons
#
- class SafetyColons < Tilt::Template
+ class SafetyColons < Template
def prepare
end
@@ -1,7 +1,5 @@
-require 'tilt'
-
module Sprockets
- class SassCompressor < Tilt::Template
+ class SassCompressor < Template
self.default_mime_type = 'text/css'
def self.engine_initialized?
@@ -1,12 +1,6 @@
-require 'tilt'
-
module Sprockets
- # This custom Tilt handler replaces the one built into Tilt. The
- # main difference is that it uses a custom importer that plays nice
- # with sprocket's caching system.
- #
- # See `SassImporter` for more infomation.
- class SassTemplate < Tilt::Template
+ # Also see `SassImporter` for more infomation.
+ class SassTemplate < Template
self.default_mime_type = 'text/css'
def self.engine_initialized?
@@ -1,8 +1,6 @@
require 'sprockets/sass_template'
module Sprockets
- # Scss handler to replace Tilt's builtin one. See `SassTemplate` and
- # `SassImporter` for more infomation.
class ScssTemplate < SassTemplate
self.default_mime_type = 'text/css'
@@ -1,7 +1,5 @@
-require 'tilt'
-
module Sprockets
- class StringTemplate < Tilt::Template
+ class StringTemplate < Template
def prepare
hash = "TILT#{data.hash.abs}"
@code = "<<#{hash}.chomp\n#{data}\n#{hash}"
@@ -0,0 +1,6 @@
+require 'tilt'
+
+module Sprockets
+ class Template < ::Tilt::Template
+ end
+end
@@ -1,7 +1,5 @@
-require 'tilt'
-
module Sprockets
- class UglifierCompressor < Tilt::Template
+ class UglifierCompressor < Template
self.default_mime_type = 'application/javascript'
def self.engine_initialized?
@@ -1,7 +1,5 @@
-require 'tilt'
-
module Sprockets
- class YUICompressor < Tilt::Template
+ class YUICompressor < Template
def self.engine_initialized?
defined?(::YUI)
end

0 comments on commit ec04deb

Please sign in to comment.