Skip to content

Commit

Permalink
Remove development dependency on sassc
Browse files Browse the repository at this point in the history
Nothing in Roda requires sass/sassc.  It was used for testing the
assets plugin and a few other plugins, but there is no need to use
it, the testing can be done with other tilt template engines.

sass went end of life over 5 years ago. sassc's last release and
commit were over 4 years ago.  The recommended replacement library is
sass-embedded, but that depends on google-protobuf, and I'd like
to remove dependencies and not add them.
  • Loading branch information
jeremyevans committed Jun 17, 2024
1 parent f73ba9b commit 37a6f7d
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 81 deletions.
6 changes: 0 additions & 6 deletions .ci.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ else
gem 'json'
end

if RUBY_VERSION < '2.2.0'
gem 'sass', '< 3.5'
else
gem 'sassc'
end

case RUBY_VERSION[0, 3]
when '1.9', '2.0'
gem 'rack', '<1.6'
Expand Down
1 change: 0 additions & 1 deletion roda.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Gem::Specification.new do |s|
s.add_development_dependency "tilt"
s.add_development_dependency "erubi"
s.add_development_dependency "rack_csrf"
s.add_development_dependency "sassc"
s.add_development_dependency "json"
s.add_development_dependency "mail"
end
File renamed without changes.
1 change: 1 addition & 0 deletions spec/assets/css/app.str
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
body { color: red; }
1 change: 0 additions & 1 deletion spec/assets/css/import.scss

This file was deleted.

1 change: 1 addition & 0 deletions spec/assets/css/import.str
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#{File.binread(File.join(File.dirname(__FILE__), 'importdep.str'))}
14 changes: 4 additions & 10 deletions spec/plugin/assets_preloading_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,18 @@
run_tests = true
begin
begin
require 'tilt/sass'
require 'tilt'
rescue LoadError
begin
for lib in %w'tilt sass'
require lib
end
rescue LoadError
warn "#{lib} not installed, skipping assets_preloading plugin test"
run_tests = false
end
warn "tilt not installed, skipping assets_preloading plugin test"
run_tests = false
end
end

