nanoc-sprockets-filter 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +96 -0
- data/Rakefile +2 -0
- data/lib/nanoc/filters/sprockets.rb +46 -0
- data/lib/nanoc/helpers/sprockets.rb +55 -0
- data/lib/nanoc-sprockets-filter.rb +15 -0
- data/nanoc-sprockets-filter.gemspec +23 -0
- metadata +126 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Yann Lugrin
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# Nanoc::Sprockets::Filter
|
2
|
+
|
3
|
+
A nanoc filter to use [Sprockets][sprockets], a Ruby library for compiling and serving web assets.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'nanoc-sprockets-filter'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install nanoc-sprockets-filter
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
We recommand to install [sprockets-sass][sprockets-sass] and [sprockets-helpers][sprockets-helpers]
|
22
|
+
gems for a better integration. Use [uglifier][uglifier] gem to minify
|
23
|
+
javascripts. All this dependencies is optionnal and you can use another
|
24
|
+
compressor supported by Sprockets.
|
25
|
+
|
26
|
+
Require dependencies and configure Sprockets helpers to generate assets
|
27
|
+
with digest.
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'sass'
|
31
|
+
require 'uglifier'
|
32
|
+
require 'sprockets-sass'
|
33
|
+
require 'nanoc-sprockets-filter'
|
34
|
+
|
35
|
+
Nanoc::Helpers::Sprockets.configure do |config|
|
36
|
+
config.environment = Nanoc::Filters::Sprockets.environment
|
37
|
+
config.prefix = '/assets'
|
38
|
+
config.digest = true
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
Add compile rule for stylesheets and javascripts, `css_compressor`and
|
43
|
+
`js_compressor` is optionnal and value can be replaced by any compressor
|
44
|
+
supported by Sprockets.
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
compile %r{/assets/(stylesheets|javascripts)/.+/} do
|
48
|
+
filter :sprockets, {
|
49
|
+
:css_compressor => :scss
|
50
|
+
:js_compressor => :uglifier
|
51
|
+
}
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
You can use [nanoc-gzip-filter][nanoc-gzip-filter] to create a
|
56
|
+
gzipped version of stylesheets and javascripts files.
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
compile %r{/assets/(stylesheets|javascripts)/.+/}, :rep => :gzip do
|
60
|
+
filter :sprockets, {
|
61
|
+
:css_compressor => :scss
|
62
|
+
:js_compressor => :uglifier
|
63
|
+
}
|
64
|
+
filter :gzip
|
65
|
+
end
|
66
|
+
```
|
67
|
+
|
68
|
+
Add route rule for all assets and use [sprockets-helpers][sprockets-helpers]
|
69
|
+
to generate file path.
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
route '/assets/*/' do
|
73
|
+
Nanoc::Helpers::Sprockets.asset_path(item)
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
route '/assets/*/', :rep => :gzip do
|
79
|
+
Nanoc::Helpers::Sprockets.asset_path(item) + '.gz'
|
80
|
+
end
|
81
|
+
```
|
82
|
+
|
83
|
+
## Contributing
|
84
|
+
|
85
|
+
1. Fork it
|
86
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
87
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
88
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
89
|
+
5. Create new Pull Request
|
90
|
+
|
91
|
+
[sprockets]: https://github.com/sstephenson/sprockets "Rack-based asset packaging"
|
92
|
+
[sprockets-sass]: https://github.com/petebrowne/sprockets-sass "Better Sass integration with Sprockets 2.x"
|
93
|
+
[sprockets-helpers]: https://github.com/petebrowne/sprockets-helpers "Asset path helpers for Sprockets 2.x applications"
|
94
|
+
[uglifier]: https://github.com/lautis/uglifier "Ruby wrapper for UglifyJS JavaScript compressor"
|
95
|
+
[nanoc-gzip-filter]: https://github.com/yannlugrin/nanoc-sprockets-filter "A nanoc filter to gzip content"
|
96
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'nanoc'
|
2
|
+
|
3
|
+
module Nanoc
|
4
|
+
module Filters
|
5
|
+
class Sprockets < Nanoc::Filter
|
6
|
+
VERSION = '0.0.1'
|
7
|
+
|
8
|
+
type :text
|
9
|
+
|
10
|
+
def self.environment
|
11
|
+
nanoc_stderr = $stderr
|
12
|
+
$stderr = STDERR
|
13
|
+
|
14
|
+
environment = ::Sprockets::Environment.new(File.expand_path('.')) do |env|
|
15
|
+
assets = ['javascripts', 'stylesheets', 'images', 'fonts']
|
16
|
+
paths = ['content/assets/', 'lib/assets/', 'assets/', 'vendor/assets/' ].map{|p| assets.map{|f| "#{p}#{f}" } }.flatten
|
17
|
+
|
18
|
+
paths.each{ |path| env.append_path path }
|
19
|
+
end
|
20
|
+
|
21
|
+
$stderr = nanoc_stderr
|
22
|
+
|
23
|
+
environment
|
24
|
+
end
|
25
|
+
|
26
|
+
def environment
|
27
|
+
@environment ||= self.class.environment
|
28
|
+
end
|
29
|
+
|
30
|
+
def run(content, params = {})
|
31
|
+
filename = File.basename(@item[:filename])
|
32
|
+
|
33
|
+
environment.css_compressor = params[:css_compressor]
|
34
|
+
environment.js_compressor = params[:js_compressor]
|
35
|
+
|
36
|
+
if asset = environment[filename]
|
37
|
+
asset.to_s
|
38
|
+
else
|
39
|
+
raise "error locating #{filename} / #{@item[:filename]}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
begin
|
2
|
+
require 'sprockets-helpers'
|
3
|
+
rescue LoadError => e
|
4
|
+
$stderr.puts e
|
5
|
+
$stderr.puts "If you are using a Gemfile, make sure that the Gemfile contains sprockets-helpers ('gem \"sprockets-helpers\"')."
|
6
|
+
exit 1
|
7
|
+
end
|
8
|
+
|
9
|
+
module Nanoc
|
10
|
+
module Helpers
|
11
|
+
module Sprockets
|
12
|
+
module ModuleMethods
|
13
|
+
|
14
|
+
def asset_path(item_or_filename, options = {})
|
15
|
+
if item_or_filename.is_a?(Nanoc::Item)
|
16
|
+
filename = item_or_filename
|
17
|
+
else
|
18
|
+
filename = item_or_filename
|
19
|
+
end
|
20
|
+
filename = File.basename(filename).gsub(/^(\w+\.\w+).*/, '\1')
|
21
|
+
|
22
|
+
if rep_name = options.delete(:rep)
|
23
|
+
rep_prefix = rep_name.to_s + '_'
|
24
|
+
else
|
25
|
+
rep_prefix = ''
|
26
|
+
end
|
27
|
+
|
28
|
+
super(filename, options).gsub(/([^\/]+)$/, "#{rep_prefix}\\1")
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.included(base)
|
34
|
+
base.send :include, ::Sprockets::Helpers
|
35
|
+
base.send :include, ModuleMethods
|
36
|
+
end
|
37
|
+
|
38
|
+
def method_missing(method, *args)
|
39
|
+
if ::Sprockets::Helpers.respond_to?(method)
|
40
|
+
if block_given?
|
41
|
+
::Sprockets::Helpers.send(method, *args) do |*block_args|
|
42
|
+
yield *block_args
|
43
|
+
end
|
44
|
+
else
|
45
|
+
::Sprockets::Helpers.send(method, *args)
|
46
|
+
end
|
47
|
+
else
|
48
|
+
super
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'nanoc'
|
2
|
+
require 'sprockets'
|
3
|
+
|
4
|
+
module Nanoc
|
5
|
+
module Filters
|
6
|
+
autoload 'Sprockets', 'nanoc/filters/sprockets'
|
7
|
+
|
8
|
+
Nanoc::Filter.register '::Nanoc::Filters::Sprockets', :sprockets
|
9
|
+
end
|
10
|
+
|
11
|
+
module Helpers
|
12
|
+
autoload 'Sprockets', 'nanoc/helpers/sprockets'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/nanoc/filters/sprockets', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ['Yann Lugrin']
|
6
|
+
gem.email = ['yann.lugrin@sans-savoir.net']
|
7
|
+
gem.description = %q{A nanoc filter to use Sprockets, a Ruby library for compiling and serving web assets.}
|
8
|
+
gem.summary = %q{A nanoc filter to use Sprockets, a Ruby library for compiling and serving web assets.}
|
9
|
+
gem.homepage = 'https://github.com/yannlugrin/nanoc-sprockets-filter'
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = 'nanoc-sprockets-filter'
|
15
|
+
gem.require_paths = ['lib']
|
16
|
+
gem.version = Nanoc::Filters::Sprockets::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'nanoc', '>= 3.4.0'
|
19
|
+
gem.add_dependency 'sprockets', '>= 2.8.0'
|
20
|
+
|
21
|
+
gem.add_development_dependency 'rake'
|
22
|
+
gem.add_development_dependency 'sprockets-helpers'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nanoc-sprockets-filter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Yann Lugrin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nanoc
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.4.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.4.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: sprockets
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.8.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.8.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: sprockets-helpers
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: A nanoc filter to use Sprockets, a Ruby library for compiling and serving
|
79
|
+
web assets.
|
80
|
+
email:
|
81
|
+
- yann.lugrin@sans-savoir.net
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- lib/nanoc-sprockets-filter.rb
|
92
|
+
- lib/nanoc/filters/sprockets.rb
|
93
|
+
- lib/nanoc/helpers/sprockets.rb
|
94
|
+
- nanoc-sprockets-filter.gemspec
|
95
|
+
homepage: https://github.com/yannlugrin/nanoc-sprockets-filter
|
96
|
+
licenses: []
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
hash: -3970027099751348058
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
hash: -3970027099751348058
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 1.8.24
|
122
|
+
signing_key:
|
123
|
+
specification_version: 3
|
124
|
+
summary: A nanoc filter to use Sprockets, a Ruby library for compiling and serving
|
125
|
+
web assets.
|
126
|
+
test_files: []
|