jekyll-sass 1.1.0 → 1.2.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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Roger López, Jason Kozak, Joe Buszkiewic
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
@@ -20,4 +20,5 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_runtime_dependency('jekyll', [">= 0.10.0"])
22
22
  s.add_runtime_dependency('sass', [">= 3.0.0"])
23
+ s.add_runtime_dependency('colorator', "~> 0.1")
23
24
  end
@@ -1,32 +1,50 @@
1
1
  require "jekyll-sass/version"
2
+ require "colorator"
2
3
 
3
4
  module Jekyll
4
5
  module Sass
5
6
  require 'sass'
6
7
 
7
8
  class SassConfig
8
- def self.generate()
9
- config = Hash["style", :compressed, "syntax", :scss]
10
- if Jekyll.configuration({}).has_key?('sass')
11
- config.merge!(Jekyll.configuration({})['sass']) {|key,v1,v2| v2.to_sym}
9
+ def self.style(site)
10
+ if site.config['watch']
11
+ style = site.config['sass']['style'] || 'expanded'
12
+ else
13
+ style = site.config['sass']['deploy_style'] ||
14
+ site.config['sass']['style'] ||
15
+ 'compressed'
12
16
  end
13
- config
17
+ style.to_sym
14
18
  end
15
19
 
16
- def self.get()
17
- @config ||= generate()
20
+ def self.line_comments(site)
21
+ should_comment = false
22
+ if site.config['watch'] && self.style(site).to_s == 'expanded'
23
+ should_comment = true
24
+ end
25
+ should_comment
26
+ end
27
+
28
+ def self.compile_in_place?(site)
29
+ site.config['sass']['compile_in_place']
18
30
  end
19
31
  end
20
32
 
21
33
  class SassCssFile < StaticFile
34
+ class << self
35
+ attr_accessor :should_write_sass
36
+ end
22
37
 
23
38
  # Obtain destination path.
24
39
  # +dest+ is the String path to the destination dir
25
40
  #
26
41
  # Returns destination file path.
27
42
  def destination(dest)
28
- syntax = SassConfig.get()['syntax'].to_s
29
- File.join(dest, @dir, @name.sub(/#{syntax}$/, 'css'))
43
+ File.join(dest, @dir, File.basename(@name, ".*") + ".css")
44
+ end
45
+
46
+ def in_place_destination(dest)
47
+ File.join(File.dirname(path), File.basename(@name, ".*") + ".css")
30
48
  end
31
49
 
32
50
  # Convert the sass/scss file into a css file.
@@ -34,28 +52,37 @@ module Jekyll
34
52
  #
35
53
  # Returns false if the file was not modified since last time (no-op).
36
54
  def write(dest)
37
- config = SassConfig.get()
38
- dest_path = destination(dest)
55
+ return false if !SassCssFile.should_write_sass
39
56
 
40
- return false if File.exist? dest_path and !modified?
41
57
  @@mtimes[path] = mtime
42
-
58
+ dest_path = destination(dest)
43
59
  FileUtils.mkdir_p(File.dirname(dest_path))
44
60
  begin
45
- content = File.read(path)
46
- engine = ::Sass::Engine.new( content, :syntax => config['syntax'], :load_paths => ["#{@site.source}#{@dir}"], :style => config['style'] )
61
+ engine = ::Sass::Engine.for_file(path,
62
+ :style => SassConfig.style(@site),
63
+ :line_comments => SassConfig.line_comments(@site))
47
64
  content = engine.render
48
65
  File.open(dest_path, 'w') do |f|
49
66
  f.write(content)
50
67
  end
51
- rescue => e
52
- STDERR.puts "Sass failed generating '#{dest_path}': #{e.message}"
68
+ if SassConfig.compile_in_place?(@site)
69
+ in_place_dest_path = in_place_destination(dest)
70
+ File.open(in_place_dest_path, 'w') do |f|
71
+ f.write(content)
72
+ end
73
+ end
74
+ rescue ::Sass::SyntaxError => e
75
+ STDERR.puts "Sass failed generating '#{e.sass_filename}' line:#{e.sass_line} '#{e.message}'".red
53
76
  false
54
77
  end
55
-
56
78
  true
57
79
  end
80
+ end
58
81
 
82
+ class SuppressedSassFile < StaticFile
83
+ def update_mtime
84
+ @@mtimes[path] = mtime
85
+ end
59
86
  end
60
87
 
61
88
  class SassCssGenerator < Generator
@@ -65,18 +92,93 @@ module Jekyll
65
92
  # objects to the static_files array. Here we replace those with a
66
93
  # SassCssFile object.
67
94
  def generate(site)
68
- syntax = SassConfig.get()['syntax'].to_s
69
95
  site.static_files.clone.each do |sf|
70
- if sf.kind_of?(Jekyll::StaticFile) && sf.path =~ /\.#{syntax}$/
96
+ if sf.path =~ /\.(scss|sass)$/
71
97
  site.static_files.delete(sf)
72
98
  name = File.basename(sf.path)
73
99
  destination = File.dirname(sf.path).sub(site.source, '')
74
- site.static_files << SassCssFile.new(site, site.source, destination, name)
100
+ sass_file = SassCssFile.new(site, site.source, destination, name)
101
+ if sass_file.modified?
102
+ SassCssFile.should_write_sass = true
103
+ end
104
+ site.static_files << sass_file
75
105
  end
76
106
  end
107
+ supp_files = suppressed_sass_files(site)
108
+ if suppressed_files_modified?(supp_files)
109
+ SassCssFile.should_write_sass = true
110
+ update_files_mtime(supp_files)
111
+ end
77
112
  end
78
113
 
79
- end
114
+ def suppressed_files_modified?(files)
115
+ files.each do |file|
116
+ return true if file.modified?
117
+ end
118
+ return false
119
+ end
80
120
 
121
+ def update_files_mtime(files)
122
+ files.each do |file|
123
+ file.update_mtime
124
+ end
125
+ end
126
+
127
+ def suppressed_sass_files(site)
128
+ sass_matcher = /^_.*\.(sass|scss)/
129
+ suppressed_sass_paths = recursively_search_directories(site, sass_matcher)
130
+ files = [ ]
131
+ suppressed_sass_paths.each do |path|
132
+ name = File.basename(path)
133
+ destination = File.dirname(path).sub(site.source, '')
134
+ files << SuppressedSassFile.new(site, site.source, destination, name)
135
+ end
136
+ return files
137
+ end
138
+
139
+ # Recursively find files in site that match a regexp
140
+ # Does not ignore underscored files
141
+ # This could probably be shortened but
142
+ # we need to search like jekyll searches
143
+ #
144
+ # site - The Jekyll site
145
+ # matcher - a regexp for the filename's to find
146
+ # dir - the relative directory to recurse in
147
+ #
148
+ # Returns an Array of absolute paths that match
149
+ def recursively_search_directories(site, matcher, dir = '')
150
+ base = File.join(site.source, dir)
151
+ entries = Dir.chdir(base) { filter_files(Dir.entries('.'), site) }
152
+ found = [ ]
153
+ entries.each do |f|
154
+ f_abs = File.join(base, f)
155
+ found << f_abs if matcher.match(f)
156
+ if File.directory?(f_abs)
157
+ f_rel = File.join(dir, f)
158
+ if site.dest.sub(/\/$/, '') != f_abs
159
+ more_found = recursively_search_directories(site, matcher, f_rel)
160
+ found.concat(more_found)
161
+ end
162
+ end
163
+ end
164
+ return found
165
+ end
166
+
167
+ # Filter out any files/directories that are specifically
168
+ # excluded in the site config
169
+ #
170
+ # entries - The Array of String file/directory entries to filter.
171
+ #
172
+ # Returns the Array of filtered entries.
173
+ def filter_files(entries, site)
174
+ entries.reject do |e|
175
+ unless site.include.glob_include?(e)
176
+ ['.', '#'].include?(e[0..0]) ||
177
+ site.exclude.glob_include?(e) ||
178
+ (File.symlink?(e) && site.safe)
179
+ end
180
+ end
181
+ end
182
+ end
81
183
  end
82
184
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Sass
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
data/readme.md CHANGED
@@ -2,7 +2,7 @@ Sass for Jekyll
2
2
  ===============
3
3
 
4
4
  This gem provides a [Jekyll](http://github.com/mojombo/jekyll) converter for
5
- [Sass](http://http://sass-lang.com//) files.
5
+ [Sass](http://sass-lang.com/) files.
6
6
 
7
7
  Basic Setup
8
8
  -----------
@@ -17,7 +17,7 @@ In a plugin file within your Jekyll project's `_plugins` directory:
17
17
 
18
18
  Place .scss files anywhere in your Jekyll project's directory. These will be
19
19
  converted to .css files with the same directory path and filename. For example,
20
- if you create a Less file at `css/my-stuff/styles.scss`, then the corresponding
20
+ if you create an `scss` file at `css/my-stuff/styles.scss`, then the corresponding
21
21
  css file would end up at `css/my-stuff/styles.css`.
22
22
 
23
23
  Bundler Setup
@@ -38,11 +38,18 @@ Configuration
38
38
  -------------
39
39
  In your `_config.yml`
40
40
 
41
- # defaults
41
+ # defaults
42
42
  sass:
43
- syntax: scss # scss|sass
44
- style: compressed # nested|expanded|compact|compressed
43
+ style: expanded # nested|expanded|compact|compressed
44
+ deploy_style: compressed # nested|expanded|compact|compressed
45
+ # "deploy_style:" is used only for building the site
46
+ # (ie: not using the --watch flag)
47
+
48
+ compile_in_place: false # true|false
49
+ # If true, compiles sass directly into your jekyll source directory
50
+ # As well as your destination directory
45
51
 
46
52
  Credit
47
53
  ------
48
- This gem is based on [Roger López's](https://github.com/zroger) [jekyll-less](https://github.com/zroger/jekyll-less), with contributions from [Joe Buszkiewic](https://github.com/zznq).
54
+ This gem is based on [@zroger's](https://github.com/zroger) [jekyll-less](https://github.com/zroger/jekyll-less),
55
+ with contributions from [@zznq](https://github.com/zznq), [@Tambling](https://github.com/Tambling), and [@rebelzach](https://github.com/rebelzach).
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: jekyll-sass
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.1.0
5
+ version: 1.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jason Kozak
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-11-20 00:00:00 Z
13
+ date: 2013-11-21 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: jekyll
@@ -34,6 +34,17 @@ dependencies:
34
34
  version: 3.0.0
35
35
  type: :runtime
36
36
  version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: colorator
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: "0.1"
46
+ type: :runtime
47
+ version_requirements: *id003
37
48
  description: Convert Sass SCSS files to standard CSS files as part of your Jekyll build.
38
49
  email:
39
50
  - jay@noctal.com
@@ -46,6 +57,7 @@ extra_rdoc_files: []
46
57
  files:
47
58
  - .gitignore
48
59
  - Gemfile
60
+ - LICENSE
49
61
  - Rakefile
50
62
  - jekyll-sass.gemspec
51
63
  - lib/jekyll-sass.rb