nanoc-dart-sass 1.0.4 → 2.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00b8a5410aedb44c77a639f2607d9769df7d5fac58f331d576980b3958f362c5
4
- data.tar.gz: 85e761f9c95f6c3f5cea82e438a7f7b1b3b7b92b4def0ad0beca8f5c96bade4d
3
+ metadata.gz: a840ef7c17c7990a2284598a2c33f76f7ab9e8dc36a2b80b5f92fed04d372e76
4
+ data.tar.gz: c3af25569e9f23519cf53bad2cdd5f01bfbb328d3e6f732447f6f5fa68eee76b
5
5
  SHA512:
6
- metadata.gz: 634b5c0a938d24fee988c2dd17de69ae97d0333da032ee48c3b99c4fb165693b4047353665838edd28976bb1cdd33012eb7df4a3b10a3650574a98e597ab6b7e
7
- data.tar.gz: 6cf0ceccc71587928aecaa1322a23a40baaf15e4511f5085b40a00384805f2d7e00f093f878b1023804652f11916be82556fb07d258dedd313127ffce5761421
6
+ metadata.gz: 794c4037f669e64e01c4bcae49c3a83b790d13d8598d39f99e5e128127735adea09cb9d384f8973aec4ab58e70af7990d7369f7f048772b97b3d0b46bcb8f310
7
+ data.tar.gz: 94a5d55959ba24ea46254632bfa1ed2c1e3b7424f69084ae628f0be68afe66cab37e0e92e59f0abced939710bd34af8bec880cf2ce09b514bde6f86f483c74d3
data/NEWS.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # nanoc-dart-sass news
2
2
 