describe "assets_preloading plugin" do
before do
app(:bare) do
plugin :assets, {
:css => ['app.scss'],
:css => ['app.str'],
:js => { :head => ['app.js'] },
:path => 'spec/assets',
:public => 'spec',
Expand Down
82 changes: 38 additions & 44 deletions spec/plugin/assets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,18 @@
run_tests = true
begin
begin
require 'tilt/sass'
require 'tilt'
rescue LoadError
begin
for lib in %w'tilt sass'
require lib
end
rescue LoadError
warn "#{lib} not installed, skipping assets plugin test"
run_tests = false
end
warn "tilt not installed, skipping assets plugin test"
run_tests = false
end
end

if run_tests
pid_dir = "spec/pid-#{$$}"
assets_dir = File.join(pid_dir, "assets")
metadata_file = File.expand_path(File.join(assets_dir, 'precompiled.json'))
importdep_file = File.expand_path(File.join(assets_dir, 'css/importdep.scss'))
importdep_file = File.expand_path(File.join(assets_dir, 'css/importdep.str'))
js_file = File.expand_path(File.join(assets_dir, 'js/head/app.js'))
css_file = File.expand_path(File.join(assets_dir, 'css/no_access.css'))
describe 'assets plugin' do
Expand All @@ -36,7 +30,7 @@
before do
app(:bare) do
plugin :assets,
:css => ['app.scss', 'raw.css'],
:css => ['app.str', 'raw.css'],
:js => { :head => ['app.js'] },
:path => assets_dir,
:public => pid_dir,
Expand Down Expand Up @@ -162,7 +156,7 @@ def gunzip(body)

it 'assets_paths should return arrays of source paths' do
html = body('/paths_test')
html.scan('css:Array:2:/assets/css/app.scss,/assets/css/raw.css').length.must_equal 1
html.scan('css:Array:2:/assets/css/app.str,/assets/css/raw.css').length.must_equal 1
html.scan('js:Array:1:/assets/js/head/app.js').length.must_equal 1
html.scan('empty:Array:0').length.must_equal 1
end
Expand All @@ -181,22 +175,22 @@ def gunzip(body)
app.plugin :assets, :relative_paths=>true

html = body('/paths_test')
html.scan('css:Array:2:./assets/css/app.scss,./assets/css/raw.css').length.must_equal 1
html.scan('css:Array:2:./assets/css/app.str,./assets/css/raw.css').length.must_equal 1
html.scan('js:Array:1:./assets/js/head/app.js').length.must_equal 1
html.scan('empty:Array:0').length.must_equal 1

html = body('/paths_test/foo')
html.scan('css:Array:2:../assets/css/app.scss,../assets/css/raw.css').length.must_equal 1
html.scan('css:Array:2:../assets/css/app.str,../assets/css/raw.css').length.must_equal 1
html.scan('js:Array:1:../assets/js/head/app.js').length.must_equal 1
html.scan('empty:Array:0').length.must_equal 1

html = body('/paths_test/foo/')
html.scan('css:Array:2:../../assets/css/app.scss,../../assets/css/raw.css').length.must_equal 1
html.scan('css:Array:2:../../assets/css/app.str,../../assets/css/raw.css').length.must_equal 1
html.scan('js:Array:1:../../assets/js/head/app.js').length.must_equal 1
html.scan('empty:Array:0').length.must_equal 1

html = body('/paths_test/foo/bar')
html.scan('css:Array:2:../../assets/css/app.scss,../../assets/css/raw.css').length.must_equal 1
html.scan('css:Array:2:../../assets/css/app.str,../../assets/css/raw.css').length.must_equal 1
html.scan('js:Array:1:../../assets/js/head/app.js').length.must_equal 1
html.scan('empty:Array:0').length.must_equal 1
end
Expand Down Expand Up @@ -226,7 +220,7 @@ def gunzip(body)
it 'should handle rendering assets, linking to them, and accepting requests for them when not compiling' do
html = body('/test')
html.scan(/<link/).length.must_equal 2
html =~ %r{href="(/assets/css/app\.scss)"}
html =~ %r{href="(/assets/css/app\.str)"}
css = body($1)
html =~ %r{href="(/assets/css/raw\.css)"}
css2 = body($1)
Expand All @@ -242,7 +236,7 @@ def gunzip(body)
app.plugin :assets, :timestamp_paths=>true
html = body('/test')
html.scan(/<link/).length.must_equal 2
html =~ %r{href="(/assets/css/\d+/app\.scss)"}
html =~ %r{href="(/assets/css/\d+/app\.str)"}
css = body($1)
html =~ %r{href="(/assets/css/\d+/raw\.css)"}
css2 = body($1)
Expand All @@ -258,7 +252,7 @@ def gunzip(body)
app.plugin :assets, :timestamp_paths=>'-'
html = body('/test')
html.scan(/<link/).length.must_equal 2
html =~ %r{href="(/assets/css/\d+-app\.scss)"}
html =~ %r{href="(/assets/css/\d+-app\.str)"}
css = body($1)
html =~ %r{href="(/assets/css/\d+-raw\.css)"}
css2 = body($1)
Expand All @@ -272,9 +266,9 @@ def gunzip(body)

it 'should not handle non-GET requests for asset rouets' do
html = body('/test')
html =~ %r{href="(/assets/css/app\.scss)"}
html =~ %r{href="(/assets/css/app\.str)"}
html.scan(/<link/).length.must_equal 2
html =~ %r{href="(/assets/css/app\.scss)"}
html =~ %r{href="(/assets/css/app\.str)"}
status($1, 'REQUEST_METHOD'=>'POST').must_equal 404
html =~ %r{href="(/assets/css/raw\.css)"}
status($1, 'REQUEST_METHOD'=>'POST').must_equal 404
Expand All @@ -287,7 +281,7 @@ def gunzip(body)
app.plugin :assets, :early_hints=>true
eh = []
html = body('/test', 'rack.early_hints'=>proc{|h| eh << h})
css_eh = ["</assets/css/app.scss>; rel=preload; as=style", "</assets/css/raw.css>; rel=preload; as=style"]
css_eh = ["</assets/css/app.str>; rel=preload; as=style", "</assets/css/raw.css>; rel=preload; as=style"]
js_eh = ["</assets/js/head/app.js>; rel=preload; as=script"]
if Rack.release < '3'
css_eh = css_eh.join("\n")
Expand All @@ -298,7 +292,7 @@ def gunzip(body)
{Roda::RodaResponseHeaders::LINK=>js_eh}
]
html.scan(/<link/).length.must_equal 2
html =~ %r{href="(/assets/css/app\.scss)"}
html =~ %r{href="(/assets/css/app\.str)"}
css = body($1)
html =~ %r{href="(/assets/css/raw\.css)"}
css2 = body($1)
Expand All @@ -315,7 +309,7 @@ def gunzip(body)
app.plugin :assets
html = body('/test', 'SCRIPT_NAME'=>'/foo')
html.scan(/<link/).length.must_equal 2
html =~ %r{href="/foo(/assets/css/app\.scss)"}
html =~ %r{href="/foo(/assets/css/app\.str)"}
css = body($1)
html =~ %r{href="/foo(/assets/css/raw\.css)"}
css2 = body($1)
Expand All @@ -332,21 +326,21 @@ def gunzip(body)
:js_route=>'foo', :css_route=>'bar', :add_suffix=>true, :css_opts=>{:style=>:compressed}
html = body('/test')
html.scan(/<link/).length.must_equal 2
html =~ %r{href="(/a/bar/app\.scss.css)"}
html =~ %r{href="(/a/bar/app\.str.css)"}
css = body($1)
html =~ %r{href="(/a/bar/raw\.css.css)"}
css2 = body($1)
html.scan(/<script/).length.must_equal 1
html =~ %r{src="(/a/foo/head/app\.js.js)"}
js = body($1)
css.must_match(/color:red\}/)
css.must_match(/color: red;/)
css2.must_match(/color: blue;/)
js.must_include('console.log')
end

