rack-sassc 0.0.0 → 0.1.0
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.rb +13 -14
- data/lib/rack/sassc/version.rb +1 -1
- data/test/test_rack_sassc.rb +42 -16
- metadata +2 -4
- 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: f98e422e93a40cb46f7ad7239c72c6063c982b19d08de986cde4ee9898c6fd83
|
4
|
+
data.tar.gz: 8cfa07e1fb7fe48f77ca0c4b9e2442cb1ebe440287b2e8264ddb2d47f0edd301
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d06d701db73c95d09620287bd949f6cb1931f1168d32b8f05cca073f6f5689fbf632be552459ec8bc0e82d0f2536c5c2f98f991b0f53ef49a581f98b7ae67726
|
7
|
+
data.tar.gz: 59c1114bda8c9b512c689cde4ed022b3cd710c82dd53385befb042ec7a3f5e6b6de6f60fa7212a14fc106deb93069caa88270ac0b420c95515e950c97fde2a2d
|
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.rb
CHANGED
@@ -10,14 +10,14 @@ 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
|
@@ -25,12 +25,10 @@ module Rack
|
|
25
25
|
@app.call env
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
def filepath dirname, filename, ext
|
33
|
-
::File.join location(dirname), "#{filename}.#{ext}"
|
28
|
+
def filepath filename, type
|
29
|
+
location = @opts[type==:css ? :css_location : :scss_location]
|
30
|
+
ext = type==:scss ? @opts[:syntax] : type
|
31
|
+
::File.join location, "#{filename}.#{ext}"
|
34
32
|
end
|
35
33
|
|
36
34
|
private
|
@@ -44,15 +42,16 @@ module Rack
|
|
44
42
|
end
|
45
43
|
|
46
44
|
def handle_path path_info
|
47
|
-
return unless path_info[/\/#{@opts[:css_dirname]}\/[^\/]+\.css$/]
|
48
45
|
|
49
46
|
filename = ::File.basename path_info, '.*'
|
50
|
-
scss_filepath = filepath(
|
47
|
+
scss_filepath = filepath(filename, :scss)
|
51
48
|
return unless ::File.exist?(scss_filepath)
|
52
49
|
|
50
|
+
css_filepath = filepath(filename, :css)
|
51
|
+
return unless css_filepath[/#{path_info}/]
|
52
|
+
|
53
53
|
scss = ::File.read(scss_filepath)
|
54
54
|
engine = ::SassC::Engine.new(scss, build_engine_opts(filename))
|
55
|
-
css_filepath = filepath(@opts[:css_dirname], filename, :css)
|
56
55
|
|
57
56
|
::File.open(css_filepath, 'w') do |css_file|
|
58
57
|
css_file.write(engine.render)
|
@@ -69,7 +68,7 @@ module Rack
|
|
69
68
|
engine_opts = {
|
70
69
|
style: :compressed,
|
71
70
|
syntax: @opts[:syntax],
|
72
|
-
load_paths: [
|
71
|
+
load_paths: [@opts[:scss_location]],
|
73
72
|
}
|
74
73
|
|
75
74
|
if @opts[:create_map_file]
|
data/lib/rack/sassc/version.rb
CHANGED
data/test/test_rack_sassc.rb
CHANGED
@@ -23,9 +23,15 @@ 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
|
+
Dir.children('other-public/stylesheets').each do |f|
|
27
|
+
::File.delete("other-public/stylesheets/#{f}") unless KEEP_IN_CSS_DIR.include?(f)
|
28
|
+
end
|
26
29
|
if ::File.exist? "public/scss/tmp.scss"
|
27
30
|
::File.delete "public/scss/tmp.scss"
|
28
31
|
end
|
32
|
+
if ::File.exist? "other-public/sassc/tmp.scss"
|
33
|
+
::File.delete "other-public/sassc/tmp.scss"
|
34
|
+
end
|
29
35
|
end
|
30
36
|
|
31
37
|
def app
|
@@ -136,32 +142,38 @@ class TestRackSassC < MiniTest::Test
|
|
136
142
|
assert_css_dir_untouched
|
137
143
|
end
|
138
144
|
|
139
|
-
def
|
140
|
-
local_opts = {
|
145
|
+
def test_css_location_option_is_expanded
|
146
|
+
local_opts = {css_location: 'other-public/stylesheets'}
|
141
147
|
local_app = Rack::SassC.new(inner_app, local_opts)
|
142
|
-
assert_equal ::File.expand_path('other-public'), local_app.opts[:
|
148
|
+
assert_equal ::File.expand_path('other-public/stylesheets'), local_app.opts[:css_location]
|
143
149
|
# Make sure the original opts hash is unchanged
|
144
|
-
assert_equal 'other-public', local_opts[:
|
150
|
+
assert_equal 'other-public/stylesheets', local_opts[:css_location]
|
145
151
|
end
|
146
152
|
|
147
|
-
def
|
148
|
-
local_opts = {
|
153
|
+
def test_scss_location_option_is_expanded
|
154
|
+
local_opts = {scss_location: 'other-public/sassc'}
|
149
155
|
local_app = Rack::SassC.new(inner_app, local_opts)
|
150
|
-
assert_equal ::File.
|
156
|
+
assert_equal ::File.expand_path('other-public/sassc'), local_app.opts[:scss_location]
|
157
|
+
# Make sure the original opts hash is unchanged
|
158
|
+
assert_equal 'other-public/sassc', local_opts[:scss_location]
|
151
159
|
end
|
152
160
|
|
153
|
-
def
|
154
|
-
local_opts = {
|
161
|
+
def test_filepath
|
162
|
+
local_opts = {
|
163
|
+
css_location: 'other-public/stylesheets',
|
164
|
+
scss_location: 'other-public/sassc',
|
165
|
+
syntax: :sass
|
166
|
+
}
|
155
167
|
local_app = Rack::SassC.new(inner_app, local_opts)
|
156
|
-
assert_equal ::File.join(::File.expand_path('
|
168
|
+
assert_equal ::File.join(::File.expand_path('other-public/stylesheets'), 'main.css'), local_app.filepath(:main, :css)
|
169
|
+
assert_equal ::File.join(::File.expand_path('other-public/sassc'), 'main.sass'), local_app.filepath(:main, :scss)
|
157
170
|
end
|
158
171
|
|
159
|
-
def
|
172
|
+
def test_works_with_different_locations_and_syntax
|
160
173
|
@inner_app = inner_app_other
|
161
174
|
@app_options = {
|
162
|
-
|
163
|
-
|
164
|
-
scss_dirname: :sassc,
|
175
|
+
css_location: 'other-public/stylesheets',
|
176
|
+
scss_location: 'other-public/sassc',
|
165
177
|
syntax: :sass
|
166
178
|
}
|
167
179
|
get "/stylesheets/main.css"
|
@@ -172,6 +184,20 @@ class TestRackSassC < MiniTest::Test
|
|
172
184
|
assert_created_in_css_dir "main.css", "main.css.map"
|
173
185
|
end
|
174
186
|
|
187
|
+
def test_works_with_absolute_paths
|
188
|
+
# @inner_app = inner_app_other
|
189
|
+
@app_options = {
|
190
|
+
scss_location: ::File.expand_path('other-public/sassc'),
|
191
|
+
syntax: :sass
|
192
|
+
}
|
193
|
+
get "/css/main.css"
|
194
|
+
assert_equal 200, last_response.status
|
195
|
+
assert_equal 'text/css', last_response.headers['Content-Type']
|
196
|
+
assert last_response.body[/body\{color:blue\}/]
|
197
|
+
assert last_response.body[/sourceMappingURL=main\.css\.map/]
|
198
|
+
assert_created_in_css_dir "main.css", "main.css.map"
|
199
|
+
end
|
200
|
+
|
175
201
|
private
|
176
202
|
|
177
203
|
# This will assert the files were created
|
@@ -179,9 +205,9 @@ class TestRackSassC < MiniTest::Test
|
|
179
205
|
# are not passed as argument. Therefore the list
|
180
206
|
# of files created needs to be exhaustive.
|
181
207
|
def assert_created_in_css_dir *created_files
|
182
|
-
if @app_options.has_key?(:
|
208
|
+
if @app_options.has_key?(:css_location)
|
183
209
|
possible_files = created_files.dup
|
184
|
-
path =
|
210
|
+
path = @app_options[:css_location]
|
185
211
|
else
|
186
212
|
possible_files = KEEP_IN_CSS_DIR + created_files
|
187
213
|
path = 'public/css'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mickael Riga
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -112,8 +112,6 @@ 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/main.css
|
116
|
-
- test/other-public/stylesheets/main.css.map
|
117
115
|
- test/public/css/already.css
|
118
116
|
- test/public/scss/main.scss
|
119
117
|
- test/test_rack_sassc.rb
|