Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Source maps #528

Closed
wants to merge 60 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
ab46ff6
use a set in `resolve_dependencies` so we don't need two data structures
tenderlove Nov 14, 2013
64d2d64
Fix searching for index or component with `.`
josh Nov 23, 2013
54d5dbe
Sprockets 2.10.1
josh Nov 23, 2013
81ee87f
Merge branch '2.x'
josh Nov 23, 2013
f36e67a
Update homepage
schneems Dec 5, 2013
59727a1
Merge pull request #510 from schneems/schneems/fix-homepage
sstephenson Dec 5, 2013
01fed0b
Correct minor spelling mistakes in README.md
righi Dec 5, 2013
43cb7d6
raise FileNotFound if stat returns nil
sonnym Dec 7, 2013
deb4bb2
Require Ruby 1.9.3 or greater
josh Dec 11, 2013
6e9dad3
Merge pull request #511 from righi/master
josh Dec 11, 2013
69f5c27
remove stubbing from tests
sonnym Dec 11, 2013
659c7d5
Eager require tilt deps
josh Dec 11, 2013
09e8032
Merge pull request #513 from sonnym/guard_against_nil_stat
josh Dec 11, 2013
43f4cb5
Require tilt 1.4.x
josh Dec 11, 2013
7d23344
Vendor CoffeeScript tilt template
josh Dec 11, 2013
fe825ee
Vendor Less tilt template
josh Dec 11, 2013
77392b5
Vendor String tilt template
josh Dec 11, 2013
f94c883
Vendor tilt erb template
josh Dec 11, 2013
f22526f
Drop Sprockets 1.x compat mode
josh Dec 11, 2013
6db01c9
Remove component.json support
josh Dec 11, 2013
7c56f3a
ws
josh Dec 11, 2013
2b6ff3b
Hash#key is supported
josh Dec 11, 2013
a848c35
All the encodings
josh Dec 11, 2013
923ee20
Some ruby 1.9 love
josh Dec 11, 2013
c221d88
Ignore broken symlinks
josh Dec 11, 2013
8a19a1e
Move entires and stat to paths concern
josh Dec 11, 2013
6c7b2dc
Replace each_entry helper
josh Dec 11, 2013
05d382d
Rename find logical paths helper
josh Dec 11, 2013
ec04deb
Create Sprockets::Template
josh Dec 19, 2013
4b9ce5a
Avoid tilt require
josh Dec 19, 2013
2c0444c
No one wanted to prepare anyway
josh Dec 19, 2013
a9e4bad
Remove Tilt references from tests
josh Dec 19, 2013
0899459
Pass data to template for test
josh Dec 19, 2013
c6047e2
Remove String template
josh Dec 19, 2013
73feb6b
Mini tilt template subclass
josh Dec 19, 2013
0d8bb6c
Sprockets namespace
josh Dec 19, 2013
314734e
Drop tilt dep
josh Dec 19, 2013
79d5fa7
Implement render instead of evaluate
josh Dec 19, 2013
6199931
Remove prepare
josh Dec 19, 2013
3d00def
Remove template#file
josh Dec 19, 2013
b5b7416
Remove engine initialize as well
josh Dec 19, 2013
d93b48f
Process doesn't need to inherit from template
josh Dec 19, 2013
743c1b1
default_mime_type can just be a class method
josh Dec 19, 2013
974801d
Skip self arg
josh Dec 19, 2013
ddba36b
ditto
josh Dec 19, 2013
488787e
Merge pull request #516 from sstephenson/tiltless
josh Dec 19, 2013
60618d0
Prepare for 3.0 release
josh Feb 9, 2014
3a42e11
Update LICENSE year
josh Feb 9, 2014
ae92dd8
Change default digest to SHA1
josh Feb 9, 2014
437af58
Note SHA1 digest change
josh Feb 9, 2014
3dcf8bf
Fix changing digest
josh Feb 9, 2014
f3a1c15
Skip jruby
josh Feb 9, 2014
47dc70c
Catch execjs error subclass
josh Feb 9, 2014
cf9c96e
Merge branch 'master' into sha1-digest
josh Feb 9, 2014
b535c0a
Add minifying section
josh Feb 9, 2014
5620203
Revert "Mark session as "skipped" so no Set-Cookie header is set"
josh Feb 9, 2014
0ab1514
Link to context.rb from readme
josh Feb 9, 2014
cd21590
Merge branch 'set' of https://github.com/tenderlove/sprockets into te…
josh Feb 9, 2014
cc5a169
Note that stub should only be used at the bundle top level
josh Feb 13, 2014
0633c14
Merge branch 'master' into source-maps
ConradIrwin Feb 14, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ language: ruby
rvm:
- 1.9.3
- 2.0.0
- jruby-19mode