it 'should handle rendering assets, linking to them, and accepting requests for them when not compiling with a multi-level hash' do
app.plugin :assets, :path=>pid_dir, :js_dir=>nil, :css_dir=>nil, :prefix=>nil,
:css=>{:assets=>{:css=>%w'app.scss raw.css'}}, :js=>{:assets=>{:js=>{:head=>'app.js'}}}
:css=>{:assets=>{:css=>%w'app.str raw.css'}}, :js=>{:assets=>{:js=>{:head=>'app.js'}}}
app.route do |r|
r.assets
r.is 'test' do
Expand All @@ -355,7 +349,7 @@ def gunzip(body)
end
html = body('/test')
html.scan(/<link/).length.must_equal 2
html =~ %r{href="(/assets/css/app\.scss)"}
html =~ %r{href="(/assets/css/app\.str)"}
css = body($1)
html =~ %r{href="(/assets/css/raw\.css)"}
css2 = body($1)
Expand All @@ -369,7 +363,7 @@ def gunzip(body)

it 'should handle :group_subdirs => false' do
app.plugin :assets, :path=>pid_dir, :js_dir=>nil, :css_dir=>nil, :prefix=>nil, :group_subdirs=>false,
:css=>{:assets=>{:css=>%w'assets/css/app.scss assets/css/raw.css'}}, :js=>{:assets=>{:js=>{:head=>'assets/js/head/app.js'}}}
:css=>{:assets=>{:css=>%w'assets/css/app.str assets/css/raw.css'}}, :js=>{:assets=>{:js=>{:head=>'assets/js/head/app.js'}}}
app.route do |r|
r.assets
r.is 'test' do
Expand All @@ -378,7 +372,7 @@ def gunzip(body)
end
html = body('/test')
html.scan(/<link/).length.must_equal 2
html =~ %r{href="(/assets/css/app\.scss)"}
html =~ %r{href="(/assets/css/app\.str)"}
css = body($1)
html =~ %r{href="(/assets/css/raw\.css)"}
css2 = body($1)
Expand Down Expand Up @@ -606,7 +600,7 @@ def gunzip(body)

it 'should handle rendering assets, linking to them, and accepting requests for them when not compiling with a multi-level hash' do
app.plugin :assets, :path=>pid_dir, :js_dir=>nil, :css_dir=>nil, :compiled_js_dir=>nil, :compiled_css_dir=>nil,
:css=>{:assets=>{:css=>%w'app.scss raw.css'}}, :js=>{:assets=>{:js=>{:head=>'app.js'}}}
:css=>{:assets=>{:css=>%w'app.str raw.css'}}, :js=>{:assets=>{:js=>{:head=>'app.js'}}}
app.compile_assets
app.route do |r|
r.assets
Expand All @@ -629,7 +623,7 @@ def gunzip(body)
it 'should handle rendering assets, linking to them, and accepting requests for them when not compiling with a multi-level hash when :add_script_name app option is used' do
app.opts[:add_script_name] = true
app.plugin :assets, :path=>pid_dir, :js_dir=>nil, :css_dir=>nil, :compiled_js_dir=>nil, :compiled_css_dir=>nil,
:css=>{:assets=>{:css=>%w'app.scss raw.css'}}, :js=>{:assets=>{:js=>{:head=>'app.js'}}}
:css=>{:assets=>{:css=>%w'app.str raw.css'}}, :js=>{:assets=>{:js=>{:head=>'app.js'}}}
app.compile_assets
app.route do |r|
r.assets
Expand All @@ -651,7 +645,7 @@ def gunzip(body)

