jekyll-sass-converter 1.5.2 → 2.0.0.pre.beta

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a89449e32d89721639e197984bc0ff57632a816ca8649d787d07c0b8b7e94cc0
4
- data.tar.gz: 0b4d273ad2a4463e679f70971a742fdb779376d8f37bb1ace8f7596fa3a27431
3
+ metadata.gz: 32ee65ba1a116c08b27670f7927808870566b835f04f2e6306635feeab013d52
4
+ data.tar.gz: e92c052e3d395c0b9fe6ca3337a8815eb752b7db09805597988f1eabf02bc40e
5
5
  SHA512:
6
- metadata.gz: 3268e9b3fce2074122f16fc64882b75048847930ae7329d42268bfe7e519d92b2727b4564f6c587c95922075ca5cc0d2d39287ac8abbdad5f70f7b5b16431b78
7
- data.tar.gz: bfbf9cf8fc49ebfc788287ef5e5abd810c9cbf26634d96d43876375ac3ddd0923e5c381f7bed4d4a9cedb616d86e46766c7483bfb67b343a8c38e6731bfcc6da
6
+ metadata.gz: 32b9663ca870b8a92a8abad9fe6e4cc1d3367821a08c4f9d78888e0e52444cb9469844148c2ba1de364b4022d70186dbbb3ef3ea264093a6c4980e7e26cb4b99
7
+ data.tar.gz: 5f2041e1f9b46900bad242431ce1a686dd8919657f0a9810c7256e93986dd7cec36f8506ebbc1a1261fb372ab56bcb230ee2645dfbe35134f7c88c5dec0b7589
data/lib/fake-sass.rb ADDED
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This module helps to get rid of the now deprecated
4
+ # [ruby-sass](https://github.com/sass/ruby-sass).
5
+ #
6
+ # Some modules used in jekyll depend on the function `Sass.load_paths`
7
+ # from ruby-sass. (see for example `Jekyll::Theme.configure_sass`).
8
+ #
9
+ # This module provides a workaround when ruby-sass is not installed
10
+ # by faking this functionality...
11
+ #
12
+ # Please note that this module should never be installed __together__ with ruby-sass.
13
+ module Sass
14
+ # The global load paths for Sass files. This is meant for plugins and libraries to register
15
+ # the paths to their Sass stylesheets to that they may be `@imported`. This load path is used
16
+ # by every instance of {Sass::Engine}.
17
+ # They are lower-precedence than any load paths passed in via the
18
+ # {file:SASS_REFERENCE.md#load_paths-option `:load_paths` option}.
19
+ #
20
+ # If the `SASS_PATH` environment variable is set, the initial value of `load_paths` will be
21
+ # initialized based on that. The variable should be a colon-separated list of path names
22
+ # (semicolon-separated on Windows).
23
+ #
24
+ # Note that files on the global load path are never compiled to CSS themselves, even if they
25
+ # aren't partials. They exist only to be imported.
26
+ #
27
+ # @example
28
+ # Sass.load_paths << File.dirname(__FILE__ + '/sass')
29
+ # @return [Array<String, Pathname, Sass::Importers::Base>]
30
+ def self.load_paths
31
+ @load_paths ||= ENV["SASS_PATH"].to_s.split(File::PATH_SEPARATOR)
32
+ end
33
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "fake-sass"
3
4
  require "jekyll-sass-converter/version"
4
5
  require "jekyll/converters/scss"
5
6
  require "jekyll/converters/sass"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllSassConverter
4
- VERSION = "1.5.2".freeze
4
+ VERSION = "2.0.0.pre.beta"
5
5
  end
@@ -1,19 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "sass"
3
+ require "sassc"
4
4
  require "jekyll/utils"
5
5
  require "jekyll/converters/scss"
6
6
 
7
7
  module Jekyll
8
8
  module Converters
9
9
  class Sass < Scss
10
+ EXTENSION_PATTERN = %r!^\.sass$!i.freeze
11
+
10
12
  safe true
11
13
  priority :low
12
14
 
13
- def matches(ext)
14
- ext =~ %r!^\.sass$!i
15
- end
16
-
17
15
  def syntax
18
16
  :sass
19
17
  end
@@ -1,21 +1,71 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "sass"
3
+ require "sassc"
4
4
  require "jekyll/utils"
