nutils 0.7.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -9,6 +9,7 @@ A set of utilities for Nanoc3.
9
9
  * **sprockets** Runs the content through [Sprockets](http://getsprockets.org)
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 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 and yui-compressor 0.9.1.
12
+ * **zass** Compiles the content using [Sass](http://sass-lang.com/) 3.1. Tested in Mac OS X 10.6.7, Ruby 1.8.7, Nanoc 3.1.6 and sass 3.1.
12
13
 
13
14
  ## Data Sources
14
15
  * **filesystem_customizable** Allows an array for source directories and for layout directories.
@@ -1,8 +1,11 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require 'sass'
4
+
3
5
  module Nutils
4
6
  module Filters
5
7
  class Sass < Nanoc3::Filters::Sass
8
+ FILES = []
6
9
  identifier :zass
7
10
  type :text
8
11
 
@@ -13,70 +16,62 @@ module Nutils
13
16
  #
14
17
  # @return [String] The filtered content
15
18
  def run(content, params={})
16
- require 'sass'
17
-
18
- # Add imported_filename read accessor to ImportNode
19
- # … but… but… nex3 said I could monkey patch it! :(
20
- methods = ::Sass::Tree::ImportNode.instance_methods
21
- if !methods.include?(:import_filename) && !methods.include?('import_filename')
22
- ::Sass::Tree::ImportNode.send(:attr_reader, :imported_filename)
23
- end
24
-
25
19
  # Get options
26
20
  options = params.dup
27
21
  sass_filename = options[:filename] || (@item && @item[:content_filename])
28
22
  options[:filename] ||= sass_filename
29
-
23
+ options[:filesystem_importer] ||= Nutils::Importers::Nanoc
24
+
30
25
  # Build engine
31
26
  engine = ::Sass::Engine.new(content, options)
32
-
33
- # Get import nodes
34
- require 'set'
35
- imported_nodes = []
36
- unprocessed_nodes = Set.new([ engine.to_tree ])
37
- until unprocessed_nodes.empty?
38
- # Get an unprocessed node
39
- node = unprocessed_nodes.each { |n| break n }
40
- unprocessed_nodes.delete(node)
41
-
42
- # Add to list of import nodes if necessary
43
- imported_nodes << node if node.is_a?(::Sass::Tree::ImportNode)
44
-
45
- # Mark children of this node for processing
46
- node.children.each { |c| unprocessed_nodes << c }
27
+ output = engine.render
28
+
29
+ until Nutils::Filters::Sass::FILES.empty?
30
+ filename = Nutils::Filters::Sass::FILES.pop
31
+ notify(filename)
47
32
  end
33
+
34
+ return output
35
+ end
48
36
 
49
- # Get import paths
50
- import_paths = (options[:load_paths] || []).dup
51
- import_paths.unshift(File.dirname(sass_filename)) if sass_filename
52
- # Get imported filenames
53
- imported_filenames = imported_nodes.map do |node|
54
- ::Sass::Files.find_file_to_import(node.imported_filename, import_paths)
55
- end
37
+ def notify(filename)
38
+ pathname = Pathname.new(filename)
39
+ item = @items.find { |i| i[:content_filename] && Pathname.new(i[:content_filename]).realpath == pathname.realpath }
40
+
41
+ # Notify
42
+ ::Nanoc3::NotificationCenter.post(:visit_started, item)
43
+ ::Nanoc3::NotificationCenter.post(:visit_ended, item)
44
+
45
+ # Raise unmet dependency error if item is not yet compiled
46
+ any_uncompiled_rep = item.reps.find { |r| !r.compiled? }
47
+ raise ::Nanoc3::Errors::UnmetDependency.new(any_uncompiled_rep) if any_uncompiled_rep
48
+ end
56
49
 
57
- # Convert to items
58
- imported_items = imported_filenames.map do |filename|
59
- pathname = Pathname.new(filename)
60
- next unless pathname.file?
61
- normalized_filename = pathname.realpath
62
- @items.find { |i| i[:content_filename] && Pathname.new(i[:content_filename]).realpath == normalized_filename }
63
- end.compact
50
+ end
51
+ end
64
52
 
65
- # Require compilation of each item
66
- imported_items.each do |item|
67
- # Notify
68
- Nanoc3::NotificationCenter.post(:visit_started, item)
69
- Nanoc3::NotificationCenter.post(:visit_ended, item)
70
53
 
71
- # Raise unmet dependency error if item is not yet compiled
72
- any_uncompiled_rep = item.reps.find { |r| !r.compiled? }
73
- raise Nanoc3::Errors::UnmetDependency.new(any_uncompiled_rep) if any_uncompiled_rep
74
- end
54
+ module Importers
75
55
 
76
- # Done
77
- engine.render
56
+ ##
57
+ # Essentially the {Sass::Importers::Filesystem} but registering each import
58
+ # file path.
59
+ class Nanoc < ::Sass::Importers::Filesystem
60
+
61
+ private
62
+
63
+ def _find(dir, name, options)
64
+ full_filename, syntax = find_real_file(dir, name)
65
+ return unless full_filename && File.readable?(full_filename)
66
+
67
+ Nutils::Filters::Sass::FILES << full_filename
68
+
69
+ options[:syntax] = syntax
70
+ options[:filename] = full_filename
71
+ options[:importer] = self
72
+ ::Sass::Engine.new(File.read(full_filename), options)
78
73
  end
79
-
80
74
  end
81
75
  end
76
+
82
77
  end
@@ -1,15 +1,17 @@
1
1
  module Nutils
2
2
  module Filters
3
- autoload "Beautify", "nutils/filters/beautify"
4
- autoload "Crop", "nutils/filters/crop"
5
- autoload "SprocketWheel", "nutils/filters/sprockets"
6
- autoload "SvgToPng", "nutils/filters/svg2png"
7
- autoload "YuiCompressor", "nutils/filters/yuicompressor"
3
+ autoload 'Beautify', 'nutils/filters/beautify'
4
+ autoload 'Crop', 'nutils/filters/crop'
5
+ autoload 'SprocketWheel', 'nutils/filters/sprockets'
6
+ autoload 'SvgToPng', 'nutils/filters/svg2png'
7
+ autoload 'YuiCompressor', 'nutils/filters/yuicompressor'
8
+ autoload 'Sass', 'nutils/filters/sass'
8
9
 
9
- ::Nanoc3::Filter.register "::Nutils::Filters::Beautify", :beautify
10
- ::Nanoc3::Filter.register "::Nutils::Filters::Crop", :crop
11
- ::Nanoc3::Filter.register "::Nutils::Filters::SprocketWheel", :sprockets
12
- ::Nanoc3::Filter.register "::Nutils::Filters::SvgToPng", :svg_to_png
13
- ::Nanoc3::Filter.register "::Nutils::Filters::YuiCompressor", :yuicompressor
10
+ ::Nanoc3::Filter.register '::Nutils::Filters::Beautify', :beautify
11
+ ::Nanoc3::Filter.register '::Nutils::Filters::Crop', :crop
12
+ ::Nanoc3::Filter.register '::Nutils::Filters::SprocketWheel', :sprockets
13
+ ::Nanoc3::Filter.register '::Nutils::Filters::SvgToPng', :svg_to_png
14
+ ::Nanoc3::Filter.register '::Nutils::Filters::YuiCompressor', :yuicompressor
15
+ ::Nanoc3::Filter.register '::Nutils::Filters::Sass', :zass
14
16
  end
15
17
  end
data/lib/nutils.rb CHANGED
@@ -3,15 +3,15 @@
3
3
  module Nutils
4
4
 
5
5
  # The current nutils version.
6
- VERSION = "0.7.0"
6
+ VERSION = '0.8.1'
7
7
 
8
8
  end
9
9
 
10
10
  # Load requirements
11
- require "nanoc3"
11
+ require 'nanoc3'
12
12
 
13
13
  # Load nutils
14
- require "nutils/base"
15
- require "nutils/data_sources"
16
- require "nutils/filters"
17
- require "nutils/helpers"
14
+ require 'nutils/base'
15
+ require 'nutils/data_sources'
16
+ require 'nutils/filters'
17
+ require 'nutils/helpers'
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: 3
4
+ hash: 61
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 7
9
- - 0
10
- version: 0.7.0
8
+ - 8
9
+ - 1
10
+ version: 0.8.1
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-02-13 00:00:00 -05:00
18
+ date: 2011-04-26 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency