nanoc 4.10.0 → 4.10.1
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 +4 -4
- data/NEWS.md +6 -0
- data/lib/nanoc/filters/sass.rb +18 -114
- data/lib/nanoc/filters/sass/functions.rb +24 -0
- data/lib/nanoc/filters/sass/importer.rb +88 -0
- data/lib/nanoc/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 780927fbc58c76e3906df40019201441f6675433afbd34222ae79e7daeb0f4f0
|
4
|
+
data.tar.gz: 0c62c92d07ef676a555a8cf7c680226048788ae6cab56bcdd82ab2227d091794
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11011bf293454e1c66b644ed12864e1a8c6ab72a18548e2f770048097918cc08c5f48410968cec0bcaff85cd14f052ff4c78fc2040f19fe75232e283f949fc6d
|
7
|
+
data.tar.gz: d6fbdaca866cf1b79b4bac978a1c09c3dbd36ad2b6a1d4d90e832f04b3e5133e7496e1e247bcafaff1b53baca9cf0cfd354eee69504757163115ed05c7910fd5
|
data/NEWS.md
CHANGED
data/lib/nanoc/filters/sass.rb
CHANGED
@@ -1,19 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Nanoc::Filters
|
4
|
-
|
5
|
-
|
6
|
-
css(self, @item_rep, content, params)
|
7
|
-
end
|
8
|
-
|
9
|
-
Nanoc::Filter.define(:sass_sourcemap) do |content, params = {}|
|
10
|
-
include Sass
|
11
|
-
sourcemap(self, @item_rep, content, params)
|
12
|
-
end
|
4
|
+
module SassCommon
|
5
|
+
REQUIRES = %w[sass nanoc/filters/sass/importer nanoc/filters/sass/functions].freeze
|
13
6
|
|
14
|
-
require 'sass'
|
15
|
-
|
16
|
-
module Sass
|
17
7
|
def css(filter, rep, content, params)
|
18
8
|
css, = render(filter, rep, content, params)
|
19
9
|
css
|
@@ -27,7 +17,7 @@ module Nanoc::Filters
|
|
27
17
|
private
|
28
18
|
|
29
19
|
def render(filter, rep, content, params = {})
|
30
|
-
importer =
|
20
|
+
importer = Nanoc::Filters::SassCommon::Importer.new(filter)
|
31
21
|
|
32
22
|
options = params.merge(
|
33
23
|
load_paths: [importer, *params[:load_paths]&.reject { |p| p.is_a?(String) && %r{^content/} =~ p }],
|
@@ -41,113 +31,27 @@ module Nanoc::Filters
|
|
41
31
|
css, sourcemap = sourcemap_path ? engine.render_with_sourcemap(sourcemap_path) : engine.render
|
42
32
|
[css, sourcemap&.to_json(css_uri: rep.path, type: rep.path.nil? ? :inline : :auto)]
|
43
33
|
end
|
34
|
+
end
|
44
35
|
|
45
|
-
|
46
|
-
|
47
|
-
attr_reader :filter
|
48
|
-
|
49
|
-
def initialize(filter)
|
50
|
-
@filter = filter
|
51
|
-
super('.')
|
52
|
-
end
|
53
|
-
|
54
|
-
def find_relative(name, base_identifier, options)
|
55
|
-
base_raw_filename = filter.items[base_identifier].raw_filename
|
56
|
-
|
57
|
-
# we can't resolve a relative filename from an in-memory item
|
58
|
-
return unless base_raw_filename
|
59
|
-
|
60
|
-
raw_filename, syntax = ::Sass::Util.destructure(find_real_file(File.dirname(base_raw_filename), name, options))
|
61
|
-
return unless raw_filename
|
62
|
-
|
63
|
-
item = raw_filename_to_item(raw_filename)
|
64
|
-
# it doesn't make sense to import a file, from Nanoc's content if the corresponding item has been deleted
|
65
|
-
raise "unable to map #{raw_filename} to any item" if item.nil?
|
66
|
-
|
67
|
-
filter.depend_on([item])
|
68
|
-
|
69
|
-
options[:syntax] = syntax
|
70
|
-
options[:filename] = item.identifier.to_s
|
71
|
-
options[:importer] = self
|
72
|
-
::Sass::Engine.new(item.raw_content, options)
|
73
|
-
end
|
74
|
-
|
75
|
-
def find(identifier, options)
|
76
|
-
items = filter.items.find_all(identifier)
|
77
|
-
return if items.empty?
|
78
|
-
|
79
|
-
content = if items.size == 1
|
80
|
-
items.first.compiled_content
|
81
|
-
else
|
82
|
-
items.map { |item| %(@import "#{item.identifier}";) }.join("\n")
|
83
|
-
end
|
84
|
-
|
85
|
-
options[:syntax] = :scss
|
86
|
-
options[:filename] = identifier.to_s
|
87
|
-
options[:importer] = self
|
88
|
-
::Sass::Engine.new(content, options)
|
89
|
-
end
|
90
|
-
|
91
|
-
def key(identifier, _options)
|
92
|
-
[self.class.name + ':' + root, identifier.to_s]
|
93
|
-
end
|
94
|
-
|
95
|
-
def public_url(identifier, _sourcemap_directory)
|
96
|
-
path = filter.items[identifier].path
|
97
|
-
return path unless path.nil?
|
98
|
-
|
99
|
-
raw_filename = filter.items[identifier].raw_filename
|
100
|
-
return if raw_filename.nil?
|
101
|
-
|
102
|
-
::Sass::Util.file_uri_from_path(raw_filename)
|
103
|
-
end
|
104
|
-
|
105
|
-
def to_s
|
106
|
-
'Nanoc Sass Importer'
|
107
|
-
end
|
108
|
-
|
109
|
-
def self.raw_filename_to_item_map_for_config(config, items)
|
110
|
-
@raw_filename_to_item_map ||= {}
|
111
|
-
@raw_filename_to_item_map[config.object_id] ||=
|
112
|
-
{}.tap do |map|
|
113
|
-
items.each do |item|
|
114
|
-
if item.raw_filename
|
115
|
-
path = Pathname.new(item.raw_filename).realpath.to_s
|
116
|
-
map[path] = item
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
36
|
+
class SassFilter < Nanoc::Filter
|
37
|
+
identifier :sass
|
121
38
|
|
122
|
-
|
123
|
-
|
39
|
+
include SassCommon
|
40
|
+
requires(*SassCommon::REQUIRES)
|
124
41
|
|
125
|
-
|
126
|
-
|
127
|
-
end
|
42
|
+
def run(content, params = {})
|
43
|
+
css(self, @item_rep, content, params)
|
128
44
|
end
|
129
45
|
end
|
130
46
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
when Array
|
140
|
-
list(result, :comma)
|
141
|
-
when Hash
|
142
|
-
map(result)
|
143
|
-
when nil
|
144
|
-
null
|
145
|
-
when Numeric
|
146
|
-
number(result)
|
147
|
-
else
|
148
|
-
params['unquote'] ? unquoted_string(result) : quoted_string(result)
|
149
|
-
end
|
47
|
+
class SassSourcemapFilter < Nanoc::Filter
|
48
|
+
identifier :sass_sourcemap
|
49
|
+
|
50
|
+
include SassCommon
|
51
|
+
requires(*SassCommon::REQUIRES)
|
52
|
+
|
53
|
+
def run(content, params = {})
|
54
|
+
sourcemap(self, @item_rep, content, params)
|
150
55
|
end
|
151
|
-
declare :nanoc, [:string], var_kwargs: true
|
152
56
|
end
|
153
57
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ::Sass::Script::Functions
|
4
|
+
def nanoc(string, params)
|
5
|
+
assert_type string, :String
|
6
|
+
assert_type params, :Hash
|
7
|
+
result = options[:importer].filter.instance_eval(string.value)
|
8
|
+
case result
|
9
|
+
when TrueClass, FalseClass
|
10
|
+
bool(result)
|
11
|
+
when Array
|
12
|
+
list(result, :comma)
|
13
|
+
when Hash
|
14
|
+
map(result)
|
15
|
+
when nil
|
16
|
+
null
|
17
|
+
when Numeric
|
18
|
+
number(result)
|
19
|
+
else
|
20
|
+
params['unquote'] ? unquoted_string(result) : quoted_string(result)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
declare :nanoc, [:string], var_kwargs: true
|
24
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Nanoc::Filters::SassCommon
|
4
|
+
# @api private
|
5
|
+
class Importer < ::Sass::Importers::Filesystem
|
6
|
+
attr_reader :filter
|
7
|
+
|
8
|
+
def initialize(filter)
|
9
|
+
@filter = filter
|
10
|
+
super('.')
|
11
|
+
end
|
12
|
+
|
13
|
+
def find_relative(name, base_identifier, options)
|
14
|
+
base_raw_filename = filter.items[base_identifier].raw_filename
|
15
|
+
|
16
|
+
# we can't resolve a relative filename from an in-memory item
|
17
|
+
return unless base_raw_filename
|
18
|
+
|
19
|
+
raw_filename, syntax = ::Sass::Util.destructure(find_real_file(File.dirname(base_raw_filename), name, options))
|
20
|
+
return unless raw_filename
|
21
|
+
|
22
|
+
item = raw_filename_to_item(raw_filename)
|
23
|
+
# it doesn't make sense to import a file, from Nanoc's content if the corresponding item has been deleted
|
24
|
+
raise "unable to map #{raw_filename} to any item" if item.nil?
|
25
|
+
|
26
|
+
filter.depend_on([item])
|
27
|
+
|
28
|
+
options[:syntax] = syntax
|
29
|
+
options[:filename] = item.identifier.to_s
|
30
|
+
options[:importer] = self
|
31
|
+
::Sass::Engine.new(item.raw_content, options)
|
32
|
+
end
|
33
|
+
|
34
|
+
def find(identifier, options)
|
35
|
+
items = filter.items.find_all(identifier)
|
36
|
+
return if items.empty?
|
37
|
+
|
38
|
+
content = if items.size == 1
|
39
|
+
items.first.compiled_content
|
40
|
+
else
|
41
|
+
items.map { |item| %(@import "#{item.identifier}";) }.join("\n")
|
42
|
+
end
|
43
|
+
|
44
|
+
options[:syntax] = :scss
|
45
|
+
options[:filename] = identifier.to_s
|
46
|
+
options[:importer] = self
|
47
|
+
::Sass::Engine.new(content, options)
|
48
|
+
end
|
49
|
+
|
50
|
+
def key(identifier, _options)
|
51
|
+
[self.class.name + ':' + root, identifier.to_s]
|
52
|
+
end
|
53
|
+
|
54
|
+
def public_url(identifier, _sourcemap_directory)
|
55
|
+
path = filter.items[identifier].path
|
56
|
+
return path unless path.nil?
|
57
|
+
|
58
|
+
raw_filename = filter.items[identifier].raw_filename
|
59
|
+
return if raw_filename.nil?
|
60
|
+
|
61
|
+
::Sass::Util.file_uri_from_path(raw_filename)
|
62
|
+
end
|
63
|
+
|
64
|
+
def to_s
|
65
|
+
'Nanoc Sass Importer'
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.raw_filename_to_item_map_for_config(config, items)
|
69
|
+
@raw_filename_to_item_map ||= {}
|
70
|
+
@raw_filename_to_item_map[config.object_id] ||=
|
71
|
+
{}.tap do |map|
|
72
|
+
items.each do |item|
|
73
|
+
if item.raw_filename
|
74
|
+
path = Pathname.new(item.raw_filename).realpath.to_s
|
75
|
+
map[path] = item
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def raw_filename_to_item(filename)
|
82
|
+
realpath = Pathname.new(filename).realpath.to_s
|
83
|
+
|
84
|
+
map = self.class.raw_filename_to_item_map_for_config(filter.config, filter.items)
|
85
|
+
map[realpath]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/lib/nanoc/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nanoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.10.
|
4
|
+
version: 4.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Defreyne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -401,6 +401,8 @@ files:
|
|
401
401
|
- lib/nanoc/filters/relativize_paths.rb
|
402
402
|
- lib/nanoc/filters/rubypants.rb
|
403
403
|
- lib/nanoc/filters/sass.rb
|
404
|
+
- lib/nanoc/filters/sass/functions.rb
|
405
|
+
- lib/nanoc/filters/sass/importer.rb
|
404
406
|
- lib/nanoc/filters/slim.rb
|
405
407
|
- lib/nanoc/filters/typogruby.rb
|
406
408
|
- lib/nanoc/filters/uglify_js.rb
|