nutils 0.11.3 → 1.1.0
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/README.md +9 -8
- data/lib/nutils/base/errors.rb +2 -2
- data/lib/nutils/data_sources/filesystem_customizable.rb +5 -5
- data/lib/nutils/data_sources.rb +2 -2
- data/lib/nutils/filters/beautify.rb +2 -2
- data/lib/nutils/filters/crop.rb +2 -2
- data/lib/nutils/filters/sprockets.rb +10 -40
- data/lib/nutils/filters/svg2png.rb +4 -3
- data/lib/nutils/filters/yuicompressor.rb +6 -6
- data/lib/nutils/filters.rb +6 -8
- data/lib/nutils/helpers/rules.rb +2 -4
- data/lib/nutils.rb +2 -3
- metadata +8 -9
- data/lib/nutils/filters/sass.rb +0 -82
data/README.md
CHANGED
@@ -1,24 +1,25 @@
|
|
1
1
|
# Nutils Readme
|
2
2
|
|
3
|
-
A set of utilities for nanoc 3.
|
3
|
+
A set of utilities for nanoc 3. Tested in Mac OS X 10.6, Ruby 1.8.7, 1.92 and nanoc 3.3.
|
4
4
|
|
5
5
|
## Filters
|
6
6
|
|
7
|
-
* **beautify** Retabs HTML code.
|
8
|
-
* **crop** Extracts the specified rectangle from the image
|
9
|
-
* **sprockets** Runs the content through [Sprockets](http://getsprockets.org).
|
10
|
-
* **svg_to_png** Converts an SVG to PNG.
|
11
|
-
* **yuicompressor** Compress the content with [YUI Compressor](http://developer.yahoo.com/yui/compressor/).
|
12
|
-
* **
|
7
|
+
* **beautify** Retabs HTML code. htmlbeautifier 0.0.6.
|
8
|
+
* **crop** Extracts the specified rectangle from the image. RMagick 2.13.1.
|
9
|
+
* **sprockets** Runs the content through [Sprockets](http://getsprockets.org). Sprockets 2.
|
10
|
+
* **svg_to_png** Converts an SVG to PNG. Batik 1.7.
|
11
|
+
* **yuicompressor** Compress the content with [YUI Compressor](http://developer.yahoo.com/yui/compressor/). yui-compressor 0.9.1.
|
12
|
+
* **sass** Importer `Nutils::SassImporters::NanocItem` which deals with `@import /nanoc/identifier/` instead of real filenames.
|
13
13
|
|
14
14
|
## Data Sources
|
15
15
|
* **filesystem_customizable** Allows an array for source directories and for layout directories.
|
16
16
|
|
17
17
|
## Helpers
|
18
|
-
* **load_rules** Allows to use multiple files with Nanoc rules.
|
18
|
+
* **load_rules** Allows to use multiple files with Nanoc rules.
|
19
19
|
|
20
20
|
## Collaborators
|
21
21
|
|
22
|
+
* [Choan](https://github.com/choan)
|
22
23
|
* [Ximus](https://github.com/ximus)
|
23
24
|
|
24
25
|
## Contact
|
data/lib/nutils/base/errors.rb
CHANGED
@@ -3,7 +3,7 @@ module Nutils
|
|
3
3
|
|
4
4
|
# Error that is raised when no partial rules file can be found in any
|
5
5
|
# directory provided.
|
6
|
-
class NoRulesFileFound < ::
|
6
|
+
class NoRulesFileFound < ::Nanoc::Errors::NoRulesFileFound
|
7
7
|
|
8
8
|
# @param [String] filename The file name not found.
|
9
9
|
def initialize(filename)
|
@@ -13,4 +13,4 @@ module Nutils
|
|
13
13
|
end
|
14
14
|
|
15
15
|
end
|
16
|
-
end
|
16
|
+
end
|
@@ -16,8 +16,8 @@ module Nutils
|
|
16
16
|
# source_dir: ["src"]
|
17
17
|
# layout_dir: ["layouts", "other_layouts"]
|
18
18
|
#
|
19
|
-
# @see
|
20
|
-
class FilesystemCustomizable <
|
19
|
+
# @see Nanoc::DataSources::FilesystemUnified
|
20
|
+
class FilesystemCustomizable < Nanoc::DataSources::FilesystemUnified
|
21
21
|
identifier :filesystem_customizable
|
22
22
|
|
23
23
|
def setup
|
@@ -26,12 +26,12 @@ module Nutils
|
|
26
26
|
end
|
27
27
|
def items
|
28
28
|
@sources.map do |dir|
|
29
|
-
load_objects(dir, 'item',
|
29
|
+
load_objects(dir, 'item', Nanoc::Item)
|
30
30
|
end.flatten
|
31
31
|
end
|
32
32
|
def layouts
|
33
33
|
@layouts.map do |dir|
|
34
|
-
load_objects(dir, 'layout',
|
34
|
+
load_objects(dir, 'layout', Nanoc::Layout)
|
35
35
|
end.flatten
|
36
36
|
end
|
37
37
|
|
@@ -48,4 +48,4 @@ module Nutils
|
|
48
48
|
|
49
49
|
end
|
50
50
|
end
|
51
|
-
end
|
51
|
+
end
|
data/lib/nutils/data_sources.rb
CHANGED
@@ -2,6 +2,6 @@ module Nutils
|
|
2
2
|
module DataSources
|
3
3
|
autoload "FilesystemCustomizable", "nutils/data_sources/filesystem_customizable"
|
4
4
|
|
5
|
-
::
|
5
|
+
::Nanoc::DataSource.register "::Nutils::DataSources::FilesystemCustomizable", :filesystem_customizable
|
6
6
|
end
|
7
|
-
end
|
7
|
+
end
|
@@ -9,7 +9,7 @@ module Nutils
|
|
9
9
|
# @note Requires htmlbeautifer
|
10
10
|
#
|
11
11
|
# @todo Pass parameters to the HtmlBeautifer engine.
|
12
|
-
class Beautify <
|
12
|
+
class Beautify < Nanoc::Filter
|
13
13
|
|
14
14
|
identifier :beautify
|
15
15
|
type :text
|
@@ -30,4 +30,4 @@ module Nutils
|
|
30
30
|
end
|
31
31
|
|
32
32
|
end
|
33
|
-
end
|
33
|
+
end
|
data/lib/nutils/filters/crop.rb
CHANGED
@@ -2,11 +2,10 @@ module Nutils
|
|
2
2
|
module Filters
|
3
3
|
# @author Arnau Siches
|
4
4
|
#
|
5
|
-
# @version
|
5
|
+
# @version 3.0.0
|
6
6
|
#
|
7
7
|
# @note Requires «sprockets»
|
8
|
-
class SprocketWheel <
|
9
|
-
require 'pathname'
|
8
|
+
class SprocketWheel < Nanoc::Filter
|
10
9
|
identifier :sprockets
|
11
10
|
type :text
|
12
11
|
# Concatenate the Javascript, CoffeeScript or Sass content through [Sprockets](http://getsprockets.org).
|
@@ -17,13 +16,9 @@ module Nutils
|
|
17
16
|
# @return [String] The filtered content.
|
18
17
|
def run(content, params={})
|
19
18
|
require 'sprockets'
|
20
|
-
Gem.loaded_specs['sprockets'].version < Gem::Version.create('2.0')
|
21
|
-
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def default(content, params)
|
26
|
-
filename = ::Pathname.new(@item[:content_filename])
|
19
|
+
raise "Sprockets should be 2.0.0 or higher" if Gem.loaded_specs['sprockets'].version < Gem::Version.create('2.0')
|
20
|
+
|
21
|
+
filename = Pathname.new(@item[:content_filename])
|
27
22
|
|
28
23
|
# Create a temp file with the content received to give the desired
|
29
24
|
# content to Sprockets on the same context.
|
@@ -31,9 +26,9 @@ module Nutils
|
|
31
26
|
tmp_filename.open('w') { |io| io.puts content }
|
32
27
|
|
33
28
|
load_path = params[:load_path] || []
|
34
|
-
load_path <<
|
29
|
+
load_path << tmp_filename.dirname.realpath
|
35
30
|
|
36
|
-
env = ::Sprockets::Environment.new(
|
31
|
+
env = ::Sprockets::Environment.new(tmp_filename.dirname.realpath)
|
37
32
|
|
38
33
|
# Assign load paths to Sprockets
|
39
34
|
load_path.each do |path|
|
@@ -45,16 +40,16 @@ module Nutils
|
|
45
40
|
|
46
41
|
# Select just the possible items that can be dependencies
|
47
42
|
possible_items = @items.reject { |i| i[:content_filename].nil? }.select do |i|
|
48
|
-
load_path.find { |p|
|
43
|
+
load_path.find { |p| Pathname.new(p).realpath.to_s == Pathname.new(i[:content_filename]).dirname.realpath.to_s }
|
49
44
|
end
|
50
45
|
|
51
46
|
# Get Nanoc::Item equivalent for each dependence managed by Sprockets
|
52
47
|
dependencies = main_asset.dependencies.inject([]) do |dep, asset|
|
53
|
-
item = possible_items.find { |i| asset.pathname ==
|
48
|
+
item = possible_items.find { |i| asset.pathname == Pathname.new(i[:content_filename]).realpath }
|
54
49
|
dep << item unless item.nil?
|
55
50
|
dep
|
56
51
|
end
|
57
|
-
#
|
52
|
+
# Register Nanoc dependencies
|
58
53
|
depend_on(dependencies) unless dependencies.nil?
|
59
54
|
|
60
55
|
# Output compiled asset
|
@@ -62,31 +57,6 @@ module Nutils
|
|
62
57
|
ensure
|
63
58
|
tmp_filename.delete if tmp_filename.exist?
|
64
59
|
end
|
65
|
-
|
66
|
-
def backwards(content, params)
|
67
|
-
puts "You are using Sprockets 1.0.0. It's strongly recommended you upgrade to Sprockets >= 2.0.0"
|
68
|
-
puts "Nutils 1.0.0 will *not* support Sprockets 1.0.0"
|
69
|
-
|
70
|
-
filename = ::Pathname.new(@item[:content_filename])
|
71
|
-
|
72
|
-
# Create a temp file with the content received to give the desired
|
73
|
-
# content to Sprockets on the same context.
|
74
|
-
tmp_filename = filename.dirname + ('tmp_' + filename.basename.to_s)
|
75
|
-
tmp_filename.open('w') { |io| io.puts content }
|
76
|
-
|
77
|
-
load_path = params[:load_path] || []
|
78
|
-
load_path << tmp_filename.dirname.realpath.to_s
|
79
|
-
params.merge!({
|
80
|
-
:load_path => load_path,
|
81
|
-
:source_files => [tmp_filename.realpath.to_s]
|
82
|
-
})
|
83
|
-
|
84
|
-
secretary = ::Sprockets::Secretary.new(params)
|
85
|
-
secretary.install_assets if params[:asset_root]
|
86
|
-
secretary.concatenation.to_s
|
87
|
-
ensure
|
88
|
-
tmp_filename.delete if tmp_filename.exist?
|
89
|
-
end
|
90
60
|
end
|
91
61
|
end
|
92
62
|
end
|
@@ -7,7 +7,7 @@ module Nutils
|
|
7
7
|
# @version 0.3.1
|
8
8
|
#
|
9
9
|
# @note Requires «rjb» and «batik»
|
10
|
-
class SvgToPng <
|
10
|
+
class SvgToPng < Nanoc::Filter
|
11
11
|
require 'rjb'
|
12
12
|
require 'tempfile'
|
13
13
|
require 'fileutils'
|
@@ -74,7 +74,8 @@ module Nutils
|
|
74
74
|
|
75
75
|
t.addTranscodingHint(@pngTranscoder.KEY_WIDTH, @float.new(opts[:width])) if opts[:width]
|
76
76
|
t.addTranscodingHint(@pngTranscoder.KEY_HEIGHT, @float.new(opts[:height])) if opts[:height]
|
77
|
-
t.addTranscodingHint(@pngTranscoder.KEY_PIXEL_TO_MM, @float.new(254 / opts[:dpi])) if opts[:dpi]
|
77
|
+
#t.addTranscodingHint(@pngTranscoder.KEY_PIXEL_TO_MM, @float.new(254 / opts[:dpi])) if opts[:dpi]
|
78
|
+
t.addTranscodingHint(@pngTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER, @float.new(254 / opts[:dpi])) if opts[:dpi]
|
78
79
|
t.addTranscodingHint(@pngTranscoder.KEY_BACKGROUND_COLOR, @color.new(hex2int(opts[:background_color]))) if opts[:background_color] and opts[:background_color] != 'transparent'
|
79
80
|
# t.addTranscodingHint(@pngTranscoder.KEY_BACKGROUND_COLOR, @color.decode('#FC0'))
|
80
81
|
|
@@ -112,4 +113,4 @@ module Nutils
|
|
112
113
|
|
113
114
|
end
|
114
115
|
end
|
115
|
-
end
|
116
|
+
end
|
@@ -3,10 +3,10 @@ module Nutils
|
|
3
3
|
|
4
4
|
# @author Arnau Siches
|
5
5
|
#
|
6
|
-
# @version 1.2.
|
6
|
+
# @version 1.2.0
|
7
7
|
#
|
8
8
|
# @note Requires «yui-compressor»
|
9
|
-
class YuiCompressor <
|
9
|
+
class YuiCompressor < Nanoc::Filter
|
10
10
|
|
11
11
|
identifier :yuicompressor
|
12
12
|
type :text
|
@@ -24,12 +24,12 @@ module Nutils
|
|
24
24
|
require "yui/compressor"
|
25
25
|
if (params[:type] == :css)
|
26
26
|
compressor = ::YUI::CssCompressor.new
|
27
|
-
|
28
|
-
puts "Remember to add a params[:type] to your filter declaration to ensure straight compatibility with YUICompressor" unless params.has_key?(:type)
|
29
|
-
# elsif (params[:type] == :js)
|
27
|
+
elsif (params[:type] == :js)
|
30
28
|
# It fallbacks to `:type => :js` because backwards compatibility w/
|
31
29
|
# prior versions of the filter.
|
32
30
|
compressor = ::YUI::JavaScriptCompressor.new
|
31
|
+
else
|
32
|
+
raise "You should define a params[:type] either :js or :css"
|
33
33
|
end
|
34
34
|
|
35
35
|
compressor.compress(content)
|
@@ -37,4 +37,4 @@ module Nutils
|
|
37
37
|
|
38
38
|
end
|
39
39
|
end
|
40
|
-
end
|
40
|
+
end
|
data/lib/nutils/filters.rb
CHANGED
@@ -5,13 +5,11 @@ module Nutils
|
|
5
5
|
autoload 'SprocketWheel', 'nutils/filters/sprockets'
|
6
6
|
autoload 'SvgToPng', 'nutils/filters/svg2png'
|
7
7
|
autoload 'YuiCompressor', 'nutils/filters/yuicompressor'
|
8
|
-
autoload 'Sass', 'nutils/filters/sass'
|
9
8
|
|
10
|
-
::
|
11
|
-
::
|
12
|
-
::
|
13
|
-
::
|
14
|
-
::
|
15
|
-
::Nanoc3::Filter.register '::Nutils::Filters::Sass', :zass
|
9
|
+
::Nanoc::Filter.register '::Nutils::Filters::Beautify', :beautify
|
10
|
+
::Nanoc::Filter.register '::Nutils::Filters::Crop', :crop
|
11
|
+
::Nanoc::Filter.register '::Nutils::Filters::SprocketWheel', :sprockets
|
12
|
+
::Nanoc::Filter.register '::Nutils::Filters::SvgToPng', :svg_to_png
|
13
|
+
::Nanoc::Filter.register '::Nutils::Filters::YuiCompressor', :yuicompressor
|
16
14
|
end
|
17
|
-
end
|
15
|
+
end
|
data/lib/nutils/helpers/rules.rb
CHANGED
@@ -25,15 +25,13 @@ module Nutils
|
|
25
25
|
#
|
26
26
|
# @return [Proc]
|
27
27
|
def load_rules(filepath)
|
28
|
-
raise "You should upgrade to nanoc 3.
|
28
|
+
raise "You should upgrade to nanoc 3.3 to run the load_rules helper properly" if Gem.loaded_specs["nanoc"].version == Gem::Version.create('3.3')
|
29
29
|
|
30
|
-
rules_dir = if Gem.loaded_specs["
|
30
|
+
rules_dir = if Gem.loaded_specs["nanoc"].version >= Gem::Version.create('3.1') and Gem.loaded_specs["nanoc"].version < Gem::Version.create('3.3')
|
31
31
|
(@site.config[:rules_dir] || ['.'])
|
32
32
|
else
|
33
33
|
@config[:rules_dir] || ['.']
|
34
34
|
end
|
35
|
-
|
36
|
-
|
37
35
|
|
38
36
|
path = rules_dir.map do |dir|
|
39
37
|
Dir[File.join(dir, filepath)].each { |filename| filename }
|
data/lib/nutils.rb
CHANGED
metadata
CHANGED
@@ -3,10 +3,10 @@ name: nutils
|
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
|
+
- 1
|
7
|
+
- 1
|
6
8
|
- 0
|
7
|
-
|
8
|
-
- 3
|
9
|
-
version: 0.11.3
|
9
|
+
version: 1.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Arnau Siches
|
@@ -14,11 +14,11 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2012-
|
17
|
+
date: 2012-02-18 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
21
|
+
name: nanoc
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
@@ -26,12 +26,12 @@ dependencies:
|
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
segments:
|
28
28
|
- 3
|
29
|
+
- 3
|
29
30
|
- 1
|
30
|
-
|
31
|
-
version: 3.1.2
|
31
|
+
version: 3.3.1
|
32
32
|
type: :runtime
|
33
33
|
version_requirements: *id001
|
34
|
-
description: Nutils is a set of utilities like filters, data_sources and helpers for
|
34
|
+
description: Nutils is a set of utilities like filters, data_sources and helpers for Nanoc.
|
35
35
|
email: arnau.siches@gmail.com
|
36
36
|
executables: []
|
37
37
|
|
@@ -47,7 +47,6 @@ files:
|
|
47
47
|
- lib/nutils/data_sources.rb
|
48
48
|
- lib/nutils/filters/beautify.rb
|
49
49
|
- lib/nutils/filters/crop.rb
|
50
|
-
- lib/nutils/filters/sass.rb
|
51
50
|
- lib/nutils/filters/sprockets.rb
|
52
51
|
- lib/nutils/filters/svg2png.rb
|
53
52
|
- lib/nutils/filters/yuicompressor.rb
|
data/lib/nutils/filters/sass.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'sass'
|
4
|
-
|
5
|
-
module Nutils
|
6
|
-
module Filters
|
7
|
-
class Sass < Nanoc3::Filters::Sass
|
8
|
-
FILES = []
|
9
|
-
identifier :zass
|
10
|
-
type :text
|
11
|
-
|
12
|
-
# Runs the content through [Sass](http://sass-lang.com/).
|
13
|
-
# Parameters passed to this filter will be passed on to Sass.
|
14
|
-
#
|
15
|
-
# @param [String] content The content to filter
|
16
|
-
#
|
17
|
-
# @return [String] The filtered content
|
18
|
-
def run(content, params={})
|
19
|
-
|
20
|
-
puts "You should use the Sass filter from nanoc 3.1.9 or later. This Sass filter (:zass) is deprecated."
|
21
|
-
|
22
|
-
# Get options
|
23
|
-
options = params.dup
|
24
|
-
sass_filename = options[:filename] || (@item && @item[:content_filename])
|
25
|
-
options[:filename] ||= sass_filename
|
26
|
-
options[:filesystem_importer] ||= Nutils::Importers::Nanoc
|
27
|
-
|
28
|
-
# Build engine
|
29
|
-
engine = ::Sass::Engine.new(content, options)
|
30
|
-
output = engine.render
|
31
|
-
|
32
|
-
until Nutils::Filters::Sass::FILES.empty?
|
33
|
-
filename = Nutils::Filters::Sass::FILES.pop
|
34
|
-
notify(filename)
|
35
|
-
end
|
36
|
-
|
37
|
-
return output
|
38
|
-
end
|
39
|
-
|
40
|
-
def notify(filename)
|
41
|
-
pathname = Pathname.new(filename)
|
42
|
-
item = @items.find { |i| i[:content_filename] && Pathname.new(i[:content_filename]).realpath == pathname.realpath }
|
43
|
-
|
44
|
-
unless item.nil?
|
45
|
-
# Notify
|
46
|
-
::Nanoc3::NotificationCenter.post(:visit_started, item)
|
47
|
-
::Nanoc3::NotificationCenter.post(:visit_ended, item)
|
48
|
-
|
49
|
-
# Raise unmet dependency error if item is not yet compiled
|
50
|
-
any_uncompiled_rep = item.reps.find { |r| !r.compiled? }
|
51
|
-
raise ::Nanoc3::Errors::UnmetDependency.new(any_uncompiled_rep) if any_uncompiled_rep
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
|
59
|
-
module Importers
|
60
|
-
|
61
|
-
##
|
62
|
-
# Essentially the {Sass::Importers::Filesystem} but registering each import
|
63
|
-
# file path.
|
64
|
-
class Nanoc < ::Sass::Importers::Filesystem
|
65
|
-
|
66
|
-
private
|
67
|
-
|
68
|
-
def _find(dir, name, options)
|
69
|
-
full_filename, syntax = find_real_file(dir, name)
|
70
|
-
return unless full_filename && File.readable?(full_filename)
|
71
|
-
|
72
|
-
Nutils::Filters::Sass::FILES << full_filename
|
73
|
-
|
74
|
-
options[:syntax] = syntax
|
75
|
-
options[:filename] = full_filename
|
76
|
-
options[:importer] = self
|
77
|
-
::Sass::Engine.new(File.read(full_filename), options)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|