Compare commits
No commits in common. "14f1f3daa64dcdc56d6cdf2607da3857577f6055" and "971c5f2233ef500bd03111d5c8ef24cf22bacbec" have entirely different histories.
14f1f3daa6
...
971c5f2233
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,2 +0,0 @@
|
||||||
/.rake_tasks~
|
|
||||||
/temp.db
|
|
||||||
7
Gemfile
7
Gemfile
|
|
@ -4,13 +4,6 @@ gem 'roda'
|
||||||
gem 'rack-unreloader'
|
gem 'rack-unreloader'
|
||||||
gem 'tilt'
|
gem 'tilt'
|
||||||
gem 'erubi'
|
gem 'erubi'
|
||||||
gem 'sequel'
|
|
||||||
gem 'rake'
|
|
||||||
|
|
||||||
# Change to whatever database you plan to use
|
|
||||||
gem 'sqlite3'
|
|
||||||
# gem 'pg' # will also want gem sequel-pg
|
|
||||||
# gem 'mysql2'
|
|
||||||
|
|
||||||
# change to gunicorn or passenger if you prefer:
|
# change to gunicorn or passenger if you prefer:
|
||||||
gem 'puma'
|
gem 'puma'
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
For the single file app template, really the only file you need is the config.ru and run it with puma.
|
For the single file app template, really the only file you need is the config.ru and run it with puma.
|
||||||
|
|
||||||
## Database
|
|
||||||
|
|
||||||
## Views
|
## Views
|
||||||
|
|
||||||
In this template, I've taken the single-file template and split up the config.ru to put routes and app logic in app.rb and call on templates to render proper html pages. `tilt` and `erubi` gems are added to do the rendering, and `rack-unreloader` gem is added to have puma automatically load file changes while running in development mode.
|
In this template, I've taken the single-file template and split up the config.ru to put routes and app logic in app.rb and call on templates to render proper html pages. `tilt` and `erubi` gems are added to do the rendering, and `rack-unreloader` gem is added to have puma automatically load file changes while running in development mode.
|
||||||
|
|
@ -23,7 +21,7 @@ Will need ruby; install it via package manager or a ruby manager like rbenv/ruby
|
||||||
With this example, will basically just ignore the project's Gemfile. Debian 12 has a pretty current ruby version so just using it.
|
With this example, will basically just ignore the project's Gemfile. Debian 12 has a pretty current ruby version so just using it.
|
||||||
|
|
||||||
```
|
```
|
||||||
sudo apt install ruby ruby-rack puma ruby-erubi ruby-tilt ruby-sequel ruby-sqlite3 rake
|
sudo apt install ruby ruby-rack puma ruby-erubi ruby-tilt
|
||||||
sudo gem install roda rack-unreloader
|
sudo gem install roda rack-unreloader
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
33
Rakefile
33
Rakefile
|
|
@ -1,33 +0,0 @@
|
||||||
namespace :db do
|
|
||||||
|
|
||||||
migrator = lambda do |version|
|
|
||||||
require_relative 'db'
|
|
||||||
Sequel.extension :migration
|
|
||||||
Sequel::Migrator.apply(DB, 'migrate', version)
|
|
||||||
end
|
|
||||||
|
|
||||||
namespace :migrate do
|
|
||||||
|
|
||||||
desc "Perform migration up to latest migration available"
|
|
||||||
task :up do
|
|
||||||
migrator.call(nil)
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "Perform migration all the way down (erase all data)"
|
|
||||||
task :down do
|
|
||||||
migrator.call(0)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "Erase all data, then bring back to latest migration"
|
|
||||||
task :reset do
|
|
||||||
migrator.call(0)
|
|
||||||
Sequel::Migrator.apply(DB, 'migrate')
|
|
||||||
end
|
|
||||||
|
|
||||||
#desc "Migrate to a specific version"
|
|
||||||
#task :migrate do |version|
|
|
||||||
#end
|
|
||||||
|
|
||||||
end
|
|
||||||
15
app.rb
15
app.rb
|
|
@ -14,17 +14,10 @@ class App < Roda
|
||||||
view :index
|
view :index
|
||||||
end
|
end
|
||||||
|
|
||||||
r.is 'users' do
|
r.is String do |name|
|
||||||
@users = User.order(:id)
|
@page_title = 'A Custom Greeting'
|
||||||
view :users
|
@name = name.capitalize
|
||||||
end
|
view :greeting
|
||||||
|
|
||||||
r.on 'hello' do
|
|
||||||
r.is String do |name|
|
|
||||||
@page_title = 'A Custom Greeting'
|
|
||||||
@name = name.capitalize
|
|
||||||
view :greeting
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,7 @@ dev = ENV['RACK_ENV'] == 'development'
|
||||||
|
|
||||||
require 'rack/unreloader'
|
require 'rack/unreloader'
|
||||||
|
|
||||||
Unreloader = Rack::Unreloader.new(:subclasses=>%w'Roda Sequel::Model', reload: dev, autoload: dev){App}
|
Unreloader = Rack::Unreloader.new(:subclasses=>%w'Roda', :reload=>dev){App}
|
||||||
Unreloader.require './models.rb'
|
|
||||||
Unreloader.require './app.rb'
|
Unreloader.require './app.rb'
|
||||||
|
|
||||||
run(dev ? Unreloader : App)
|
run(dev ? Unreloader : App)
|
||||||
|
|
|
||||||
4
db.rb
4
db.rb
|
|
@ -1,4 +0,0 @@
|
||||||
# frozen_string_literal: true
|
|
||||||
require 'sequel/core'
|
|
||||||
|
|
||||||
DB = Sequel.connect('sqlite://temp.db')
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
Sequel.migration do
|
|
||||||
change do
|
|
||||||
create_table(:users) do
|
|
||||||
primary_key :id
|
|
||||||
String :name, unique: true, null: false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
14
models.rb
14
models.rb
|
|
@ -1,14 +0,0 @@
|
||||||
# frozen_string_literal: true
|
|
||||||
require_relative 'db'
|
|
||||||
require 'sequel/model'
|
|
||||||
|
|
||||||
if ENV['RACK_ENV'] == 'development'
|
|
||||||
Sequel::Model.cache_associations = false
|
|
||||||
end
|
|
||||||
|
|
||||||
unless defined?(Unreloader)
|
|
||||||
require 'rack/unreloader'
|
|
||||||
Unreloader = Rack::Unreloader.new(reload: false, autoload: !ENV['NO_AUTOLOAD'])
|
|
||||||
end
|
|
||||||
|
|
||||||
Unreloader.autoload('models'){|f| Sequel::Model.send(:camelize, File.basename(f).sub(/\.rb\z/, ''))}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
# frozen_string_literal: true
|
|
||||||
class User < Sequel::Model
|
|
||||||
end
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
<p class="subtitle is-3">
|
<p class="subtitle is-3">
|
||||||
Welcome to my new page! Running in <%= ENV['RACK_ENV'] %> mode!
|
Welcome to my new page!
|
||||||
</p>
|
</p>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
<% for u in @users do %>
|
|
||||||
<p class="subtitle is-3">
|
|
||||||
Hello, <%= u.name %>! You're #<%= u.id %>!
|
|
||||||
</p>
|
|
||||||
<% end %>
|
|
||||||
Loading…
Reference in a new issue