Skip to content

Commit eed0a47

Browse files
Use SCSS for development
1 parent 7244b94 commit eed0a47

File tree

7 files changed

+52
-6
lines changed

7 files changed

+52
-6
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@
99

1010
/gemfiles/*.gemfile.lock
1111
/gemfiles/.bundle
12+
13+
14+
# No CSS is committed. In development, the SCSS is used. The CSS is compiled when building a gem release.
15+
*.css

Rakefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require "bundler/gem_tasks"
22
require "rspec/core/rake_task"
3+
require "better_errors/error_page_style"
34

45
RSpec::Core::RakeTask.new(:test)
56
task :default => :test
@@ -36,3 +37,13 @@ namespace :test do
3637
with_each_gemfile { sh "bundle exec rspec" rescue nil }
3738
end
3839
end
40+
41+
namespace :style do
42+
desc "Build main.css from the SASS sources"
43+
task :build do
44+
css = BetterErrors::ErrorPageStyle.compiled_style(true)
45+
File.open(File.expand_path("lib/better_errors/templates/main.css", File.dirname(__FILE__)), "w") do |f|
46+
f.write(css)
47+
end
48+
end
49+
end

better_errors.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
1313
s.license = "MIT"
1414

1515
s.files = `git ls-files -z`.split("\x0").reject do |f|
16-
f.match(%r{^((test|spec|features|feature-screenshots)/|Rakefile)})
1716
end
17+
f.match(%r{^((test|spec|features|feature-screenshots)/|Rakefile)|\.scss$})
1818

1919
s.require_paths = ["lib"]
2020

@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
2525
s.add_development_dependency "rspec-html-matchers"
2626
s.add_development_dependency "rspec-its"
2727
s.add_development_dependency "yard"
28+
s.add_development_dependency "sassc"
2829
# kramdown 2.1 requires Ruby 2.3+
2930
s.add_development_dependency "kramdown", (RUBY_VERSION < '2.3' ? '< 2.0.0' : '> 2.0.0')
3031
# simplecov and coveralls must not be included here. See the Gemfiles instead.

lib/better_errors/error_page.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require "cgi"
22
require "json"
33
require "securerandom"
4+
require "better_errors/error_page_style"
45

56
module BetterErrors
67
# @private
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require "sassc"
2+
3+
module BetterErrors
4+
# @private
5+
module ErrorPageStyle
6+
def self.compiled_style(for_deployment = false)
7+
style_dir = File.expand_path("style", File.dirname(__FILE__))
8+
style_file = "#{style_dir}/main.scss"
9+
10+
engine = SassC::Engine.new(
11+
File.read(style_file),
12+
filename: style_file,
13+
style: for_deployment ? :compressed : :expanded,
14+
line_comments: !for_deployment,
15+
load_paths: [style_dir],
16+
)
17+
engine.render
18+
end
19+
20+
def self.style_tag
21+
style_file = File.expand_path("templates/main.css", File.dirname(__FILE__))
22+
css = if File.exist?(style_file)
23+
File.open(style_file).read
24+
else
25+
compiled_style(false)
26+
end
27+
"<style type='text/css'>\n#{css}\n</style>"
28+
end
29+
end
30+
end
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,9 @@ header.exception:hover p {
205205
}
206206
}
207207

208-
<%#
208+
209209
/* Light theme */
210+
/*
210211
header.exception {
211212
text-shadow: 0 1px 0 rgba(250, 250, 250, 0.6);
212213
background: rgba(200,100,50,0.10);
@@ -218,7 +219,7 @@ header.exception h2 strong {
218219
header.exception p {
219220
color: #744;
220221
}
221-
%>
222+
*/
222223

223224
/* ---------------------------------------------------------------------
224225
* Navigation

lib/better_errors/templates/main.erb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
</head>
66
<body class="better-errors-javascript-not-loaded">
77
<%# Stylesheets are placed in the <body> for Turbolinks compatibility. %>
8-
<style type='text/css'>
9-
<%= File.open(File.expand_path("templates/main.css", File.dirname(__FILE__))).read %>
10-
</style>
8+
<%== ErrorPageStyle.style_tag %>
119

1210
<%# IE8 compatibility crap %>
1311
<script nonce="<%= csp_nonce %>">

0 commit comments

Comments
 (0)