rack-sassc 0.0.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -14
- data/lib/rack/sassc/version.rb +1 -1
- data/lib/rack/sassc.rb +17 -14
- data/rack-sassc.gemspec +2 -2
- data/test/other-public/stylesheets/already.css +1 -0
- data/test/test_rack_sassc.rb +45 -17
- metadata +13 -14
- data/test/other-public/stylesheets/main.css +0 -3
- data/test/other-public/stylesheets/main.css.map +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59d53b05df35a17dd7d243d6a3e917b55ced842e9d3ff235ee799bb0315dba55
|
4
|
+
data.tar.gz: fb4b77417231cbda166a2666ee61a6c000ee8fab4d8fb1c800d8905896f396df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7adc86dfe36ffa21510368f3d480d79d9bdfac8da4ef4a9b97dc56598dce2d1a479c523ab1737f999723a384d30bf3dbdd9fb9ab279a6d2f0ab346c66572ec08
|
7
|
+
data.tar.gz: fa8ad12fadebac9e501d92d30d97a052939a9eb29265cdb4f9061e73360c31464225c19d62565a1b6b1ce505594a71ef89d2b8ea0c8a0d9edd9430f27d3a1964
|
data/README.md
CHANGED
@@ -11,10 +11,6 @@ The files are processed each time they are requested. Since by default it does
|
|
11
11
|
it only when not in production, the speed penalty is kind of acceptable. But I
|
12
12
|
intend to improve it and use modification time.
|
13
13
|
|
14
|
-
The location of the public directory and directory names for CSS and SCSS are
|
15
|
-
editable, but both are assumed to be directly placed inside the public
|
16
|
-
directory.
|
17
|
-
|
18
14
|
The files cannot be nested, they are assumed to be directly inside the SCSS
|
19
15
|
directory, and the generated files are therefore created directly inside the CSS
|
20
16
|
directory.
|
@@ -62,10 +58,9 @@ require 'rack/sassc'
|
|
62
58
|
|
63
59
|
use Rack::SassC, {
|
64
60
|
check: ENV['RACK_ENV'] != 'production',
|
65
|
-
public_location: 'public',
|
66
61
|
syntax: :scss,
|
67
|
-
|
68
|
-
|
62
|
+
css_location: 'public/css',
|
63
|
+
scss_location: 'public/scss',
|
69
64
|
create_map_file: true,
|
70
65
|
}
|
71
66
|
```
|
@@ -77,11 +72,8 @@ equivalent to not having the middleware at all. By default it is `true` if the
|
|
77
72
|
rack environment is NOT `production`. The value of `check` can also be a Proc
|
78
73
|
which receives the `env` on each request.
|
79
74
|
|
80
|
-
`
|
81
|
-
|
82
|
-
|
83
|
-
`scss_dirname` and `css_dirname` are just the name of the directories in which
|
84
|
-
we search for template files and we generate css/map files.
|
75
|
+
`scss_location` and `css_location` are just the name of the directories in which
|
76
|
+
we search for template files and we generate css/map files. These paths are expanded.
|
85
77
|
|
86
78
|
`syntax` is `:scss` or `:sass`. It is used for the engine, but also for the
|
87
79
|
extension of template files, which means they have to match.
|
@@ -105,7 +97,7 @@ The default options for the engine are the following:
|
|
105
97
|
{
|
106
98
|
style: :compressed,
|
107
99
|
syntax: @opts[:syntax],
|
108
|
-
load_paths: [
|
100
|
+
load_paths: [@opts[:scss_location]],
|
109
101
|
}
|
110
102
|
```
|
111
103
|
|
@@ -115,12 +107,19 @@ Or this when no map file is to be created:
|
|
115
107
|
{
|
116
108
|
style: :compressed,
|
117
109
|
syntax: @opts[:syntax],
|
118
|
-
load_paths: [
|
110
|
+
load_paths: [@opts[:scss_location]],
|
119
111
|
source_map_file: "#{filename}.css.map",
|
120
112
|
source_map_contents: true,
|
121
113
|
}
|
122
114
|
```
|
123
115
|
|
116
|
+
Changelog
|
117
|
+
---------
|
118
|
+
|
119
|
+
**0.0.0** All new
|
120
|
+
|
121
|
+
**0.1.0** `:public_location`, `:css_dirname` and `:scss_dirname` 3 options where all replaced by 2 options: `:css_location` and `:scss_location`. Meaning the locations can be outside of the public directory (for scss/sass). They also can be absolute or will be expanded from current directory. The behaviour of default options remains unchanged: css is assumed to be in `'public/css'` and scss in `'public/scss'`. The update is based on a [conversation about a pull request](https://github.com/mig-hub/rack-sassc/pull/1) by [@straight-shoota](https://github.com/straight-shoota).
|
122
|
+
|
124
123
|
Alternatives
|
125
124
|
------------
|
126
125
|
|
data/lib/rack/sassc/version.rb
CHANGED
data/lib/rack/sassc.rb
CHANGED
@@ -10,27 +10,29 @@ module Rack
|
|
10
10
|
|
11
11
|
@opts = {
|
12
12
|
check: ENV['RACK_ENV'] != 'production',
|
13
|
-
public_location: 'public',
|
14
13
|
syntax: :scss,
|
15
|
-
|
16
|
-
|
14
|
+
css_location: 'public/css',
|
15
|
+
scss_location: 'public/scss',
|
17
16
|
create_map_file: true,
|
18
17
|
}.merge(opts)
|
19
18
|
|
20
|
-
@opts[:
|
19
|
+
@opts[:css_location] = ::File.expand_path @opts[:css_location]
|
20
|
+
@opts[:scss_location] = ::File.expand_path @opts[:scss_location]
|
21
21
|
end
|
22
22
|
|
23
23
|
def call env
|
24
|
-
|
25
|
-
@app.call env
|
24
|
+
dup._call env
|
26
25
|
end
|
27
26
|
|
28
|
-
def
|
29
|
-
|
27
|
+
def _call env
|
28
|
+
handle_path(env['PATH_INFO']) if must_check?(env)
|
29
|
+
@app.call env
|
30
30
|
end
|
31
31
|
|
32
|
-
def filepath
|
33
|
-
|
32
|
+
def filepath filename, type
|
33
|
+
location = @opts[type==:css ? :css_location : :scss_location]
|
34
|
+
ext = type==:scss ? @opts[:syntax] : type
|
35
|
+
::File.join location, "#{filename}.#{ext}"
|
34
36
|
end
|
35
37
|
|
36
38
|
private
|
@@ -44,15 +46,16 @@ module Rack
|
|
44
46
|
end
|
45
47
|
|
46
48
|
def handle_path path_info
|
47
|
-
return unless path_info[/\/#{@opts[:css_dirname]}\/[^\/]+\.css$/]
|
48
49
|
|
49
50
|
filename = ::File.basename path_info, '.*'
|
50
|
-
scss_filepath = filepath(
|
51
|
+
scss_filepath = filepath(filename, :scss)
|
51
52
|
return unless ::File.exist?(scss_filepath)
|
52
53
|
|
54
|
+
css_filepath = filepath(filename, :css)
|
55
|
+
return unless css_filepath[/#{path_info}/]
|
56
|
+
|
53
57
|
scss = ::File.read(scss_filepath)
|
54
58
|
engine = ::SassC::Engine.new(scss, build_engine_opts(filename))
|
55
|
-
css_filepath = filepath(@opts[:css_dirname], filename, :css)
|
56
59
|
|
57
60
|
::File.open(css_filepath, 'w') do |css_file|
|
58
61
|
css_file.write(engine.render)
|
@@ -69,7 +72,7 @@ module Rack
|
|
69
72
|
engine_opts = {
|
70
73
|
style: :compressed,
|
71
74
|
syntax: @opts[:syntax],
|
72
|
-
load_paths: [
|
75
|
+
load_paths: [@opts[:scss_location]],
|
73
76
|
}
|
74
77
|
|
75
78
|
if @opts[:create_map_file]
|
data/rack-sassc.gemspec
CHANGED
@@ -12,10 +12,10 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.license = 'MIT'
|
13
13
|
s.require_paths = ["lib"]
|
14
14
|
|
15
|
-
s.add_dependency 'rack', '
|
15
|
+
s.add_dependency 'rack', '~> 2.0'
|
16
16
|
s.add_dependency 'sassc', '~> 2.0'
|
17
17
|
s.add_development_dependency 'minitest', '~> 5.8'
|
18
|
-
s.add_development_dependency 'rack-test', '~>
|
18
|
+
s.add_development_dependency 'rack-test', '~> 2'
|
19
19
|
s.add_development_dependency "rake"
|
20
20
|
s.add_development_dependency "bundler"
|
21
21
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
.already{color:yellow}
|
data/test/test_rack_sassc.rb
CHANGED
@@ -23,9 +23,17 @@ class TestRackSassC < MiniTest::Test
|
|
23
23
|
Dir.children('public/css').each do |f|
|
24
24
|
::File.delete("public/css/#{f}") unless KEEP_IN_CSS_DIR.include?(f)
|
25
25
|
end
|
26
|
+
if ::File.directory?( 'other-public/stylesheets' )
|
27
|
+
Dir.children('other-public/stylesheets').each do |f|
|
28
|
+
::File.delete("other-public/stylesheets/#{f}") unless KEEP_IN_CSS_DIR.include?(f)
|
29
|
+
end
|
30
|
+
end
|
26
31
|
if ::File.exist? "public/scss/tmp.scss"
|
27
32
|
::File.delete "public/scss/tmp.scss"
|
28
33
|
end
|
34
|
+
if ::File.exist? "other-public/sassc/tmp.scss"
|
35
|
+
::File.delete "other-public/sassc/tmp.scss"
|
36
|
+
end
|
29
37
|
end
|
30
38
|
|
31
39
|
def app
|
@@ -136,32 +144,38 @@ class TestRackSassC < MiniTest::Test
|
|
136
144
|
assert_css_dir_untouched
|
137
145
|
end
|
138
146
|
|
139
|
-
def
|
140
|
-
local_opts = {
|
147
|
+
def test_css_location_option_is_expanded
|
148
|
+
local_opts = {css_location: 'other-public/stylesheets'}
|
141
149
|
local_app = Rack::SassC.new(inner_app, local_opts)
|
142
|
-
assert_equal ::File.expand_path('other-public'), local_app.opts[:
|
150
|
+
assert_equal ::File.expand_path('other-public/stylesheets'), local_app.opts[:css_location]
|
143
151
|
# Make sure the original opts hash is unchanged
|
144
|
-
assert_equal 'other-public', local_opts[:
|
152
|
+
assert_equal 'other-public/stylesheets', local_opts[:css_location]
|
145
153
|
end
|
146
154
|
|
147
|
-
def
|
148
|
-
local_opts = {
|
155
|
+
def test_scss_location_option_is_expanded
|
156
|
+
local_opts = {scss_location: 'other-public/sassc'}
|
149
157
|
local_app = Rack::SassC.new(inner_app, local_opts)
|
150
|
-
assert_equal ::File.
|
158
|
+
assert_equal ::File.expand_path('other-public/sassc'), local_app.opts[:scss_location]
|
159
|
+
# Make sure the original opts hash is unchanged
|
160
|
+
assert_equal 'other-public/sassc', local_opts[:scss_location]
|
151
161
|
end
|
152
162
|
|
153
|
-
def
|
154
|
-
local_opts = {
|
163
|
+
def test_filepath
|
164
|
+
local_opts = {
|
165
|
+
css_location: 'other-public/stylesheets',
|
166
|
+
scss_location: 'other-public/sassc',
|
167
|
+
syntax: :sass
|
168
|
+
}
|
155
169
|
local_app = Rack::SassC.new(inner_app, local_opts)
|
156
|
-
assert_equal ::File.join(::File.expand_path('
|
170
|
+
assert_equal ::File.join(::File.expand_path('other-public/stylesheets'), 'main.css'), local_app.filepath(:main, :css)
|
171
|
+
assert_equal ::File.join(::File.expand_path('other-public/sassc'), 'main.sass'), local_app.filepath(:main, :scss)
|
157
172
|
end
|
158
173
|
|
159
|
-
def
|
174
|
+
def test_works_with_different_locations_and_syntax
|
160
175
|
@inner_app = inner_app_other
|
161
176
|
@app_options = {
|
162
|
-
|
163
|
-
|
164
|
-
scss_dirname: :sassc,
|
177
|
+
css_location: 'other-public/stylesheets',
|
178
|
+
scss_location: 'other-public/sassc',
|
165
179
|
syntax: :sass
|
166
180
|
}
|
167
181
|
get "/stylesheets/main.css"
|
@@ -172,6 +186,20 @@ class TestRackSassC < MiniTest::Test
|
|
172
186
|
assert_created_in_css_dir "main.css", "main.css.map"
|
173
187
|
end
|
174
188
|
|
189
|
+
def test_works_with_absolute_paths
|
190
|
+
# @inner_app = inner_app_other
|
191
|
+
@app_options = {
|
192
|
+
scss_location: ::File.expand_path('other-public/sassc'),
|
193
|
+
syntax: :sass
|
194
|
+
}
|
195
|
+
get "/css/main.css"
|
196
|
+
assert_equal 200, last_response.status
|
197
|
+
assert_equal 'text/css', last_response.headers['Content-Type']
|
198
|
+
assert last_response.body[/body\{color:blue\}/]
|
199
|
+
assert last_response.body[/sourceMappingURL=main\.css\.map/]
|
200
|
+
assert_created_in_css_dir "main.css", "main.css.map"
|
201
|
+
end
|
202
|
+
|
175
203
|
private
|
176
204
|
|
177
205
|
# This will assert the files were created
|
@@ -179,9 +207,9 @@ class TestRackSassC < MiniTest::Test
|
|
179
207
|
# are not passed as argument. Therefore the list
|
180
208
|
# of files created needs to be exhaustive.
|
181
209
|
def assert_created_in_css_dir *created_files
|
182
|
-
if @app_options.has_key?(:
|
183
|
-
possible_files = created_files.dup
|
184
|
-
path =
|
210
|
+
if @app_options.has_key?(:css_location)
|
211
|
+
possible_files = KEEP_IN_CSS_DIR + created_files.dup
|
212
|
+
path = @app_options[:css_location]
|
185
213
|
else
|
186
214
|
possible_files = KEEP_IN_CSS_DIR + created_files
|
187
215
|
path = 'public/css'
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-sassc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mickael Riga
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
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: '
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sassc
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '2'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '2'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,8 +112,7 @@ files:
|
|
112
112
|
- lib/rack/sassc/version.rb
|
113
113
|
- rack-sassc.gemspec
|
114
114
|
- test/other-public/sassc/main.sass
|
115
|
-
- test/other-public/stylesheets/
|
116
|
-
- test/other-public/stylesheets/main.css.map
|
115
|
+
- test/other-public/stylesheets/already.css
|
117
116
|
- test/public/css/already.css
|
118
117
|
- test/public/scss/main.scss
|
119
118
|
- test/test_rack_sassc.rb
|
@@ -121,7 +120,7 @@ homepage: https://github.com/mig-hub/rack-sassc
|
|
121
120
|
licenses:
|
122
121
|
- MIT
|
123
122
|
metadata: {}
|
124
|
-
post_install_message:
|
123
|
+
post_install_message:
|
125
124
|
rdoc_options: []
|
126
125
|
require_paths:
|
127
126
|
- lib
|
@@ -136,8 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
135
|
- !ruby/object:Gem::Version
|
137
136
|
version: '0'
|
138
137
|
requirements: []
|
139
|
-
rubygems_version: 3.
|
140
|
-
signing_key:
|
138
|
+
rubygems_version: 3.3.7
|
139
|
+
signing_key:
|
141
140
|
specification_version: 4
|
142
141
|
summary: Rack middleware for SassC
|
143
142
|
test_files: []
|