5
+ require "jekyll/source_map_page"
5
6
 
6
7
  module Jekyll
7
8
  module Converters
8
9
  class Scss < Converter
9
- BYTE_ORDER_MARK = %r!^\xEF\xBB\xBF!
10
+ BYTE_ORDER_MARK = %r!^\xEF\xBB\xBF!.freeze
11
+ EXTENSION_PATTERN = %r!^\.scss$!i.freeze
12
+
10
13
  SyntaxError = Class.new(ArgumentError)
11
14
 
12
15
  safe true
13
16
  priority :low
14
17
 
18
+ # This hook is triggered just before the method {#convert(content)} is executed, it
19
+ # associates the Scss (and Sass) converters with their respective sass_page objects.
20
+ Jekyll::Hooks.register :pages, :pre_render do |page|
21
+ page.converters.each do |converter|
22
+ converter.associate_page(page) if converter.is_a?(Jekyll::Converters::Scss)
23
+ end
24
+ end
25
+
26
+ # This hook is triggered just after the method {#convert(content)} has been executed, it
27
+ # dissociates the Scss (and Sass) converters with their respective sass_page objects.
28
+ Jekyll::Hooks.register :pages, :post_render do |page|
29
+ page.converters.each do |converter|
30
+ converter.dissociate_page(page) if converter.is_a?(Jekyll::Converters::Scss)
31
+ end
32
+ end
33
+
15
34
  ALLOWED_STYLES = %w(nested expanded compact compressed).freeze
16
35
 
36
+ # Associate this Converter with the "page" object that manages input and output files for
37
+ # this converter.
38
+ #
39
+ # Note: changing the associated sass_page during the live time of this Converter instance
40
+ # may result in inconsistent results.
41
+ #
42
+ # @param [Jekyll:Page] page The sass_page for which this object acts as converter.
43
+ def associate_page(page)
44
+ if @sass_page
45
+ Jekyll.logger.debug "Sass Converter:",
46
+ "sass_page re-assigned: #{@sass_page.name} to #{page.name}"
47
+ dissociate_page(page)
48
+ return
49
+ end
50
+ @sass_page = page
51
+ end
52
+
53
+ # Dissociate this Converter with the "page" object.
54
+ #
55
+ # @param [Jekyll:Page] page The sass_page for which this object has acted as a converter.
56
+ def dissociate_page(page)
57
+ unless page.equal?(@sass_page)
58
+ Jekyll.logger.debug "Sass Converter:",
59
+ "dissociating a page that was never associated #{page.name}"
60
+ end
61
+
62
+ @source_map_page = nil
63
+ @sass_page = nil
64
+ @site = nil
65
+ end
66
+
17
67
  def matches(ext)
18
- ext =~ %r!^\.scss$!i
68
+ ext =~ self.class::EXTENSION_PATTERN
19
69
  end
20
70
 
21
71
  def output_ext(_ext)
@@ -27,21 +77,18 @@ module Jekyll
27
77
  end
28
78
 
29
79
  def jekyll_sass_configuration
30
- options = @config["sass"] || {}
31
- unless options["style"].nil?
32
- options["style"] = options["style"].to_s.gsub(%r!\A:!, "").to_sym
80
+ @jekyll_sass_configuration ||= begin
81
+ options = @config["sass"] || {}
82
+ unless options["style"].nil?
83
+ options["style"] = options["style"].to_s.gsub(%r!\A:!, "").to_sym
84
+ end
85
+ options
33
86
  end
34
- options
35
87
  end
36
88
 
37
89
  def sass_build_configuration_options(overrides)
38
90
  if safe?
39
- {
40
- :load_paths => sass_load_paths,
41
- :syntax => syntax,
42
- :style => sass_style,
43
- :cache => false,
44
- }
91
+ overrides
45
92
  else
