Skip to content

Instantly share code, notes, and snippets.

@johnbintz
Created August 29, 2012 23:50
Show Gist options
  • Save johnbintz/3520579 to your computer and use it in GitHub Desktop.
Save johnbintz/3520579 to your computer and use it in GitHub Desktop.
add_t
Gem::Specification.new do |s|
s.name = 'add_t'
s.version = '0.1.0'
s.platform = Gem::Platform::RUBY
s.author = 'John Bintz'
s.email = '[email protected]'
s.summary = 'Filter JavaScript files for %{path} and replace it with the logical Sprockets path.'
s.description = 'Filter JavaScript files for %{path} and replace it with the logical Sprockets path.'
s.files = ['add_t.rb']
s.require_path = '.'
s.add_dependency 'tilt'
end
require 'tilt'
class AddT < ::Tilt::Template
def prepare ; end
def evaluate(scope, locals, &block)
data.gsub('%{path}', scope.logical_path.split('/')[1..-1].join('.'))
end
class Engine < Rails::Engine
initializer "add_t.sprockets", :after => "sprockets.environment" do |app|
app.assets.register_preprocessor 'application/javascript', ::AddT
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment