nutils 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -1
- data/lib/nutils/filters/sprockets.rb +65 -20
- data/lib/nutils.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -6,7 +6,7 @@ A set of utilities for nanoc 3.
|
|
6
6
|
|
7
7
|
* **beautify** Retabs HTML code. Tested in Mac OS X 10.6, Ruby 1.8.7 and Nanoc 3.1.6, 3.2.1.
|
8
8
|
* **crop** Extracts the specified rectangle from the image.. Tested in Mac OS X 10.6, Ruby 1.8.7 and Nanoc 3.1.6, 3.2.1.
|
9
|
-
* **sprockets** Runs the content through [Sprockets](http://getsprockets.org). Tested in Mac OS X 10.6, Ruby 1.8.7,
|
9
|
+
* **sprockets** Runs the content through [Sprockets](http://getsprockets.org). Tested in Mac OS X 10.6, Ruby 1.8.7, 1.9.2, Nanoc 3.2.2 and Sprockets.
|
10
10
|
* **svg_to_png** Converts an SVG to PNG. Tested in Mac OS X 10.6, Ruby 1.8.7, Nanoc 3.1.6, 3.2.1 and Batik 1.7.
|
11
11
|
* **yuicompressor** Compress the content with [YUI Compressor](http://developer.yahoo.com/yui/compressor/). Tested in Mac OS X 10.6, Ruby 1.8.7, Nanoc 3.1.6, 3.2.1 and yui-compressor 0.9.1.
|
12
12
|
* **zass** Deprecated. You **should** use the **sass** filter from nanoc 3.1.9+
|
@@ -17,5 +17,9 @@ A set of utilities for nanoc 3.
|
|
17
17
|
## Helpers
|
18
18
|
* **load_rules** Allows to use multiple files with Nanoc rules. It works with nanoc 3.1 and 3.2.
|
19
19
|
|
20
|
+
## Collaborators
|
21
|
+
|
22
|
+
* [Ximus](https://github.com/ximus)
|
23
|
+
|
20
24
|
## Contact
|
21
25
|
You can reach me at <arnau.siches@gmail.com>.
|
@@ -1,43 +1,88 @@
|
|
1
1
|
module Nutils
|
2
2
|
module Filters
|
3
|
-
|
4
3
|
# @author Arnau Siches
|
5
4
|
#
|
6
|
-
# @version
|
5
|
+
# @version 2.0.0
|
7
6
|
#
|
8
7
|
# @note Requires «sprockets»
|
9
8
|
class SprocketWheel < Nanoc3::Filter
|
10
|
-
|
11
9
|
identifier :sprockets
|
12
10
|
type :text
|
13
|
-
|
14
|
-
# Concatenate the Javascript content through [Sprockets](http://getsprockets.org).
|
11
|
+
# Concatenate the Javascript, CoffeeScript or Sass content through [Sprockets](http://getsprockets.org).
|
15
12
|
# This method takes no options.
|
16
13
|
#
|
17
14
|
# @param [String] content The content to filter.
|
18
15
|
#
|
16
|
+
# @todo Use the content to build a Sprocket Asset instead of just get the
|
17
|
+
# `@item[:content_filename]`.
|
18
|
+
#
|
19
19
|
# @return [String] The filtered content.
|
20
20
|
def run(content, params={})
|
21
|
-
require
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
21
|
+
require 'sprockets'
|
22
|
+
Gem.loaded_specs['sprockets'].version < Gem::Version.create('2.0') ? backwards(content, params) : default(content, params)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def default(content, params)
|
28
|
+
filename = Pathname.new(@item[:content_filename])
|
29
|
+
|
30
|
+
# Create a temp file with the content received to give the desired
|
31
|
+
# content to Sprockets on the same context.
|
32
|
+
tmp_filename = filename.dirname + ('tmp_' + filename.basename.to_s)
|
33
|
+
tmp_filename.open('w') { |io| io.puts content }
|
34
|
+
|
35
|
+
load_path = params[:load_path] || []
|
36
|
+
load_path << tmp_filename.dirname.realpath
|
37
|
+
|
38
|
+
env = ::Sprockets::Environment.new(tmp_filename.dirname.realpath)
|
39
|
+
|
40
|
+
# Assign load paths to Sprockets
|
41
|
+
load_path.each do |path|
|
42
|
+
env.append_path(File.expand_path(path))
|
43
|
+
end
|
44
|
+
|
45
|
+
# Get the Sprockets BundledAsset object for the content
|
46
|
+
main_asset = env.find_asset(tmp_filename.realpath)
|
47
|
+
|
48
|
+
# Get Nanoc::Item equivalent for each dependence managed by Sprockets
|
49
|
+
dependencies = main_asset.dependencies.inject([]) do |dep, asset|
|
50
|
+
item = @items.find { |i| asset.pathname == Pathname.new(i[:content_filename]).realpath }
|
51
|
+
dep << item unless item.nil?
|
52
|
+
dep
|
53
|
+
end
|
54
|
+
# Register Nanoc dependencies
|
55
|
+
depend_on(dependencies) unless dependencies.nil?
|
56
|
+
|
57
|
+
# Output compiled asset
|
58
|
+
main_asset.to_s
|
59
|
+
ensure
|
60
|
+
tmp_filename.delete if tmp_filename.exist?
|
61
|
+
end
|
62
|
+
|
63
|
+
def backwards(content, params)
|
64
|
+
puts "You are using Sprockets 1.0.0. It's strongly recommended you upgrade to Sprockets >= 2.0.0"
|
65
|
+
puts "Nutils 1.0.0 will *not* support Sprockets 1.0.0"
|
66
|
+
|
67
|
+
filename = Pathname.new(@item[:content_filename])
|
68
|
+
|
69
|
+
# Create a temp file with the content received to give the desired
|
70
|
+
# content to Sprockets on the same context.
|
71
|
+
tmp_filename = filename.dirname + ('tmp_' + filename.basename.to_s)
|
72
|
+
tmp_filename.open('w') { |io| io.puts content }
|
73
|
+
|
74
|
+
load_path = params[:load_path] || []
|
75
|
+
load_path << tmp_filename.dirname.realpath.to_s
|
32
76
|
params.merge!({
|
33
77
|
:load_path => load_path,
|
34
|
-
:source_files => [
|
78
|
+
:source_files => [tmp_filename.realpath.to_s]
|
35
79
|
})
|
36
|
-
|
80
|
+
|
37
81
|
secretary = ::Sprockets::Secretary.new(params)
|
38
82
|
secretary.install_assets if params[:asset_root]
|
39
|
-
secretary.concatenation
|
40
|
-
|
83
|
+
secretary.concatenation.to_s
|
84
|
+
ensure
|
85
|
+
tmp_filename.delete if tmp_filename.exist?
|
41
86
|
end
|
42
87
|
end
|
43
88
|
end
|
data/lib/nutils.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nutils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 51
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 11
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.11.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Arnau Siches
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-09-30 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|