46
93
  Jekyll::Utils.symbolize_hash_keys(
47
94
  Jekyll::Utils.deep_merge_hashes(
@@ -58,6 +105,7 @@ module Jekyll
58
105
 
59
106
  def sass_dir
60
107
  return "_sass" if jekyll_sass_configuration["sass_dir"].to_s.empty?
108
+
61
109
  jekyll_sass_configuration["sass_dir"]
62
110
  end
63
111
 
@@ -74,8 +122,12 @@ module Jekyll
74
122
  Jekyll.sanitized_path(site_source, sass_dir)
75
123
  end
76
124
 
125
+ # rubocop:disable Metrics/AbcSize
77
126
  def sass_load_paths
78
- paths = user_sass_load_paths + [sass_dir_relative_to_site_source]
127
+ paths = user_sass_load_paths +
128
+ [sass_dir_relative_to_site_source] +
129
+ Array(::Sass.load_paths)
130
+ paths << site.theme.sass_path if site.theme&.sass_path
79
131
 
80
132
  if safe?
81
133
  # Sanitize paths to prevent any attack vectors (.e.g. `/**/*`)
@@ -98,6 +150,7 @@ module Jekyll
98
150
 
99
151
  paths.select { |path| File.directory?(path) }
100
152
  end
153
+ # rubocop:enable Metrics/AbcSize
101
154
 
102
155
  def allow_caching?
103
156
  !safe?
@@ -108,24 +161,125 @@ module Jekyll
108
161
  end
109
162
 
110
163
  def sass_configs
111
- sass_build_configuration_options({
112
- "syntax" => syntax,
113
- "cache" => allow_caching?,
114
- "load_paths" => sass_load_paths,
115
- })
164
+ sass_build_configuration_options(
165
+ :style => sass_style,
166
+ :syntax => syntax,
167
+ :filename => filename,
168
+ :output_path => output_path,
169
+ :source_map_file => source_map_file,
170
+ :load_paths => sass_load_paths,
171
+ :omit_source_map_url => !sourcemap_required?,
172
+ :source_map_contents => true,
173
+ :line_comments_option => line_comments_option
174
+ )
116
175
  end
117
176
 
118
177
  def convert(content)
119
- output = ::Sass.compile(content, sass_configs)
178
+ config = sass_configs
179
+ engine = SassC::Engine.new(content.dup, config)
180
+ output = engine.render
181
+ generate_source_map(engine) if sourcemap_required?
120
182
  replacement = add_charset? ? '@charset "UTF-8";' : ""
121
183
  output.sub(BYTE_ORDER_MARK, replacement)
122
- rescue ::Sass::SyntaxError => e
123
- raise SyntaxError, "#{e} on line #{e.sass_line}"
184
+ rescue SassC::SyntaxError => e
185
+ raise SyntaxError, e.to_s
124
186
  end
125
187
 
126
188
  private
189
+
190
+ # The Page instance for which this object acts as a converter.
191
+ attr_reader :sass_page
192
+
193
+ def associate_page_failed?
194
+ !sass_page
195
+ end
196
+
197
+ # The name of the input scss (or sass) file. This information will be used for error
198
+ # reporting and will written into the source map file as main source.
199
+ #
200
+ # Returns the name of the input file or "stdin" if #associate_page failed
201
+ def filename
202
+ return "stdin" if associate_page_failed?
203
+
204
+ sass_page.name
205
+ end
206
+
207
+ # The value of the `line_comments` option.
208
+ # When set to `true` causes the line number and filename of the source be emitted into the
209
+ # compiled CSS-file. Useful for debugging when the source-map is not available.
210
+ #
211
+ # Returns the value of the `line_comments`-option chosen by the user or 'false' by default.
212
+ def line_comments_option
213
+ jekyll_sass_configuration.fetch("line_comments", false)
214
+ end
215
+
216
+ # The value of the `sourcemap` option chosen by the user.
217
+ #
218
+ # This option controls when sourcemaps shall be generated or not.
219
+ #
220
+ # Returns the value of the `sourcemap`-option chosen by the user or ':always' by default.
221
+ def sourcemap_option
222
+ jekyll_sass_configuration.fetch("sourcemap", :always).to_sym
223
+ end
224
+
225
+ # Determines whether a sourcemap shall be generated or not.
226
+ #
227
+ # Returns `true` if a sourcemap shall be generated, `false` otherwise.
228
+ def sourcemap_required?
229
+ return false if associate_page_failed? || sourcemap_option == :never
230
+ return true if sourcemap_option == :always
231
+
232
+ !(sourcemap_option == :development && Jekyll.env != "development")
233
+ end
234
+
235
+ # The name of the generated css file. This information will be written into the source map
236
+ # file as a backward reference to the input.
237
+ #
238
+ # Returns the name of the css file or "stdin.css" if #associate_page failed
239
+ def output_path
240
+ return "stdin.css" if associate_page_failed?
241
+
242
+ sass_page.basename + ".css"
243
+ end
244
+
245
+ # The name of the generated source map file. This information will be written into the
246
+ # css file to reference to the source map.
247
+ #
248
+ # Returns the name of the css file or "" if #associate_page failed
249
+ def source_map_file
250
+ return "" if associate_page_failed?
251
+
252
+ sass_page.basename + ".css.map"
253
+ end
254
+
255
+ def source_map_page
256
+ return if associate_page_failed?
257
+
258
+ @source_map_page ||= SourceMapPage.new(sass_page)
259
+ end
260
+
261
+ # Reads the source-map from the engine and adds it to the source-map-page.
262
+ #
263
+ # @param [::SassC::Engine] engine The sass Compiler engine.
264
+ def generate_source_map(engine)
265
+ return if associate_page_failed?
266
+
267
+ source_map_page.source_map(engine.source_map)
268
+ site.pages << source_map_page
269
+ rescue ::SassC::NotRenderedError => e
270
+ Jekyll.logger.warn "Could not generate source map #{e.message} => #{e.cause}"
271
+ end
272
+
273
+ def site
274
+ if associate_page_failed?
275
+ Jekyll.sites.last
276
+ else
277
+ sass_page.site
278
+ end
279
+ end
280
+
127
281
  def site_source
128
- @site_source ||= File.expand_path(@config["source"]).freeze
282
+ site.source
129
283
  end
130
284
  end
131
285
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ # A Jekyll::Page subclass to manage the source map file associated with
5
+ # a given scss / sass page.
6
+ class SourceMapPage < Page
7
+ # Initialize a new SourceMapPage.
8
+ #
9
+ # @param [Jekyll::Page] css_page The Page object that manages the css file.
10
+ def initialize(css_page)
11
+ @site = css_page.site
12
+ @dir = css_page.dir
13
+ @data = css_page.data
14
+ @name = css_page.basename + ".css.map"
15
+
16
+ process(@name)
17
+ Jekyll::Hooks.trigger :pages, :post_init, self
18
+ end
19
+
20
+ def source_map(map)
21
+ self.content = map
22
+ end
23
+
24
+ def ext
25
+ ".map"
26
+ end
27
+
28
+ def asset_file?
29
+ true
30
+ end
31
+
32
+ # @return[String] the object as a debug String.
33
+ def inspect
34
+ "#<#{self.class} @name=#{name.inspect}>"
35
+ end
36
+ end
37
+ end
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-sass-converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 2.0.0.pre.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - Parker Moore
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-03 00:00:00.000000000 Z
11
+ date: 2019-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: sass
14
+ name: sassc
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.4'
19
+ version: '2.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.4'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.5'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.5'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: jekyll
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.0'
47
+ version: '3.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2.0'
54
+ version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -81,19 +81,19 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: rubocop
84
+ name: rubocop-jekyll
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '='
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.51'
89
+ version: '0.4'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '='
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0.51'
96
+ version: '0.4'
97
97
  description:
98
98
  email:
99
99
  - parkrmoore@gmail.com
@@ -101,10 +101,12 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
+ - lib/fake-sass.rb
104
105
  - lib/jekyll-sass-converter.rb
105
106
  - lib/jekyll-sass-converter/version.rb
106
107
  - lib/jekyll/converters/sass.rb
107
108
  - lib/jekyll/converters/scss.rb
109
+ - lib/jekyll/source_map_page.rb
108
110
  homepage: https://github.com/jekyll/jekyll-sass-converter
109
111
  licenses:
110
112
  - MIT
@@ -117,15 +119,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
119
  requirements:
118
120
  - - ">="
119
121
  - !ruby/object:Gem::Version
120
- version: '0'
122
+ version: 2.4.0
121
123
  required_rubygems_version: !ruby/object:Gem::Requirement
122
124
  requirements:
123
- - - ">="
125
+ - - ">"
124
126
  - !ruby/object:Gem::Version
125
- version: '0'
127
+ version: 1.3.1
126
128
  requirements: []
127
- rubyforge_project:
128
- rubygems_version: 2.7.4
129
+ rubygems_version: 3.0.4
129
130
  signing_key:
130
131
  specification_version: 4
131
132
  summary: A basic Sass converter for Jekyll.