Skip to content

Commit 640c994

Browse files
authored
Serve Static Files (#5)
* Setup to get it working on Harvest * require web-console and turbo-rails * Remove unused code in lib/playground/engine.rb * Make text area not break lines
1 parent 8402aa9 commit 640c994

File tree

11 files changed

+6008
-17
lines changed

11 files changed

+6008
-17
lines changed

Gemfile

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
55
gemspec
66

77
gem "sqlite3"
8-
9-
gem "sprockets-rails"
8+
gem "rails"
109
gem "puma"
11-
gem 'web-console'
12-
gem "turbo-rails"
10+
gem "sprockets-rails"
1311
# Start debugger with binding.b [https://github.com/ruby/debug]
1412
gem "debug", ">= 1.0.0"

Gemfile.lock

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ PATH
22
remote: .
33
specs:
44
playground (0.1.0)
5-
rails (>= 7.0.2.2)
65
turbo-rails
76
web-console
87

@@ -186,10 +185,9 @@ DEPENDENCIES
186185
debug (>= 1.0.0)
187186
playground!
188187
puma
188+
rails
189189
sprockets-rails
190190
sqlite3
191-
turbo-rails
192-
web-console
193191

194192
BUNDLED WITH
195193
2.3.7
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
//= link_directory ../stylesheets/playground .css
2-
//= link_directory ../javascript/playground .js
2+
//= link_directory ../javascripts/playground .js

app/assets/stylesheets/playground/application.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ textarea, input, select {
2626
}
2727

2828
textarea, select { padding:1rem; height:100%; max-height:500px; }
29-
textarea { width:100%; max-height:500px; }
29+
textarea { width:100%; max-height:500px; white-space:nowrap; }
3030
input { margin-bottom:0.5rem; padding:0.5rem;}
3131
select, input { width:200px; }
3232
select { font-size:0.7em; }

app/views/layouts/playground/application.html.erb

+20-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,26 @@
55
<%= csrf_meta_tags %>
66
<%= csp_meta_tag %>
77

8-
<%= stylesheet_link_tag "playground/application", media: "all" %>
9-
<%= javascript_include_tag "playground/application", media: "all" %>
8+
<%= javascript_include_tag "playground/application", nonce: true, media: "all" %>
9+
10+
<style type="text/css">
11+
body { max-width:900px; margin:auto; padding:0 1rem; }
12+
13+
.code { flex-grow:1; height:500px; }
14+
.sidebar, .code { margin-right:1rem; }
15+
16+
textarea, input, select {
17+
-webkit-box-sizing:border-box;
18+
-moz-box-sizing:border-box;
19+
box-sizing:border-box;
20+
}
21+
22+
textarea, select { padding:1rem; height:100%; max-height:500px; }
23+
textarea { width:100%; max-height:500px; white-space:nowrap; }
24+
input { margin-bottom:0.5rem; padding:0.5rem;}
25+
select, input { width:200px; }
26+
select { font-size:0.7em; }
27+
</style>
1028
</head>
1129
<body>
1230

lib/playground.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
require "playground/version"
22
require "playground/engine"
3+
require "web-console"
4+
require "turbo-rails"
35

46
module Playground
57
# Your code goes here...

lib/playground/engine.rb

+14-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,20 @@ module Playground
22
class Engine < ::Rails::Engine
33
isolate_namespace Playground
44

5-
initializer "blorgh.assets.precompile" do |app|
6-
app.config.assets.precompile += %w( application.js application.css )
5+
# If you don't want to precompile Turbo's assets (eg. because you're using webpack),
6+
# you can do this in an intiailzer:
7+
#
8+
# config.after_initialize do
9+
# config.assets.precompile -= Turbo::Engine::PRECOMPILE_ASSETS
10+
# end
11+
PRECOMPILE_ASSETS = %w( application.js application.css )
12+
13+
initializer "playground.assets" do |app|
14+
# if app.config.respond_to?(:assets)
15+
# app.config.assets.precompile += PRECOMPILE_ASSETS
16+
# end
17+
app.middleware.insert_before(::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/vendor")
718
end
19+
820
end
921
end

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"esbuild": "^0.14.25"
77
},
88
"scripts": {
9-
"watch": "esbuild javascript/application.js --outfile=app/assets/javascript/playground/application.js --bundle --watch",
10-
"build": "esbuild javascript/application.js --outfile=app/assets/javascript/playground/application.js --bundle"
9+
"watch": "esbuild javascript/application.js --outfile=app/assets/javascripts/playground/application.js --bundle --watch",
10+
"build": "esbuild javascript/application.js --outfile=app/assets/javascripts/playground/application.js --bundle"
1111
}
1212
}

playground.gemspec

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ Gem::Specification.new do |spec|
1414
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
1515

1616
spec.files = Dir.chdir(File.expand_path(__dir__)) do
17-
Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
17+
Dir["{app,config,db,lib,vendor}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
1818
end
1919

20-
spec.add_dependency "rails", ">= 7.0.2.2"
2120
spec.add_dependency "web-console"
2221
spec.add_dependency "turbo-rails"
2322
end

0 commit comments

Comments
 (0)