nanoc-sprockets3 1.0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +5 -0
- data/LICENSE +22 -0
- data/README.md +142 -0
- data/Rakefile +1 -0
- data/lib/nanoc/sprockets/filter.rb +42 -0
- data/lib/nanoc/sprockets/helper.rb +61 -0
- data/lib/nanoc/sprockets/version.rb +5 -0
- data/lib/nanoc/sprockets.rb +10 -0
- data/lib/nanoc-sprockets.rb +3 -0
- data/nanoc-sprockets.gemspec +30 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 52611d2cfa03fe313781712dca2de841e01ec055
|
4
|
+
data.tar.gz: cd41d0f48ce71ca8f7efd4dcbe4b175a1780843f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 77775cc7d0fc9129c2d353febd6dbbc3c764db8bcfecaeb1d926869d5a913f759eab8830757932bf917fa9a3669072f4cb51f0a17c522d41352a5be6819a0940
|
7
|
+
data.tar.gz: 15b1e2e5f8fe870792731e199a5f2e2287ad348db9aa18c17c788ae1aead1074771415e7bbaffe097e73c0a56e86025ae0d1bf3a43f1fef7ad4d5a14cbf2391c
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Remi Barraquand
|
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,142 @@
|
|
1
|
+
# Nanoc::Sprockets3
|
2
|
+
|
3
|
+
A nanoc extension to use [Sprockets 3.x][sprockets], a Ruby library for compiling and serving web assets.
|
4
|
+
|
5
|
+
You are using [nanoc-sprockets-filter][nanoc-sprockets-filter] or [nanoc-sprockets-datasource][nanoc-sprockets] and
|
6
|
+
you would like to use Sprockets 3.x to take advantages of the news features then [nanoc-sprockets3] is
|
7
|
+
what you are looking for !
|
8
|
+
|
9
|
+
**Note:** *Unlike [nanoc-sprockets-filter] or [nanoc-sprockets] that lack a support
|
10
|
+
for dependency tracking, which is annoying when working with partials and/or livereload, [nanoc-sprockets3] is built
|
11
|
+
on top of [Sprockets 3.x][sprockets] and integrates seamlessly with Nanoc3/nanoc4 and livereload.
|
12
|
+
With [nanoc-sprockets3] no need to clear the cache or purge the output to regenerate your assets whenever partials
|
13
|
+
or dependencies change !*
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
gem 'nanoc-sprockets3'
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install nanoc-sprockets3
|
28
|
+
|
29
|
+
## Configuration
|
30
|
+
|
31
|
+
[nanoc-sprockets3][nanoc-sprockets3] does not require any mandatory configuration, however you may want to configure it
|
32
|
+
for your needs. Currently you can configure [nanoc-sprockets3][nanoc-sprockets3] with two parameters:
|
33
|
+
- *prefix* which is the prefix to give to all assets
|
34
|
+
- *environment* which is the Sprockets environment to use
|
35
|
+
|
36
|
+
The default environment is configured with the following paths
|
37
|
+
- content/assets/
|
38
|
+
- vendor/assets/
|
39
|
+
- static/assets/
|
40
|
+
|
41
|
+
concatenated with the following sub-paths
|
42
|
+
- stylesheets
|
43
|
+
- stylesheets/pages
|
44
|
+
- stylesheets/vendor
|
45
|
+
- javascripts
|
46
|
+
- javascripts/pages
|
47
|
+
- javascripts/vendor
|
48
|
+
- fonts
|
49
|
+
|
50
|
+
To load the default [nanoc-sprockets] configuration do as follow:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
include Nanoc::Sprockets::Helper
|
54
|
+
|
55
|
+
```
|
56
|
+
|
57
|
+
To fully customize the [nanoc-sprockets] configuration do as follow:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
include Nanoc::Sprockets::Helper
|
61
|
+
|
62
|
+
Nanoc::Sprockets::Helper.configure do |config|
|
63
|
+
config.environment = ::Sprockets::Environment.new(File.expand_path('.')) do |env|
|
64
|
+
env.append_path 'app/assets/javascripts'
|
65
|
+
env.append_path 'lib/assets/javascripts'
|
66
|
+
env.append_path 'vendor/assets/jquery'
|
67
|
+
end
|
68
|
+
config.prefix = '/assets'
|
69
|
+
end
|
70
|
+
```
|
71
|
+
|
72
|
+
**Note:** you can find more advanced configuration on the [sprockets website][sprockets].
|
73
|
+
|
74
|
+
## Usage
|
75
|
+
|
76
|
+
We recommend the use of [uglifier][uglifier] gem to minify javascripts.
|
77
|
+
You may use any other compressor supported by Sprockets.
|
78
|
+
|
79
|
+
Add compile rule for stylesheets and javascripts, `css_compressor`and `js_compressor` is optional
|
80
|
+
and value can be replaced by any compressor supported by Sprockets.
|
81
|
+
Add route rule for all assets and use `Nanoc::Sprockets::Helper.asset_path(item)` to generate file path.
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
compile %r{/assets/(stylesheets|javascripts)/.+/} do
|
85
|
+
filter :sprockets, {
|
86
|
+
:css_compressor => :scss,
|
87
|
+
:js_compressor => :uglifier
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
route '/assets/*/' do
|
92
|
+
Nanoc::Sprockets::Helper.asset_path(item)
|
93
|
+
end
|
94
|
+
```
|
95
|
+
|
96
|
+
You can use [nanoc-gzip-filter][nanoc-gzip-filter] to create a
|
97
|
+
gzipped version of stylesheets and javascripts files.
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
compile %r{/assets/(stylesheets|javascripts)/.+/} do
|
101
|
+
filter :sprockets, {
|
102
|
+
:css_compressor => :scss,
|
103
|
+
:js_compressor => :uglifier
|
104
|
+
}
|
105
|
+
snapshot :text
|
106
|
+
filter :gzip
|
107
|
+
end
|
108
|
+
|
109
|
+
route '/assets/*/', :snapshot => :text do
|
110
|
+
Nanoc::Sprockets::Helper.asset_path(item)
|
111
|
+
end
|
112
|
+
|
113
|
+
route '/assets/*/' do
|
114
|
+
Nanoc::Sprockets::Helper.asset_path(item) + '.gz'
|
115
|
+
end
|
116
|
+
```
|
117
|
+
|
118
|
+
**Note:** Don't forget to require 'nanoc-sprockets' (e.g in `lib/default.rb`)
|
119
|
+
|
120
|
+
|
121
|
+
## Contributing
|
122
|
+
|
123
|
+
1. Fork it ( http://github.com/<my-github-username>/nanoc-sprockets/fork )
|
124
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
125
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
126
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
127
|
+
5. Create new Pull Request
|
128
|
+
|
129
|
+
## Acknowledgement
|
130
|
+
|
131
|
+
I wrote this plugin to bring the support of Sprockets 3.x to nanoc and take benefit of the dependencies tracking system
|
132
|
+
introduced in Sprockets 3.x.
|
133
|
+
|
134
|
+
This plugin is inspired by [nanoc-sprockets-filter][nanoc-sprockets-filter] which support Sprockets 2.x but lacks a support
|
135
|
+
for dependency tracking which makes it annoying to use with livereload and partials.
|
136
|
+
|
137
|
+
[nanoc-sprockets3]: https://github.com/barraq/nanoc-sprockets "Sprockets 3.x support for nanoc"
|
138
|
+
[sprockets]: https://github.com/sstephenson/sprockets "Rack-based asset packaging"
|
139
|
+
[nanoc-sprockets-filter]: https://github.com/yannlugrin/nanoc-sprockets-filter "A nanoc filter to use Sprocket 2.x"
|
140
|
+
[nanoc-sprockets]: https://github.com/stormz/nanoc-sprockets "Use sprockets 2.x as a datasource for nanoc"
|
141
|
+
[nanoc-gzip-filter]: https://github.com/yannlugrin/nanoc-gzip-filter "A Nanoc filter to gzip content"
|
142
|
+
[uglifier]: https://github.com/lautis/uglifier "Ruby wrapper for UglifyJS JavaScript compressor"
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Nanoc::Sprockets
|
4
|
+
|
5
|
+
class Filter < Nanoc::Filter
|
6
|
+
|
7
|
+
identifier :sprockets
|
8
|
+
type :text
|
9
|
+
|
10
|
+
def environment
|
11
|
+
@environment ||= Nanoc::Sprockets::Helper.environment
|
12
|
+
end
|
13
|
+
|
14
|
+
def run(content, params = {})
|
15
|
+
filename = File.basename(@item[:filename])
|
16
|
+
|
17
|
+
environment.css_compressor = params[:css_compressor]
|
18
|
+
environment.js_compressor = params[:js_compressor]
|
19
|
+
|
20
|
+
if asset = environment[filename]
|
21
|
+
update_dependencies_for_current_item(asset.metadata[:dependency_paths])
|
22
|
+
asset.to_s
|
23
|
+
else
|
24
|
+
raise "error locating #{filename} / #{@item[:filename]}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def update_dependencies_for_current_item(dependencies)
|
29
|
+
dependencies.each do |dep|
|
30
|
+
item = imported_filename_to_item(dep)
|
31
|
+
depend_on([item]) unless item.nil? or item.identifier == @item.identifier
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def imported_filename_to_item(filename)
|
36
|
+
@items.find do |i|
|
37
|
+
i.raw_filename &&
|
38
|
+
Pathname.new(i.raw_filename).realpath == Pathname.new(filename).realpath
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'sprockets'
|
4
|
+
|
5
|
+
module Nanoc::Sprockets
|
6
|
+
|
7
|
+
module Helper
|
8
|
+
|
9
|
+
DEFAULT_ASSETS_DIRS = [
|
10
|
+
'stylesheets', 'stylesheets/pages', 'stylesheets/vendor',
|
11
|
+
'javascripts', 'javascripts/pages', 'javascripts/vendor',
|
12
|
+
'fonts'
|
13
|
+
]
|
14
|
+
|
15
|
+
DEFAULT_ASSETS_PATHS = [
|
16
|
+
'content/assets/', 'vendor/assets/', 'static/assets/'
|
17
|
+
]
|
18
|
+
|
19
|
+
class << self
|
20
|
+
# Set the Sprockets environment to search for assets.
|
21
|
+
# This defaults to the context's #environment method.
|
22
|
+
def environment
|
23
|
+
@environment ||= ::Sprockets::Environment.new(File.expand_path('.')) do |env|
|
24
|
+
paths = DEFAULT_ASSETS_DIRS + DEFAULT_ASSETS_PATHS.map{|p| DEFAULT_ASSETS_DIRS.map{|f| "#{p}#{f}"}}.flatten
|
25
|
+
paths.each{ |path| env.append_path path }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
attr_writer :environment
|
29
|
+
|
30
|
+
# The base URL the Sprocket environment is mapped to.
|
31
|
+
# This defaults to '/assets'.
|
32
|
+
def prefix
|
33
|
+
@prefix ||= '/assets'
|
34
|
+
end
|
35
|
+
attr_writer :prefix
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
# Convience method for configuring Nanoc::Sprockets::Helpers.
|
40
|
+
def configure
|
41
|
+
yield self
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns the path to an item or a filename either in the Sprockets environment.
|
45
|
+
def asset_path(item_or_filename, options = {})
|
46
|
+
if item_or_filename.is_a?(::Nanoc::Item)
|
47
|
+
filename = item_or_filename[:filename]
|
48
|
+
else
|
49
|
+
filename = item_or_filename
|
50
|
+
end
|
51
|
+
filename = File.basename(filename).gsub(/^(\w+\.\w+).*/, '\1')
|
52
|
+
|
53
|
+
if asset = Helper.environment[filename]
|
54
|
+
File.join(Helper.prefix, asset.logical_path)
|
55
|
+
else
|
56
|
+
raise "error locating #{filename}."
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'nanoc/sprockets/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'nanoc-sprockets3'
|
8
|
+
spec.version = Nanoc::Sprockets::VERSION
|
9
|
+
spec.homepage = 'https://github.com/barraq/nanoc-sprockets'
|
10
|
+
spec.summary = %q{Sprockets 3.x support for nanoc.}
|
11
|
+
spec.description = %q{Provides Sprockets 3.x helper and filter for nanoc.}
|
12
|
+
|
13
|
+
spec.authors = ["Remi Barraquand"]
|
14
|
+
spec.email = ["dev@remibarraquand.com"]
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.required_ruby_version = '>= 1.9.3'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0")
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.rdoc_options = [ '--main', 'README.md' ]
|
25
|
+
spec.extra_rdoc_files = [ 'LICENSE', 'README.md' ]
|
26
|
+
|
27
|
+
spec.add_runtime_dependency 'sprockets', '~> 3.0.0.beta'
|
28
|
+
|
29
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nanoc-sprockets3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Remi Barraquand
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sprockets
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0.beta
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0.beta
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
description: Provides Sprockets 3.x helper and filter for nanoc.
|
42
|
+
email:
|
43
|
+
- dev@remibarraquand.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files:
|
47
|
+
- LICENSE
|
48
|
+
- README.md
|
49
|
+
files:
|
50
|
+
- ".gitignore"
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- lib/nanoc-sprockets.rb
|
56
|
+
- lib/nanoc/sprockets.rb
|
57
|
+
- lib/nanoc/sprockets/filter.rb
|
58
|
+
- lib/nanoc/sprockets/helper.rb
|
59
|
+
- lib/nanoc/sprockets/version.rb
|
60
|
+
- nanoc-sprockets.gemspec
|
61
|
+
homepage: https://github.com/barraq/nanoc-sprockets
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options:
|
67
|
+
- "--main"
|
68
|
+
- README.md
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.9.3
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.4.5
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Sprockets 3.x support for nanoc.
|
87
|
+
test_files: []
|