3
+ ## 2.0.0 (2025-12-31)
4
+
5
+ Features:
6
+
7
+ - Added support for `source_map` option [ntkme] (#1749, #1775)
8
+
9
+ Changes:
10
+
11
+ - Changed the importer to be in line with the spec [ntkme] (#1755)
12
+
3
13
  ## 1.0.4 (2024-11-04)
4
14
 
5
15
  Fixes:
@@ -18,30 +18,37 @@ module Nanoc
18
18
 
19
19
  result = Sass.compile_string(
20
20
  content,
21
- importer: NanocImporter.new(@items, item),
21
+ source_map_include_sources: true,
22
22
  **params,
23
+ importers: [NanocImporter.new(@items)].concat(params.fetch(:importers, [])),
23
24
  syntax:,
25
+ url: Addressable::URI.new({ scheme: 'nanoc', path: item.identifier.to_s }).to_s,
24
26
  )
25
- result.css
27
+
28
+ if result.source_map
29
+ "#{result.css}\n/*# sourceMappingURL=data:application/json;base64,#{[result.source_map].pack('m0')} */"
30
+ else
31
+ result.css
32
+ end
26
33
  end
27
34
 
28
35
  class NanocImporter
29
- def initialize(items, source_item)
36
+ def initialize(items)
30
37
  @items = items
31
- @source_item = source_item
32
38
  end
33
39
 
34
- def canonicalize(url, *, **)
35
- # Construct proper URL with `nanoc:` prefix if needed
36
- if url.start_with?('nanoc:')
37
- url
38
- else
39
- "nanoc:#{url}"
40
- end
40
+ def canonicalize(url, context)
41
+ uri = Addressable::URI.parse(url)
42
+ uri = Addressable::URI.parse(context.containing_url).join(uri) unless context.containing_url.nil?
43
+ return unless uri.scheme == 'nanoc'
44
+
45
+ resolved = resolve_path(uri.path, context.from_import)
46
+ Addressable::URI.new({ scheme: 'nanoc', path: resolved }).to_s unless resolved.nil?
41
47
  end
42
48
 
43
49
  def load(url)
44
- item = find_item_for_url(url)
50
+ uri = Addressable::URI.parse(url)
51
+ item = @items[uri.path]
45
52
 
46
53
  {
47
54
  contents: item.raw_content,
@@ -51,62 +58,72 @@ module Nanoc
51
58
 
52
59
  private
53
60
 
54
- def find_item_for_url(url)
55
- pat = url.sub(/\Ananoc:/, '')
61
+ # https://github.com/sass-contrib/sassc-embedded-shim-ruby/blob/594632bb896fb765462253b16ea0451f5f93316d/lib/sassc/embedded.rb#L228
62
+ def resolve_path(path, from_import)
63
+ ext = File.extname(path)
64
+ if ext == '.*'
65
+ if from_import
66
+ result = exactly_one(try_path_with_ext("#{without_ext(path)}.import") + try_path_with_ext("#{path}.import"))
67
+ return result unless result.nil?
68
+ end
56
69
 
57
- is_extension_given = !pat.match?(%r{(/|^)[^.]+$})
70
+ result = exactly_one(try_path_with_ext(without_ext(path)) + try_path_with_ext(path))
71
+ return result unless result.nil?
58
72
 
59
- # Convert to absolute pattern
60
- pat =
61
- if pat.start_with?('/')
62
- pat
63
- else
64
- dirname = File.dirname(@source_item.identifier.to_s)
65
- Nanoc::Core::Utils.expand_path_without_drive_identifier(pat, dirname)
66
- end
73
+ return try_path_as_dir(path, from_import)
74
+ end
67
75
 
68
- items = collect_items(pat, is_extension_given)
76
+ if ['.sass', '.scss', '.css'].include?(ext)
77
+ if from_import
78
+ result = exactly_one(try_path("#{without_ext(path)}.import#{ext}"))
79
+ return result unless result.nil?
80
+ end
81
+ return exactly_one(try_path(path))
82
+ end
69
83
 
70
- # Get the single matching item, or error if there isn’t exactly one
71
- items = items.compact
72
- case items.size
73
- when 0
74
- raise "Could not find an item matching pattern `#{pat}`"
75
- when 1
76
- items.first
77
- else
78
- raise "It is not clear which item to import. Multiple items match `#{pat}`: #{items.map { _1.identifier.to_s }.sort.join(', ')}"
84
+ if from_import
85
+ result = exactly_one(try_path_with_ext("#{path}.import"))
86
+ return result unless result.nil?
79
87
  end
80
- end
81
88
 
82
- # Given a pattern, return a collection of items that match this pattern.
83
- # This goes beyond what Nanoc patterns typically support by e.g.
84
- # supporting partials and index imports.
85
- def collect_items(pat, is_extension_given)
86
- items = []
89
+ result = exactly_one(try_path_with_ext(path))
90
+ return result unless result.nil?
87
91
 
88
- # Try as a regular path
89
- items.concat(try_pat(pat, is_extension_given))
92
+ try_path_as_dir(path, from_import)
93
+ end
90
94
 
91
- # Try as a partial
92
- partial_pat = File.join(File.dirname(pat), "_#{File.basename(pat)}")
93
- items.concat(try_pat(partial_pat, is_extension_given))
95
+ def try_path_with_ext(path)
96
+ result = try_path("#{path}.sass") + try_path("#{path}.scss")
97
+ result.empty? ? try_path("#{path}.css") : result
98
+ end
99
+
100
+ def try_path(path)
101
+ partial = File.join(File.dirname(path), "_#{File.basename(path)}")
102
+ result = []
103
+ result.concat(@items.find_all(partial).map(&:identifier).map(&:to_s))
104
+ result.concat(@items.find_all(path).map(&:identifier).map(&:to_s))
105
+ result
106
+ end
94
107
 
95
- # Try as index
96
- unless is_extension_given
97
- items.concat(@items.find_all(File.join(pat, '/index.*')))
98
- items.concat(@items.find_all(File.join(pat, '/_index.*')))
108
+ def try_path_as_dir(path, from_import)
109
+ if from_import
110
+ result = exactly_one(try_path_with_ext(File.join(path, 'index.import')))
111
+ return result unless result.nil?
99
112
  end
100
113
 
101
- items
114
+ exactly_one(try_path_with_ext(File.join(path, 'index')))
102
115
  end
103
116
 
104
- def try_pat(pat, is_extension_given)
105
- if is_extension_given
106
- @items.find_all(pat)
107
- else
108
- @items.find_all("#{pat}.*")
109
- end
117
+ def exactly_one(paths)
118
+ return if paths.empty?
119
+ return paths.first if paths.one?
120
+
121
+ raise "It's not clear which file to import. Found:\n#{paths.map { |path| " #{path}" }.join("\n")}"
122
+ end
123
+
124
+ def without_ext(path)
125
+ ext = File.extname(path)
126
+ path.delete_suffix(ext)
110
127
  end
111
128
  end
112
129
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Nanoc
4
4
  module DartSass
5
- VERSION = '1.0.4'
5
+ VERSION = '2.0.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc-dart-sass
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Defreyne
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-11-04 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: nanoc-core
@@ -16,34 +15,28 @@ dependencies:
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '4.13'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 4.13.1
18
+ version: '4.14'
23
19
  type: :runtime
24
20
  prerelease: false
25
21
  version_requirements: !ruby/object:Gem::Requirement
26
22
  requirements:
27
23
  - - "~>"
28
24
  - !ruby/object:Gem::Version
29
- version: '4.13'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 4.13.1
25
+ version: '4.14'
33
26
  - !ruby/object:Gem::Dependency
34
27
  name: sass-embedded
35
28
  requirement: !ruby/object:Gem::Requirement
36
29
  requirements:
37
30
  - - "~>"
38
31
  - !ruby/object:Gem::Version
39
- version: '1.56'
32
+ version: '1.80'
40
33
  type: :runtime
41
34
  prerelease: false
42
35
  version_requirements: !ruby/object:Gem::Requirement
43
36
  requirements:
44
37
  - - "~>"
45
38
  - !ruby/object:Gem::Version
46
- version: '1.56'
39
+ version: '1.80'
47
40
  description: Provides a :dart_sass filter for Nanoc
48
41
  email: denis+rubygems@denis.ws
49
42
  executables: []
@@ -62,8 +55,7 @@ licenses:
62
55
  - MIT
63
56
  metadata:
64
57
  rubygems_mfa_required: 'true'
65
- source_code_uri: https://github.com/nanoc/nanoc/tree/nanoc-dart-sass-v1.0.4/nanoc-dart-sass
66
- post_install_message:
58
+ source_code_uri: https://github.com/nanoc/nanoc/tree/nanoc-dart-sass-v2.0.0/nanoc-dart-sass
67
59
  rdoc_options: []
68
60
  require_paths:
69
61
  - lib
@@ -71,15 +63,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
63
  requirements:
72
64
  - - ">="
73
65
  - !ruby/object:Gem::Version
74
- version: '3.1'
66
+ version: '3.2'
75
67
  required_rubygems_version: !ruby/object:Gem::Requirement
76
68
  requirements:
77
69
  - - ">="
78
70
  - !ruby/object:Gem::Version
79
71
  version: '0'
80
72
  requirements: []
81
- rubygems_version: 3.5.21
82
- signing_key:
73
+ rubygems_version: 4.0.3
83
74
  specification_version: 4
84
75
  summary: Dart Sass filter for Nanoc
85
76
  test_files: []