notifications:
email: false
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Copyright (c) 2011 Sam Stephenson
Copyright (c) 2011 Joshua Peek
Copyright (c) 2014 Sam Stephenson
Copyright (c) 2014 Joshua Peek

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
32 changes: 23 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Install Sprockets from RubyGems:

Or include it in your project's `Gemfile` with Bundler:

gem 'sprockets', '~> 2.0'
gem 'sprockets', '~> 3.0'

# Understanding the Sprockets Environment #

Expand Down Expand Up @@ -139,6 +139,15 @@ filename. For example, a CSS file written in SCSS might have the name
`layout.css.scss`, while a JavaScript file written in CoffeeScript
might have the name `dialog.js.coffee`.

## Minifying Assets ##

Several JavaScript and CSS minifiers are available through shorthand.

``` ruby
environment.js_compressor = :uglify
environment.css_compressor = :scss
```

## Styling with Sass and SCSS ##

[Sass](http://sass-lang.com/) is a language that compiles to CSS and
Expand Down Expand Up @@ -237,7 +246,7 @@ include:
database, in a JavaScript asset via JSON
- embedding version constants loaded from another file

See the [Helper Methods](#FIXME) section for more information about
See the [Helper Methods](lib/sprockets/context.rb) section for more information about
interacting with `Sprockets::Context` instances via ERB.

### String Interpolation Syntax ###
Expand Down Expand Up @@ -339,14 +348,14 @@ asset's cache in response to a change in another file.
### The `depend_on_asset` Directive ###

`depend_on_asset` *path* works like `depend_on`, but operates
recursively reading the the file and following the directives found.
recursively reading the file and following the directives found.

### The `stub` Directive ###

`stub` *path* allows dependency to be excluded from the asset bundle.
The *path* must be a valid asset and may or may not already be part
of the bundle. Once stubbed, it is blacklisted and can't be brought
back by any other `require`.
of the bundle. `stub` should only be used at the top level bundle, not
within any subdependencies.

# Development #

Expand All @@ -366,6 +375,11 @@ submit a pull request.

## Version History ##

**3.0.0**

* Default digest changed to SHA1. To continue using MD5.
`env.digest_class = Digest::MD5`.

**2.10.0** (May 24, 2013)

* Support for `bower.json`
Expand Down Expand Up @@ -398,7 +412,7 @@ submit a pull request.

**2.8.0** (October 16, 2012)

* Allow manifest location to be seperated from output directory
* Allow manifest location to be separated from output directory
* Pass logical path and absolute path to each_logical_path iterator

**2.7.0** (October 10, 2012)
Expand Down Expand Up @@ -471,7 +485,7 @@ submit a pull request.

**2.1.2** (November 20, 2011)

* Disabled If-Modified-Since server checks. Fixes some browser caching issues when serving the asset body only. If-None-Match caching is sufficent.
* Disabled If-Modified-Since server checks. Fixes some browser caching issues when serving the asset body only. If-None-Match caching is sufficient.

**2.1.1** (November 18, 2011)

Expand Down Expand Up @@ -504,9 +518,9 @@ submit a pull request.

# License #

Copyright &copy; 2011 Sam Stephenson <<[email protected]>>
Copyright &copy; 2014 Sam Stephenson <<[email protected]>>

Copyright &copy; 2011 Joshua Peek <<[email protected]>>
Copyright &copy; 2014 Joshua Peek <<[email protected]>>

Sprockets is distributed under an MIT-style license. See LICENSE for
details.
14 changes: 7 additions & 7 deletions lib/sprockets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ 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"
autoload :EjsTemplate, "sprockets/ejs_template"
autoload :ERBTemplate, "sprockets/erb_template"
autoload :JstProcessor, "sprockets/jst_processor"
autoload :LessTemplate, "sprockets/less_template"
autoload :Processor, "sprockets/processor"
autoload :SassCacheStore, "sprockets/sass_cache_store"
autoload :SassFunctions, "sprockets/sass_functions"
Expand Down Expand Up @@ -86,23 +90,19 @@ 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', Tilt::CoffeeScriptTemplate
register_engine '.coffee', CoffeeScriptTemplate

# JST engines
register_engine '.jst', JstProcessor
register_engine '.eco', EcoTemplate
register_engine '.ejs', EjsTemplate

# CSS engines
register_engine '.less', Tilt::LessTemplate
register_engine '.less', LessTemplate
register_engine '.sass', SassTemplate
register_engine '.scss', ScssTemplate

# Other
register_engine '.erb', Tilt::ERBTemplate
register_engine '.str', Tilt::StringTemplate
register_engine '.erb', ERBTemplate
end
15 changes: 8 additions & 7 deletions lib/sprockets/asset_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ def initialize(environment, path)
def search_paths
paths = [pathname.to_s]

path_without_extensions = extensions.inject(pathname) { |p, ext| p.sub(ext, '') }
extension = format_extension
path_without_extension = extension ?
pathname.sub(extension, '') :
pathname

# optimization: bower.json can only be nested one level deep
if !path_without_extensions.to_s.index('/')
paths << path_without_extensions.join("bower.json").to_s
# DEPRECATED bower configuration file
paths << path_without_extensions.join("component.json").to_s
if !path_without_extension.to_s.index('/')
paths << path_without_extension.join("bower.json").to_s
end

if pathname.basename(extensions.join).to_s != 'index'
paths << path_without_extensions.join("index#{extensions.join}").to_s
if pathname.basename(extension.to_s).to_s != 'index'
paths << path_without_extension.join("index#{extension}").to_s
end

paths
Expand Down
113 changes: 5 additions & 108 deletions lib/sprockets/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ class Base

# Returns a `Digest` implementation class.
#
# Defaults to `Digest::MD5`.
# Defaults to `Digest::SHA1`.
attr_reader :digest_class

# Assign a `Digest` implementation class. This maybe any Ruby
# `Digest::` implementation such as `Digest::MD5` or
# `Digest::SHA1`.
# `Digest::` implementation such as `Digest::SHA1` or
# `Digest::MD5`.
#
# environment.digest_class = Digest::SHA1
# environment.digest_class = Digest::MD5
#
def digest_class=(klass)
expire_index!
Expand Down Expand Up @@ -130,7 +130,7 @@ def resolve(logical_path, options = {})
args = attributes_for(logical_path).search_paths + [options]
@trail.find(*args) do |path|
pathname = Pathname.new(path)
if %w( bower.json component.json ).include?(pathname.basename.to_s)
if pathname.basename.to_s == "bower.json"
bower = json_decode(pathname.read)
case bower['main']
when String
Expand Down Expand Up @@ -218,20 +218,6 @@ def index
attr_accessor :default_external_encoding
end

# Works like `Dir.entries`.
#
# Subclasses may cache this method.
def entries(pathname)
@trail.entries(pathname)
end

# Works like `File.stat`.
#
# Subclasses may cache this method.
def stat(path)
@trail.stat(path)
end

# Read and compute digest of filename.
#
# Subclasses may cache this method.
Expand Down Expand Up @@ -296,59 +282,6 @@ def [](*args)
find_asset(*args)
end

def each_entry(root, &block)
return to_enum(__method__, root) unless block_given?
root = Pathname.new(root) unless root.is_a?(Pathname)

paths = []
entries(root).sort.each do |filename|
path = root.join(filename)
paths << path

if stat(path).directory?
each_entry(path) do |subpath|
paths << subpath
end
end
end

paths.sort_by(&:to_s).each(&block)

nil
end

def each_file
return to_enum(__method__) unless block_given?
paths.each do |root|
each_entry(root) do |path|
if !stat(path).directory?
yield path
end
end
end
nil
end

def each_logical_path(*args, &block)
return to_enum(__method__, *args) unless block_given?
filters = args.flatten
files = {}
each_file do |filename|
if logical_path = logical_path_for_filename(filename, filters)
unless files[logical_path]
if block.arity == 2
yield logical_path, filename.to_s
else
yield logical_path
end
end

files[logical_path] = true
end
end
nil
end

# Pretty inspect
def inspect
"#<#{self.class}:0x#{object_id.to_s(16)} " +
Expand Down Expand Up @@ -406,42 +339,6 @@ def circular_call_protection(path)
Thread.current[:sprockets_circular_calls] = nil if reset
end

def logical_path_for_filename(filename, filters)
logical_path = attributes_for(filename).logical_path.to_s

if matches_filter(filters, logical_path, filename)
return logical_path
end

# If filename is an index file, retest with alias
if File.basename(logical_path)[/[^\.]+/, 0] == 'index'
path = logical_path.sub(/\/index\./, '.')
if matches_filter(filters, path, filename)
return path
end
end

nil
end

def matches_filter(filters, logical_path, filename)
return true if filters.empty?

filters.any? do |filter|
if filter.is_a?(Regexp)
filter.match(logical_path)
elsif filter.respond_to?(:call)
if filter.arity == 1
filter.call(logical_path)
else
filter.call(logical_path, filename.to_s)
end
else
File.fnmatch(filter.to_s, logical_path)
end
end
end

def json_decode(obj)
JSON.parse(obj, create_additions: false)
end
Expand Down
12 changes: 5 additions & 7 deletions lib/sprockets/bundled_asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BundledAsset < Asset
def initialize(environment, logical_path, pathname)
super(environment, logical_path, pathname)

@processed_asset = environment.find_asset(pathname, :bundle => false)
@processed_asset = environment.find_asset(pathname, bundle: false)
@required_assets = @processed_asset.required_assets
@dependency_paths = @processed_asset.dependency_paths

Expand All @@ -26,11 +26,9 @@ def initialize(environment, logical_path, pathname)

# Run bundle processors on concatenated source
context = environment.context_class.new(environment, logical_path, pathname)
options = { :data => @source,
:map => @map,
:processors => environment.bundle_processors(content_type) }
@source = context.evaluate(pathname, options)
@map = options[:map]

@source = context.evaluate(pathname, data: @source, map: @map,
processors: environment.bundle_processors(content_type))

@mtime = (to_a + @dependency_paths).map(&:mtime).max
@length = Rack::Utils.bytesize(source)
Expand All @@ -41,7 +39,7 @@ def initialize(environment, logical_path, pathname)
def init_with(environment, coder)
super

@processed_asset = environment.find_asset(pathname, :bundle => false)
@processed_asset = environment.find_asset(pathname, bundle: false)
@required_assets = @processed_asset.required_assets

if @processed_asset.dependency_digest != coder['required_assets_digest']
Expand Down
9 changes: 2 additions & 7 deletions lib/sprockets/charset_normalizer.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,11 +16,8 @@ module Sprockets
#
# environment.unregister_bundle_processor 'text/css', Sprockets::CharsetNormalizer
#
class CharsetNormalizer < Tilt::Template
def prepare
end

def evaluate(context, locals, &block)
class CharsetNormalizer < Template
def render(context)
charset = nil

# Find and strip out any `@charset` definitions
Expand Down
Loading