it 'should handle :group_subdirs => false when compiling' do
app.plugin :assets, :path=>pid_dir, :js_dir=>nil, :css_dir=>nil, :compiled_js_dir=>nil, :compiled_css_dir=>nil, :group_subdirs=>false,
:css=>{:assets=>{:css=>%w'assets/css/app.scss assets/css/raw.css'}}, :js=>{:assets=>{:js=>{:head=>'assets/js/head/app.js'}}}
:css=>{:assets=>{:css=>%w'assets/css/app.str assets/css/raw.css'}}, :js=>{:assets=>{:js=>{:head=>'assets/js/head/app.js'}}}
app.compile_assets
app.route do |r|
r.assets
Expand Down Expand Up @@ -784,22 +778,22 @@ def gunzip(body)
end

it 'requests for assets should include modifications to content of dependencies' do
File.open(File.join(assets_dir, 'css/importdep.scss'), 'wb'){|f| f.write('body{color:blue}')}
app.plugin :assets, :css=>['import.scss'],
:dependencies=>{File.join(assets_dir, 'css/import.scss')=>File.join(assets_dir, 'css/importdep.scss')}
File.open(File.join(assets_dir, 'css/importdep.str'), 'wb'){|f| f.write('body{color: blue;}')}
app.plugin :assets, :css=>['import.str'],
:dependencies=>{File.join(assets_dir, 'css/import.str')=>File.join(assets_dir, 'css/importdep.str')}
app.plugin :render, :cache=>false
3.times do
body('/assets/css/import.scss').must_include('color: blue;')
body('/assets/css/import.str').must_include('color: blue;')
end
File.open(File.join(assets_dir, 'css/importdep.scss'), 'wb'){|f| f.write('body{color:red}')}
File.utime(Time.now+2, Time.now+4, File.join(assets_dir, 'css/importdep.scss'))
File.open(File.join(assets_dir, 'css/importdep.str'), 'wb'){|f| f.write('body{color: red;}')}
File.utime(Time.now+2, Time.now+4, File.join(assets_dir, 'css/importdep.str'))
3.times do
body('/assets/css/import.scss').must_include('color: red;')
body('/assets/css/import.str').must_include('color: red;')
end
end

it 'should do a terminal match for assets' do
status('/assets/css/app.scss/foo').must_equal 404
status('/assets/css/app.str/foo').must_equal 404
end

it 'should only allow files that you specify' do
Expand Down Expand Up @@ -828,7 +822,7 @@ def gunzip(body)

app.plugin :assets, :path=>pid_dir, :js_dir=>nil, :css_dir=>nil, :prefix=>nil,
:postprocessor=>postprocessor,
:css=>{:assets=>{:css=>%w'app.scss'}}
:css=>{:assets=>{:css=>%w'app.str'}}
app.route do |r|
r.assets
r.is 'test' do
Expand All @@ -837,9 +831,9 @@ def gunzip(body)
end
html = body('/test')
html.scan(/<link/).length.must_equal 1
html =~ %r{href="(/assets/css/app\.scss)"}
html =~ %r{href="(/assets/css/app\.str)"}
css = body($1)
css.must_match(/app\.scss/)
css.must_match(/app\.str/)
css.must_match(/type=css/)
css.must_match(/tc=Symbol/)
css.must_match(/font: red;/)
Expand Down
10 changes: 5 additions & 5 deletions spec/plugin/precompile_templates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,22 @@
end

begin
require 'tilt/sass'
require 'tilt/plain'
rescue LoadError
warn "tilt or sass not installed, skipping precompiled_templates plugin sass test"
warn "tilt/plain not installed, skipping precompiled_templates plugin test"
else
describe "precompile_templates plugin" do
it "adds support for template precompilation for tilt template types that do not support precompilation" do
app(:bare) do
plugin :render, :views=>'spec/views'
plugin :precompile_templates
route do |r|
render(:path=>File.expand_path('spec/assets/css/app.scss'), :template_opts=>{:cache=>false})
render(:path=>File.expand_path('spec/assets/css/app.html'), :template_opts=>{:cache=>false})
end
end
key = [File.expand_path("spec/assets/css/app.scss"), nil, nil, {:cache=>false}, nil]
key = [File.expand_path("spec/assets/css/app.html"), nil, nil, {:cache=>false}, nil]
app.render_opts[:cache][key].must_be_nil
app.precompile_templates(:path=>File.expand_path('spec/assets/css/app.scss'), :template_opts=>{:cache=>false})
app.precompile_templates(:path=>File.expand_path('spec/assets/css/app.html'), :template_opts=>{:cache=>false})
app.render_opts[:cache][key].wont_be_nil
app.freeze_template_caches!
body.must_match(/color: red;/)
Expand Down
Loading

0 comments on commit 37a6f7d

Please sign in to comment.