pax_global_header 0000666 0000000 0000000 00000000064 12227535155 0014521 g ustar 00root root 0000000 0000000 52 comment=6a03c314bec3a84a3f6c8076bf058b33ed672a13
sprockets-rails-2.0.1/ 0000775 0000000 0000000 00000000000 12227535155 0014646 5 ustar 00root root 0000000 0000000 sprockets-rails-2.0.1/.gitignore 0000664 0000000 0000000 00000000031 12227535155 0016630 0 ustar 00root root 0000000 0000000 Gemfile*.lock
tmp/
*.gem
sprockets-rails-2.0.1/.travis.yml 0000664 0000000 0000000 00000000332 12227535155 0016755 0 ustar 00root root 0000000 0000000 rvm:
- 1.9.3
- 2.0.0
gemfile:
- test/gemfiles/Gemfile.rails-3.0.x
- test/gemfiles/Gemfile.rails-3.1.x
- test/gemfiles/Gemfile.rails-3.2.x
- test/gemfiles/Gemfile.rails-4.0.x
notifications:
email: false
sprockets-rails-2.0.1/CHANGELOG.md 0000664 0000000 0000000 00000000573 12227535155 0016464 0 ustar 00root root 0000000 0000000 ### 2.0.1
* Allow keep value to be specified for `assets:clean` run with args
for example `assets:clean[0]` will keep no old asset copies
*Richard Schneeman*
* Fix `javascript_include_tag`/`stylesheet_include_tag` helpers when `debug: => false` is used.
*Guillermo Iguaran*
* Fix issue when precompiling html.erb files.
Fixes #45.
*Zach Ohlgren*
sprockets-rails-2.0.1/Gemfile 0000664 0000000 0000000 00000000311 12227535155 0016134 0 ustar 00root root 0000000 0000000 source 'https://rubygems.org'
gemspec
# Roll w/ branch until 4.0 is cut
gem 'actionpack', :github => 'rails/rails', branch: '4-0-stable'
gem 'railties', :github => 'rails/rails', branch: '4-0-stable'
sprockets-rails-2.0.1/LICENSE 0000664 0000000 0000000 00000002037 12227535155 0015655 0 ustar 00root root 0000000 0000000 Copyright (c) 2012 Joshua Peek
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
sprockets-rails-2.0.1/README.md 0000664 0000000 0000000 00000014101 12227535155 0016122 0 ustar 00root root 0000000 0000000 # Sprockets Rails
Provides Sprockets implementation for Rails 4.x (and beyond) Asset Pipeline.
## Installation
``` ruby
gem 'sprockets-rails', :require => 'sprockets/railtie'
```
Or alternatively `require 'sprockets/railtie'` in your `config/application.rb` if you have Bundler auto-require disabled.
## Usage
### Rake task
**`rake assets:precompile`**
Deployment task that compiles any assets listed in `config.assets.precompile` to `public/assets`.
**`rake assets:clean`**
Only removes old assets (keeps the most recent 3 copies) from `public/assets`. Useful when doing rolling deploys that may still be serving old assets while the new ones are being compiled.
**`rake assets:clobber`**
Nuke `public/assets` and clear the Sprockets file system cache.
#### Customize
If the basic tasks don't do all that you need, it's straight forward to redefine them and replace them with something more specific to your app.
You can also redefine the task with the built in task generator.
``` ruby
require 'sprockets/rails/task'
Sprockets::Rails::Task.new do |t|
t.environment = lambda { Rails.application.assets }
t.assets = %w( application.js application.css )
t.keep = 5
end
```
Each asset task will invoke `assets:environment` first. By default this loads the Rails environment. You can override this task to add or remove dependencies for your specific compilation environment.
Also see [Sprockets::Rails::Task](https://github.com/josh/sprockets-rails/blob/master/lib/sprockets/rails/task.rb) and [Rake::SprocketsTask](https://github.com/sstephenson/sprockets/blob/master/lib/rake/sprocketstask.rb).
### Initializer options
**`config.assets.precompile`**
Add additional assets to compile on deploy. Defaults to `application.js`, `application.css` and any other non-js/css file under `app/assets`.
**`config.assets.paths`**
Add additional load paths to this Array. Rails includes `app/assets` and `vendor/assets` for you already. Plugins might want to add their custom paths to to this.
**`config.assets.version`**
Set a custom cache buster string. Changing it will cause all assets to recompile on the next build.
``` ruby
config.assets.version = 'v1'
# after installing a new plugin, change loads paths
config.assets.version = 'v2'
```
**`config.assets.prefix`**
Defaults to `/assets`. Changes the directory to compile assets to.
**`config.assets.digest`**
Link to undigest asset filenames. This option will eventually go away. Unless when `compile` is disabled.
**`config.assets.debug`**
Enable expanded asset debugging mode. Individual files will be served to make referencing filenames in the web console easier. This feature will eventually be deprecated and replaced by Source Maps in Sprockets 3.x.
**`config.assets.compile`**
Enables Sprockets compile environment. If disabled, `Rails.application.assets` will be unavailable to any ActionView helpers. View helpers will depend on assets being precompiled to `public/assets` in order to link to them. You can still access the environment by directly calling `Rails.application.assets`.
**`config.assets.configure`**
Invokes block with environment when the environment is initialized. Allows direct access to the environment instance and lets you lazily load libraries only needed for asset compiling.
``` ruby
config.assets.configure do |env|
env.js_compressor = :uglify # or :closure, :yui
env.css_compressor = :sass # or :yui
require 'my_processor'
env.register_preprocessor 'application/javascript', MyProcessor
env.logger = Rails.logger
env.cache = ActiveSupport::Cache::FileStore.new("tmp/cache/assets")
end
```
## Complementary plugins
The following plugins provide some extras for the Sprockets Asset Pipeline.
* [coffee-rails](https://github.com/rails/coffee-rails)
* [sass-rails](https://github.com/rails/sass-rails)
**NOTE** That these plugins are optional. The core coffee-script, sass, less, uglify, (any many more) features are built into Sprockets itself. Many of these plugins only provide generators and extra helpers. You can probably get by without them.
## Changes from Rails 3.x
* Only compiles digest filenames. Static non-digest assets should simply live in public/.
* Unmanaged asset paths and urls fallback to linking to public/. This should make it easier to work with both compiled assets and simple static assets. As a side effect, there will never be any "asset not precompiled errors" when linking to missing assets. They will just link to a public file which may or may not exist.
* JS and CSS compressors must be explicitly set. Magic detection has been removed to avoid loading compressors in environments where you want to avoid loading any of the asset libraries. Assign `config.assets.js_compressor = :uglify` or `config.assets.css_compressor = :sass` for the standard compressors.
* The manifest file is now in a JSON format. Since it lives in public/ by default, the initial filename is also randomized to obfuscate public access to the resource.
* Two cleanup tasks. `rake assets:clean` is now a safe cleanup that only removes older assets that are no longer used. While `rake assets:clobber` nukes the entire `public/assets` directory and clears your filesystem cache. The clean task allows for rolling deploys that may still be linking to an old asset while the new assets are being built.
## Contributing
Usual bundler workflow.
``` shell
$ git clone https://github.com/rails/sprockets-rails.git
$ cd sprockets-rails/
$ bundle install
$ bundle exec rake test
```
[](http://travis-ci.org/rails/sprockets-rails)
## Releases
sprockets-rails 2.x will primarily target sprockets 2.x. And future versions will target the corresponding sprockets release line.
The minor and patch version will be updated according to [semver](http://semver.org/).
* Any new APIs or config options that don't break compatibility will be in a minor release
* Any time the sprockets depedency is bumped, there will be a new minor release
* Simple bug fixes will be patch releases
## License
Copyright © 2012 Joshua Peek.
Released under the MIT license. See `LICENSE` for details.
sprockets-rails-2.0.1/Rakefile 0000664 0000000 0000000 00000000177 12227535155 0016320 0 ustar 00root root 0000000 0000000 require 'rake/testtask'
require 'bundler/gem_tasks'
task :default => :test
task :test do
exec "testrb test/test_*.rb"
end
sprockets-rails-2.0.1/lib/ 0000775 0000000 0000000 00000000000 12227535155 0015414 5 ustar 00root root 0000000 0000000 sprockets-rails-2.0.1/lib/sprockets/ 0000775 0000000 0000000 00000000000 12227535155 0017431 5 ustar 00root root 0000000 0000000 sprockets-rails-2.0.1/lib/sprockets/rails.rb 0000664 0000000 0000000 00000000075 12227535155 0021072 0 ustar 00root root 0000000 0000000 if defined? Rails::Railtie
require 'sprockets/railtie'
end
sprockets-rails-2.0.1/lib/sprockets/rails/ 0000775 0000000 0000000 00000000000 12227535155 0020543 5 ustar 00root root 0000000 0000000 sprockets-rails-2.0.1/lib/sprockets/rails/helper.rb 0000664 0000000 0000000 00000010747 12227535155 0022360 0 ustar 00root root 0000000 0000000 require 'action_view'
require 'sprockets'
require 'active_support/core_ext/class/attribute'
module Sprockets
module Rails
module Helper
if defined? ActionView::Helpers::AssetUrlHelper
include ActionView::Helpers::AssetUrlHelper
include ActionView::Helpers::AssetTagHelper
else
require 'sprockets/rails/legacy_asset_tag_helper'
require 'sprockets/rails/legacy_asset_url_helper'
include LegacyAssetTagHelper
include LegacyAssetUrlHelper
end
VIEW_ACCESSORS = [:assets_environment, :assets_manifest,
:assets_prefix, :digest_assets, :debug_assets]
def self.included(klass)
if klass < Sprockets::Context
klass.class_eval do
alias_method :assets_environment, :environment
def assets_manifest; end
class_attribute :config, :assets_prefix, :digest_assets, :debug_assets
end
else
klass.class_attribute(*VIEW_ACCESSORS)
end
end
def self.extended(obj)
obj.class_eval do
attr_accessor(*VIEW_ACCESSORS)
end
end
def compute_asset_path(path, options = {})
if digest_path = asset_digest_path(path)
path = digest_path if digest_assets
path += "?body=1" if options[:debug]
File.join(assets_prefix || "/", path)
else
super
end
end
# Get digest for asset path.
#
# path - String path
# options - Hash options
#
# Returns String Hex digest or nil if digests are disabled.
def asset_digest(path, options = {})
return unless digest_assets
if digest_path = asset_digest_path(path, options)
digest_path[/-(.+)\./, 1]
end
end
# Expand asset path to digested form.
#
# path - String path
# options - Hash options
#
# Returns String path or nil if no asset was found.
def asset_digest_path(path, options = {})
if manifest = assets_manifest
if digest_path = manifest.assets[path]
return digest_path
end
end
if environment = assets_environment
if asset = environment[path]
return asset.digest_path
end
end
end
# Override javascript tag helper to provide debugging support.
#
# Eventually will be deprecated and replaced by source maps.
def javascript_include_tag(*sources)
options = sources.extract_options!.stringify_keys
if options["debug"] != false && request_debug_assets?
sources.map { |source|
if asset = lookup_asset_for_path(source, :type => :javascript)
asset.to_a.map do |a|
super(path_to_javascript(a.logical_path, :debug => true), options)
end
else
super(source, options)
end
}.flatten.uniq.join("\n").html_safe
else
sources.push(options)
super(*sources)
end
end
# Override stylesheet tag helper to provide debugging support.
#
# Eventually will be deprecated and replaced by source maps.
def stylesheet_link_tag(*sources)
options = sources.extract_options!.stringify_keys
if options["debug"] != false && request_debug_assets?
sources.map { |source|
if asset = lookup_asset_for_path(source, :type => :stylesheet)
asset.to_a.map do |a|
super(path_to_stylesheet(a.logical_path, :debug => true), options)
end
else
super(source, options)
end
}.flatten.uniq.join("\n").html_safe
else
sources.push(options)
super(*sources)
end
end
protected
# Enable split asset debugging. Eventually will be deprecated
# and replaced by source maps in Sprockets 3.x.
def request_debug_assets?
debug_assets || (defined?(controller) && controller && params[:debug_assets])
rescue
return false
end
# Internal method to support multifile debugging. Will
# eventually be removed w/ Sprockets 3.x.
def lookup_asset_for_path(path, options = {})
return unless env = assets_environment
path = path.to_s
if extname = compute_asset_extname(path, options)
path = "#{path}#{extname}"
end
env[path]
end
end
end
end
sprockets-rails-2.0.1/lib/sprockets/rails/legacy_asset_tag_helper.rb 0000664 0000000 0000000 00000001631 12227535155 0025726 0 ustar 00root root 0000000 0000000 require 'sprockets'
module Sprockets
module Rails
# Backports of AssetTagHelper methods for Rails 2.x and 3.x.
module LegacyAssetTagHelper
include ActionView::Helpers::TagHelper
def javascript_include_tag(*sources)
options = sources.extract_options!.stringify_keys
sources.uniq.map { |source|
tag_options = {
"src" => path_to_javascript(source)
}.merge(options)
content_tag(:script, "", tag_options)
}.join("\n").html_safe
end
def stylesheet_link_tag(*sources)
options = sources.extract_options!.stringify_keys
sources.uniq.map { |source|
tag_options = {
"rel" => "stylesheet",
"media" => "screen",
"href" => path_to_stylesheet(source)
}.merge(options)
tag(:link, tag_options)
}.join("\n").html_safe
end
end
end
end
sprockets-rails-2.0.1/lib/sprockets/rails/legacy_asset_url_helper.rb 0000664 0000000 0000000 00000007677 12227535155 0025775 0 ustar 00root root 0000000 0000000 require 'sprockets'
module Sprockets
module Rails
# Backports of AssetUrlHelper methods for Rails 2.x and 3.x.
module LegacyAssetUrlHelper
URI_REGEXP = %r{^[-a-z]+://|^(?:cid|data):|^//}
def asset_path(source, options = {})
source = source.to_s
return "" unless source.present?
return source if source =~ URI_REGEXP
tail, source = source[/([\?#].+)$/], source.sub(/([\?#].+)$/, '')
if extname = compute_asset_extname(source, options)
source = "#{source}#{extname}"
end
if source[0] != ?/
source = compute_asset_path(source, options)
end
relative_url_root = (defined?(config.relative_url_root) && config.relative_url_root) ||
(respond_to?(:request) && request.try(:script_name))
if relative_url_root
source = "#{relative_url_root}#{source}" unless source.starts_with?("#{relative_url_root}/")
end
if host = compute_asset_host(source, options)
source = "#{host}#{source}"
end
"#{source}#{tail}"
end
alias_method :path_to_asset, :asset_path
ASSET_EXTENSIONS = {
:javascript => '.js',
:stylesheet => '.css'
}
def compute_asset_extname(source, options = {})
return if options[:extname] == false
extname = options[:extname] || ASSET_EXTENSIONS[options[:type]]
extname if extname && File.extname(source) != extname
end
ASSET_PUBLIC_DIRECTORIES = {
:audio => '/audios',
:font => '/fonts',
:image => '/images',
:javascript => '/javascripts',
:stylesheet => '/stylesheets',
:video => '/videos'
}
def compute_asset_path(source, options = {})
dir = ASSET_PUBLIC_DIRECTORIES[options[:type]] || ""
File.join(dir, source)
end
def compute_asset_host(source = "", options = {})
request = self.request if respond_to?(:request)
if defined? config
host = config.asset_host
elsif defined? ActionController::Base.asset_host
host = ActionController::Base.asset_host
end
host ||= request.base_url if request && options[:protocol] == :request
return unless host
if host.respond_to?(:call)
arity = host.respond_to?(:arity) ? host.arity : host.method(:call).arity
args = [source]
args << request if request && (arity > 1 || arity < 0)
host = host.call(*args)
elsif host =~ /%d/
host = host % (Zlib.crc32(source) % 4)
end
if host =~ URI_REGEXP
host
else
protocol = options[:protocol] || (request ? :request : :relative)
case protocol
when :relative
"//#{host}"
when :request
"#{request.protocol}#{host}"
else
"#{protocol}://#{host}"
end
end
end
def javascript_path(source, options = {})
path_to_asset(source, {:type => :javascript}.merge(options))
end
alias_method :path_to_javascript, :javascript_path
def stylesheet_path(source, options = {})
path_to_asset(source, {:type => :stylesheet}.merge(options))
end
alias_method :path_to_stylesheet, :stylesheet_path
def image_path(source, options = {})
path_to_asset(source, {:type => :image}.merge(options))
end
alias_method :path_to_image, :image_path
def video_path(source, options = {})
path_to_asset(source, {:type => :video}.merge(options))
end
alias_method :path_to_video, :video_path
def audio_path(source, options = {})
path_to_asset(source, {:type => :audio}.merge(options))
end
alias_method :path_to_audio, :audio_path
def font_path(source, options = {})
path_to_asset(source, {:type => :font}.merge(options))
end
alias_method :path_to_font, :font_path
end
end
end
sprockets-rails-2.0.1/lib/sprockets/rails/task.rb 0000664 0000000 0000000 00000003422 12227535155 0022033 0 ustar 00root root 0000000 0000000 require 'rake'
require 'rake/sprocketstask'
require 'sprockets'
module Sprockets
module Rails
class Task < Rake::SprocketsTask
attr_accessor :app
def initialize(app = nil)
self.app = app
super()
end
def environment
if app
app.assets
else
super
end
end
def output
if app
File.join(app.root, 'public', app.config.assets.prefix)
else
super
end
end
def assets
if app
app.config.assets.precompile
else
super
end
end
def cache_path
if app
"#{app.config.root}/tmp/cache/assets"
else
@cache_path
end
end
attr_writer :cache_path
def define
namespace :assets do
# Override this task change the loaded dependencies
desc "Load asset compile environment"
task :environment do
# Load full Rails environment by default
Rake::Task['environment'].invoke
end
desc "Compile all the assets named in config.assets.precompile"
task :precompile => :environment do
with_logger do
manifest.compile(assets)
end
end
desc "Remove old compiled assets"
task :clean, [:keep] => :environment do |t, args|
keep = Integer(args.keep || 2)
with_logger do
manifest.clean(keep)
end
end
desc "Remove compiled assets"
task :clobber => :environment do
with_logger do
manifest.clobber
rm_rf cache_path if cache_path
end
end
end
end
end
end
end
sprockets-rails-2.0.1/lib/sprockets/railtie.rb 0000664 0000000 0000000 00000007240 12227535155 0021412 0 ustar 00root root 0000000 0000000 require 'rails'
require 'rails/railtie'
require 'action_controller/railtie'
require 'active_support/core_ext/module/remove_method'
require 'sprockets'
require 'sprockets/rails/helper'
module Rails
class Application
# Hack: We need to remove Rails' built in config.assets so we can
# do our own thing.
class Configuration
remove_possible_method :assets
end
# Undefine Rails' assets method before redefining it, to avoid warnings.
remove_possible_method :assets
remove_possible_method :assets=
# Returns Sprockets::Environment for app config.
def assets
@assets ||= Sprockets::Environment.new(root.to_s) do |env|
env.version = ::Rails.env
path = "#{config.root}/tmp/cache/assets/#{::Rails.env}"
env.cache = Sprockets::Cache::FileStore.new(path)
env.context_class.class_eval do
include ::Sprockets::Rails::Helper
end
end
end
attr_writer :assets
end
end
module Sprockets
class Railtie < ::Rails::Railtie
LOOSE_APP_ASSETS = lambda do |filename, path|
path =~ /app\/assets/ && !%w(.js .css).include?(File.extname(filename))
end
class OrderedOptions < ActiveSupport::OrderedOptions
def configure(&block)
self._blocks << block
end
end
config.assets = OrderedOptions.new
config.assets._blocks = []
config.assets.paths = []
config.assets.prefix = "/assets"
config.assets.precompile = [LOOSE_APP_ASSETS, /(?:\/|\\|\A)application\.(css|js)$/]
config.assets.version = ""
config.assets.debug = false
config.assets.compile = true
config.assets.digest = false
rake_tasks do |app|
require 'sprockets/rails/task'
Sprockets::Rails::Task.new(app)
end
config.after_initialize do |app|
config = app.config
manifest_path = File.join(app.root, 'public', config.assets.prefix)
unless config.assets.version.blank?
app.assets.version += "-#{config.assets.version}"
end
# Copy config.assets.paths to Sprockets
config.assets.paths.each do |path|
app.assets.append_path path
end
ActionView::Base.instance_eval do
include Sprockets::Rails::Helper
# Copy relevant config to AV context
self.debug_assets = config.assets.debug
self.digest_assets = config.assets.digest
self.assets_prefix = config.assets.prefix
# Copy over to Sprockets as well
context = app.assets.context_class
context.assets_prefix = config.assets.prefix
context.digest_assets = config.assets.digest
context.config = config.action_controller
if config.assets.compile
self.assets_environment = app.assets
self.assets_manifest = Sprockets::Manifest.new(app.assets, manifest_path)
else
self.assets_manifest = Sprockets::Manifest.new(manifest_path)
end
end
app.assets.js_compressor = config.assets.js_compressor
app.assets.css_compressor = config.assets.css_compressor
# Run app.assets.configure blocks
config.assets._blocks.each do |block|
block.call app.assets
end
# No more configuration changes at this point.
# With cache classes on, Sprockets won't check the FS when files
# change. Preferable in production when the FS only changes on
# deploys when the app restarts.
if config.cache_classes
app.assets = app.assets.index
end
if config.assets.compile
if app.routes.respond_to?(:prepend)
app.routes.prepend do
mount app.assets => config.assets.prefix
end
end
end
end
end
end
sprockets-rails-2.0.1/sprockets-rails.gemspec 0000664 0000000 0000000 00000000756 12227535155 0021350 0 ustar 00root root 0000000 0000000 Gem::Specification.new do |s|
s.name = "sprockets-rails"
s.version = "2.0.1"
s.homepage = "https://github.com/rails/sprockets-rails"
s.summary = "Sprockets Rails integration"
s.license = "MIT"
s.files = Dir["README.md", "lib/**/*.rb", "LICENSE"]
s.add_dependency "sprockets", "~> 2.8"
s.add_dependency "actionpack", ">= 3.0"
s.add_dependency "activesupport", ">= 3.0"
s.add_development_dependency "rake"
s.author = "Joshua Peek"
s.email = "josh@joshpeek.com"
end
sprockets-rails-2.0.1/test/ 0000775 0000000 0000000 00000000000 12227535155 0015625 5 ustar 00root root 0000000 0000000 sprockets-rails-2.0.1/test/fixtures/ 0000775 0000000 0000000 00000000000 12227535155 0017476 5 ustar 00root root 0000000 0000000 sprockets-rails-2.0.1/test/fixtures/bar.css 0000664 0000000 0000000 00000000023 12227535155 0020747 0 ustar 00root root 0000000 0000000 /*= require foo */
sprockets-rails-2.0.1/test/fixtures/bar.js 0000664 0000000 0000000 00000000020 12227535155 0020570 0 ustar 00root root 0000000 0000000 //= require foo
sprockets-rails-2.0.1/test/fixtures/dependency.css 0000664 0000000 0000000 00000000021 12227535155 0022317 0 ustar 00root root 0000000 0000000 /* dependency */
sprockets-rails-2.0.1/test/fixtures/dependency.js 0000664 0000000 0000000 00000000016 12227535155 0022147 0 ustar 00root root 0000000 0000000 // dependency
sprockets-rails-2.0.1/test/fixtures/file1.css 0000664 0000000 0000000 00000000033 12227535155 0021204 0 ustar 00root root 0000000 0000000 /*= require dependency
*/
sprockets-rails-2.0.1/test/fixtures/file1.js 0000664 0000000 0000000 00000000027 12227535155 0021033 0 ustar 00root root 0000000 0000000 //= require dependency
sprockets-rails-2.0.1/test/fixtures/file2.css 0000664 0000000 0000000 00000000033 12227535155 0021205 0 ustar 00root root 0000000 0000000 /*= require dependency
*/
sprockets-rails-2.0.1/test/fixtures/file2.js 0000664 0000000 0000000 00000000027 12227535155 0021034 0 ustar 00root root 0000000 0000000 //= require dependency
sprockets-rails-2.0.1/test/fixtures/foo.css 0000664 0000000 0000000 00000000010 12227535155 0020762 0 ustar 00root root 0000000 0000000 .foo {}
sprockets-rails-2.0.1/test/fixtures/foo.js 0000664 0000000 0000000 00000000010 12227535155 0020606 0 ustar 00root root 0000000 0000000 var Foo; sprockets-rails-2.0.1/test/fixtures/url.css.erb 0000664 0000000 0000000 00000000065 12227535155 0021562 0 ustar 00root root 0000000 0000000 p { background: url(<%= image_path "logo.png" %>); }
sprockets-rails-2.0.1/test/fixtures/url.js.erb 0000664 0000000 0000000 00000000051 12227535155 0021401 0 ustar 00root root 0000000 0000000 var url = '<%= javascript_path :foo %>';
sprockets-rails-2.0.1/test/gemfiles/ 0000775 0000000 0000000 00000000000 12227535155 0017420 5 ustar 00root root 0000000 0000000 sprockets-rails-2.0.1/test/gemfiles/Gemfile.rails-3.0.x 0000664 0000000 0000000 00000000162 12227535155 0022567 0 ustar 00root root 0000000 0000000 source 'https://rubygems.org'
gemspec :path => "./../.."
gem "actionpack", "~> 3.0.0"
gem "railties", "~> 3.0.0"
sprockets-rails-2.0.1/test/gemfiles/Gemfile.rails-3.1.x 0000664 0000000 0000000 00000000441 12227535155 0022570 0 ustar 00root root 0000000 0000000 source 'https://rubygems.org'
gemspec :path => "./../.."
# Patch 3-1-stable to allow new sprockets
gem "actionpack", "~> 3.1.0", :github => "josh/rails", :branch => "3-1-stable-sprockets"
gem "railties", "~> 3.1.0", :github => "josh/rails", :branch => "3-1-stable-sprockets"
gem "tzinfo"
sprockets-rails-2.0.1/test/gemfiles/Gemfile.rails-3.2.x 0000664 0000000 0000000 00000000441 12227535155 0022571 0 ustar 00root root 0000000 0000000 source 'https://rubygems.org'
gemspec :path => "./../.."
# Patch 3-2-stable to allow new sprockets
gem "actionpack", "~> 3.2.0", :github => "josh/rails", :branch => "3-2-stable-sprockets"
gem "railties", "~> 3.2.0", :github => "josh/rails", :branch => "3-2-stable-sprockets"
gem "tzinfo"
sprockets-rails-2.0.1/test/gemfiles/Gemfile.rails-4.0.x 0000664 0000000 0000000 00000000162 12227535155 0022570 0 ustar 00root root 0000000 0000000 source 'https://rubygems.org'
gemspec :path => "./../.."
gem "actionpack", "~> 4.0.0"
gem "railties", "~> 4.0.0"
sprockets-rails-2.0.1/test/test_helper.rb 0000664 0000000 0000000 00000036211 12227535155 0020473 0 ustar 00root root 0000000 0000000 require 'test/unit'
require 'action_view'
require 'sprockets'
require 'sprockets/rails/helper'
class HelperTest < Test::Unit::TestCase
FIXTURES_PATH = File.expand_path("../fixtures", __FILE__)
# class ActionView::Base
# include ::Sprockets::Rails::Helper
# end
def setup
assets = @assets = Sprockets::Environment.new
@assets.append_path FIXTURES_PATH
@assets.context_class.class_eval do
include ::Sprockets::Rails::Helper
end
@view = ActionView::Base.new
@view.extend ::Sprockets::Rails::Helper
@view.assets_environment = @assets
@view.assets_prefix = "/assets"
# Rails 2.x
unless @view.respond_to?(:config)
@view.class_eval { attr_accessor :config }
@view.config = Struct.new(:asset_host).new
end
@assets.context_class.assets_prefix = @view.assets_prefix
@assets.context_class.config = @view.config
@foo_js_digest = @assets['foo.js'].digest
@foo_css_digest = @assets['foo.css'].digest
end
def test_truth
end
end
class NoHostHelperTest < HelperTest
def test_javascript_include_tag
assert_equal %(),
@view.javascript_include_tag("static")
assert_equal %(),
@view.javascript_include_tag("static.js")
assert_equal %(),
@view.javascript_include_tag(:static)
assert_equal %(),
@view.javascript_include_tag("/elsewhere.js")
assert_equal %(\n),
@view.javascript_include_tag("/script1.js", "script2.js")
assert_equal %(),
@view.javascript_include_tag("http://example.com/script")
assert_equal %(),
@view.javascript_include_tag("http://example.com/script.js")
assert_equal %(),
@view.javascript_include_tag("//example.com/script.js")
assert_equal %(),
@view.javascript_include_tag("static", :defer => "defer")
assert_equal %(),
@view.javascript_include_tag("static", :async => "async")
end
def test_stylesheet_link_tag
assert_equal %(),
@view.stylesheet_link_tag("static")
assert_equal %(),
@view.stylesheet_link_tag("static.css")
assert_equal %(),
@view.stylesheet_link_tag(:static)
assert_equal %(),
@view.stylesheet_link_tag("/elsewhere.css")
assert_equal %(\n),
@view.stylesheet_link_tag("/style1.css", "style2.css")
assert_equal %(),
@view.stylesheet_link_tag("http://www.example.com/styles/style")
assert_equal %(),
@view.stylesheet_link_tag("http://www.example.com/styles/style.css")
assert_equal %(),
@view.stylesheet_link_tag("//www.example.com/styles/style.css")
assert_equal %(),
@view.stylesheet_link_tag("print", :media => "print")
assert_equal %(),
@view.stylesheet_link_tag("print", :media => "")
end
def test_javascript_path
assert_equal "/javascripts/xmlhr.js", @view.javascript_path("xmlhr")
assert_equal "/javascripts/xmlhr.js", @view.javascript_path("xmlhr.js")
assert_equal "/javascripts/super/xmlhr.js", @view.javascript_path("super/xmlhr")
assert_equal "/super/xmlhr.js", @view.javascript_path("/super/xmlhr")
assert_equal "/javascripts/xmlhr.js?foo=1", @view.javascript_path("xmlhr.js?foo=1")
assert_equal "/javascripts/xmlhr.js?foo=1", @view.javascript_path("xmlhr?foo=1")
assert_equal "/javascripts/xmlhr.js#hash", @view.javascript_path("xmlhr.js#hash")
assert_equal "/javascripts/xmlhr.js#hash", @view.javascript_path("xmlhr#hash")
assert_equal "/javascripts/xmlhr.js?foo=1#hash", @view.javascript_path("xmlhr.js?foo=1#hash")
end
def test_stylesheet_path
assert_equal "/stylesheets/bank.css", @view.stylesheet_path("bank")
assert_equal "/stylesheets/bank.css", @view.stylesheet_path("bank.css")
assert_equal "/stylesheets/subdir/subdir.css", @view.stylesheet_path("subdir/subdir")
assert_equal "/subdir/subdir.css", @view.stylesheet_path("/subdir/subdir.css")
assert_equal "/stylesheets/bank.css?foo=1", @view.stylesheet_path("bank.css?foo=1")
assert_equal "/stylesheets/bank.css?foo=1", @view.stylesheet_path("bank?foo=1")
assert_equal "/stylesheets/bank.css#hash", @view.stylesheet_path("bank.css#hash")
assert_equal "/stylesheets/bank.css#hash", @view.stylesheet_path("bank#hash")
assert_equal "/stylesheets/bank.css?foo=1#hash", @view.stylesheet_path("bank.css?foo=1#hash")
end
end
class RelativeHostHelperTest < HelperTest
def setup
super
@view.config.asset_host = "assets.example.com"
end
def test_javascript_path
assert_equal "//assets.example.com/javascripts/xmlhr.js", @view.javascript_path("xmlhr")
assert_equal "//assets.example.com/javascripts/xmlhr.js", @view.javascript_path("xmlhr.js")
assert_equal "//assets.example.com/javascripts/super/xmlhr.js", @view.javascript_path("super/xmlhr")
assert_equal "//assets.example.com/super/xmlhr.js", @view.javascript_path("/super/xmlhr")
assert_equal "//assets.example.com/javascripts/xmlhr.js?foo=1", @view.javascript_path("xmlhr.js?foo=1")
assert_equal "//assets.example.com/javascripts/xmlhr.js?foo=1", @view.javascript_path("xmlhr?foo=1")
assert_equal "//assets.example.com/javascripts/xmlhr.js#hash", @view.javascript_path("xmlhr.js#hash")
assert_equal "//assets.example.com/javascripts/xmlhr.js#hash", @view.javascript_path("xmlhr#hash")
assert_equal "//assets.example.com/javascripts/xmlhr.js?foo=1#hash", @view.javascript_path("xmlhr.js?foo=1#hash")
assert_equal %(),
@view.javascript_include_tag("foo")
assert_equal %(),
@view.javascript_include_tag("foo.js")
assert_equal %(),
@view.javascript_include_tag(:foo)
end
def test_stylesheet_path
assert_equal "//assets.example.com/stylesheets/bank.css", @view.stylesheet_path("bank")
assert_equal "//assets.example.com/stylesheets/bank.css", @view.stylesheet_path("bank.css")
assert_equal "//assets.example.com/stylesheets/subdir/subdir.css", @view.stylesheet_path("subdir/subdir")
assert_equal "//assets.example.com/subdir/subdir.css", @view.stylesheet_path("/subdir/subdir.css")
assert_equal "//assets.example.com/stylesheets/bank.css?foo=1", @view.stylesheet_path("bank.css?foo=1")
assert_equal "//assets.example.com/stylesheets/bank.css?foo=1", @view.stylesheet_path("bank?foo=1")
assert_equal "//assets.example.com/stylesheets/bank.css#hash", @view.stylesheet_path("bank.css#hash")
assert_equal "//assets.example.com/stylesheets/bank.css#hash", @view.stylesheet_path("bank#hash")
assert_equal "//assets.example.com/stylesheets/bank.css?foo=1#hash", @view.stylesheet_path("bank.css?foo=1#hash")
assert_equal %(),
@view.stylesheet_link_tag("foo")
assert_equal %(),
@view.stylesheet_link_tag("foo.css")
assert_equal %(),
@view.stylesheet_link_tag(:foo)
end
def test_asset_url
assert_equal "var url = '//assets.example.com/assets/foo.js';\n", @assets["url.js"].to_s
assert_equal "p { background: url(//assets.example.com/images/logo.png); }\n", @assets["url.css"].to_s
end
end
class NoDigestHelperTest < NoHostHelperTest
def setup
super
@view.digest_assets = false
@assets.context_class.digest_assets = false
end
def test_javascript_include_tag
super
assert_equal %(),
@view.javascript_include_tag("foo")
assert_equal %(),
@view.javascript_include_tag("foo.js")
assert_equal %(),
@view.javascript_include_tag(:foo)
end
def test_stylesheet_link_tag
super
assert_equal %(),
@view.stylesheet_link_tag("foo")
assert_equal %(),
@view.stylesheet_link_tag("foo.css")
assert_equal %(),
@view.stylesheet_link_tag(:foo)
end
def test_javascript_path
super
assert_equal "/assets/foo.js", @view.javascript_path("foo")
end
def test_stylesheet_path
super
assert_equal "/assets/foo.css", @view.stylesheet_path("foo")
end
def test_asset_digest
assert_equal nil, @view.asset_digest("foo.js")
assert_equal nil, @view.asset_digest("foo.css")
end
def test_asset_url
assert_equal "var url = '/assets/foo.js';\n", @assets["url.js"].to_s
assert_equal "p { background: url(/images/logo.png); }\n", @assets["url.css"].to_s
end
end
class DigestHelperTest < NoHostHelperTest
def setup
super
@view.digest_assets = true
@assets.context_class.digest_assets = true
end
def test_javascript_include_tag
super
assert_equal %(),
@view.javascript_include_tag("foo")
assert_equal %(),
@view.javascript_include_tag("foo.js")
assert_equal %(),
@view.javascript_include_tag(:foo)
end
def test_stylesheet_link_tag
super
assert_equal %(),
@view.stylesheet_link_tag("foo")
assert_equal %(),
@view.stylesheet_link_tag("foo.css")
assert_equal %(),
@view.stylesheet_link_tag(:foo)
end
def test_javascript_path
super
assert_equal "/assets/foo-#{@foo_js_digest}.js", @view.javascript_path("foo")
end
def test_stylesheet_path
super
assert_equal "/assets/foo-#{@foo_css_digest}.css", @view.stylesheet_path("foo")
end
def test_asset_digest
assert_equal @foo_js_digest, @view.asset_digest("foo.js")
assert_equal @foo_css_digest, @view.asset_digest("foo.css")
end
def test_asset_digest_path
assert_equal "foo-#{@foo_js_digest}.js", @view.asset_digest_path("foo.js")
assert_equal "foo-#{@foo_css_digest}.css", @view.asset_digest_path("foo.css")
end
def test_asset_url
assert_equal "var url = '/assets/foo-#{@foo_js_digest}.js';\n", @assets["url.js"].to_s
assert_equal "p { background: url(/images/logo.png); }\n", @assets["url.css"].to_s
end
end
class DebugHelperTest < NoHostHelperTest
def setup
super
@view.debug_assets = true
end
def test_javascript_include_tag
super
assert_equal %(),
@view.javascript_include_tag(:foo)
assert_equal %(\n),
@view.javascript_include_tag(:bar)
assert_equal %(\n\n),
@view.javascript_include_tag(:file1, :file2)
end
def test_stylesheet_link_tag
super
assert_equal %(),
@view.stylesheet_link_tag(:foo)
assert_equal %(\n),
@view.stylesheet_link_tag(:bar)
assert_equal %(\n\n),
@view.stylesheet_link_tag(:file1, :file2)
end
def test_javascript_path
super
assert_equal "/assets/foo.js", @view.javascript_path("foo")
end
def test_stylesheet_path
super
assert_equal "/assets/foo.css", @view.stylesheet_path("foo")
end
end
class ManifestHelperTest < NoHostHelperTest
def setup
super
@manifest = Sprockets::Manifest.new(@assets, FIXTURES_PATH)
@manifest.assets["foo.js"] = "foo-#{@foo_js_digest}.js"
@manifest.assets["foo.css"] = "foo-#{@foo_css_digest}.css"
@view.digest_assets = true
@view.assets_environment = nil
@view.assets_manifest = @manifest
end
def test_javascript_include_tag
super
assert_equal %(),
@view.javascript_include_tag("foo")
assert_equal %(),
@view.javascript_include_tag("foo.js")
assert_equal %(),
@view.javascript_include_tag(:foo)
end
def test_stylesheet_link_tag
super
assert_equal %(),
@view.stylesheet_link_tag("foo")
assert_equal %(),
@view.stylesheet_link_tag("foo.css")
assert_equal %(),
@view.stylesheet_link_tag(:foo)
end
def test_javascript_path
super
assert_equal "/assets/foo-#{@foo_js_digest}.js", @view.javascript_path("foo")
end
def test_stylesheet_path
super
assert_equal "/assets/foo-#{@foo_css_digest}.css", @view.stylesheet_path("foo")
end
def test_asset_digest_path
assert_equal "foo-#{@foo_js_digest}.js", @view.asset_digest_path("foo.js")
assert_equal "foo-#{@foo_css_digest}.css", @view.asset_digest_path("foo.css")
end
def test_asset_digest
assert_equal @foo_js_digest, @view.asset_digest("foo.js")
assert_equal @foo_css_digest, @view.asset_digest("foo.css")
end
end
sprockets-rails-2.0.1/test/test_railtie.rb 0000664 0000000 0000000 00000007640 12227535155 0020651 0 ustar 00root root 0000000 0000000 require 'test/unit'
require 'active_support'
require 'active_support/testing/isolation'
class TestBoot < Test::Unit::TestCase
include ActiveSupport::Testing::Isolation
ROOT = File.expand_path("../../tmp/app", __FILE__)
FIXTURES_PATH = File.expand_path("../fixtures", __FILE__)
attr_reader :app
def setup
require 'rails'
# Can't seem to get initialize to run w/o this
require 'action_controller/railtie'
require 'active_support/dependencies'
require 'tzinfo'
ENV['RAILS_ENV'] = 'test'
FileUtils.mkdir_p ROOT
Dir.chdir ROOT
@app = Class.new(Rails::Application)
# Get bitched at if you don't set these
@app.config.eager_load = false
@app.config.time_zone = 'UTC'
@app.config.middleware ||= Rails::Configuration::MiddlewareStackProxy.new
@app.config.active_support.deprecation = :notify
end
def test_initialize
app.initialize!
end
end
class TestRailtie < TestBoot
def setup
require 'sprockets/railtie'
super
end
def test_defaults
app.initialize!
assert env = app.assets
assert_kind_of Sprockets::Environment, env
assert_equal ROOT, env.root
assert_equal "test", env.version
assert env.cache
assert_equal [], env.paths
assert_nil env.js_compressor
assert_nil env.css_compressor
end
def test_app_asset_available_when_compile
assert_equal true, app.config.assets.compile
app.initialize!
assert env = app.assets
end
def test_app_asset_available_when_no_compile
app.configure do
config.assets.compile = false
end
assert_equal false, app.config.assets.compile
app.initialize!
assert env = app.assets
end
def test_copies_paths
app.configure do
config.assets.paths << "javascripts"
config.assets.paths << "stylesheets"
end
app.initialize!
assert env = app.assets
assert_equal ["#{ROOT}/javascripts", "#{ROOT}/stylesheets"],
env.paths.sort
end
def test_compressors
app.configure do
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
end
app.initialize!
assert env = app.assets
assert_equal Sprockets::UglifierCompressor, env.js_compressor
assert_equal Sprockets::SassCompressor, env.css_compressor
end
def test_version
app.configure do
config.assets.version = 'v2'
end
app.initialize!
assert env = app.assets
assert_equal "test-v2", env.version
end
def test_configure
app.configure do
config.assets.configure do |env|
env.append_path "javascripts"
end
config.assets.configure do |env|
env.append_path "stylesheets"
end
end
app.initialize!
assert env = app.assets
assert_equal ["#{ROOT}/javascripts", "#{ROOT}/stylesheets"],
env.paths.sort
end
def test_environment_is_frozen_if_caching_classes
app.configure do
config.cache_classes = true
end
app.initialize!
assert env = app.assets
assert_kind_of Sprockets::Index, env
end
def test_action_view_helper
app.configure do
config.assets.paths << FIXTURES_PATH
end
app.initialize!
assert app.assets.paths.include?(FIXTURES_PATH)
assert_equal false, ActionView::Base.debug_assets
assert_equal false, ActionView::Base.digest_assets
assert_equal "/assets", ActionView::Base.assets_prefix
assert_equal app.assets, ActionView::Base.assets_environment
assert_match %r{public/assets/manifest-.*.json}, ActionView::Base.assets_manifest.path
@view = ActionView::Base.new
assert_equal "/javascripts/xmlhr.js", @view.javascript_path("xmlhr")
assert_equal "/assets/foo.js", @view.javascript_path("foo")
end
def test_sprockets_context_helper
app.initialize!
assert env = app.assets
assert_equal "/assets", env.context_class.assets_prefix
assert_equal false, env.context_class.digest_assets
assert_equal nil, env.context_class.config.asset_host
end
end
sprockets-rails-2.0.1/test/test_task.rb 0000664 0000000 0000000 00000005407 12227535155 0020161 0 ustar 00root root 0000000 0000000 require 'test/unit'
require 'tmpdir'
require 'sprockets'
require 'sprockets/rails/task'
class TestTask < Test::Unit::TestCase
FIXTURES_PATH = File.expand_path("../fixtures", __FILE__)
def setup
@rake = Rake::Application.new
Rake.application = @rake
@assets = Sprockets::Environment.new
@assets.append_path FIXTURES_PATH
@dir = File.join(Dir::tmpdir, 'rails/task')
@manifest = Sprockets::Manifest.new(@assets, @dir)
@environment_ran = false
# Stub Rails environment task
@rake.define_task Rake::Task, :environment do
@environment_ran = true
end
Sprockets::Rails::Task.new do |t|
t.environment = @assets
t.manifest = @manifest
t.assets = ['foo.js', 'foo-modified.js']
t.log_level = :fatal
end
end
def teardown
Rake.application = nil
FileUtils.rm_rf(@dir)
assert Dir["#{@dir}/*"].empty?
end
def test_precompile
assert !@environment_ran
digest_path = @assets['foo.js'].digest_path
assert !File.exist?("#{@dir}/#{digest_path}")
@rake['assets:precompile'].invoke
assert @environment_ran
assert Dir["#{@dir}/manifest-*.json"].first
assert File.exist?("#{@dir}/#{digest_path}")
end
def test_clobber
assert !@environment_ran
digest_path = @assets['foo.js'].digest_path
@rake['assets:precompile'].invoke
assert File.exist?("#{@dir}/#{digest_path}")
assert @environment_ran
@rake['assets:clobber'].invoke
assert !File.exist?("#{@dir}/#{digest_path}")
end
def test_clean
assert !@environment_ran
digest_path = @assets['foo.js'].digest_path
@rake['assets:precompile'].invoke
assert File.exist?("#{@dir}/#{digest_path}")
assert @environment_ran
@rake['assets:clean'].invoke
assert File.exist?("#{@dir}/#{digest_path}")
end
def test_clean_with_keep_specified
assert !@environment_ran
path = @assets['foo.js'].pathname
new_path = path.join("../foo-modified.js")
FileUtils.cp(path, new_path)
assert File.exist?(new_path)
digest_path = @assets['foo-modified.js'].digest_path
@rake['assets:precompile'].invoke
assert File.exist?("#{@dir}/#{digest_path}")
assert @environment_ran
# clean environment
setup
# modify file
File.open(new_path, "a") {|f| f.write("var Bar;") }
@rake['assets:precompile'].invoke
old_digest_path = digest_path
digest_path = @assets['foo-modified.js'].digest_path
refute_equal old_digest_path, digest_path
assert File.exist?("#{@dir}/#{old_digest_path}")
assert File.exist?("#{@dir}/#{digest_path}")
@rake['assets:clean'].invoke(0)
assert File.exist?("#{@dir}/#{digest_path}")
refute File.exist?("#{@dir}/#{old_digest_path}")
ensure
FileUtils.rm(new_path) if new_path
end
end