Skip to content

Commit 511e5fd

Browse files
authored
Create command line for new template (#16)
1 parent 3f6c097 commit 511e5fd

File tree

5 files changed

+110
-3
lines changed

5 files changed

+110
-3
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
examples/*.sqlite*
1010
**/*.sqlite*
1111
log/*
12-
**/uni_rails.gem
12+
**/uni_rails.gem
13+
.byebug_history

Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
uni_rails (0.3.0)
4+
uni_rails (0.4.0)
55
rackup (~> 2.1)
66
rails (~> 7.1)
77
turbo-rails (~> 2.0)

assets/templates/default.txt

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
ENV["SECRET_KEY_BASE"] = "1212312313"
2+
ENV["DATABASE_URL"] = "sqlite3:///#{__dir__}/database.sqlite"
3+
4+
require "bundler/inline"
5+
6+
gemfile do
7+
source "https://www.rubygems.org"
8+
gem "uni_rails"
9+
gem "sqlite3", "~> 1.7"
10+
gem "byebug"
11+
end
12+
13+
require "uni_rails"
14+
require "sqlite3"
15+
require "byebug"
16+
17+
# ==== ROUTES ====
18+
UniRails::App.routes.append do
19+
root "resource_names#new"
20+
resources :resource_names
21+
end
22+
23+
# ==== DB SCHEMA ====
24+
ActiveRecord::Base.establish_connection
25+
ActiveRecord::Schema.define do
26+
create_table :resources, force: :cascade do |t|
27+
t.string :title
28+
end
29+
end
30+
31+
# ==== MODELS ====
32+
class Resource < ActiveRecord::Base
33+
end
34+
35+
# ==== SEEDS ====
36+
# Create your existing records here
37+
38+
# ==== CONTROLLERS ====
39+
class ResourceNamesController < ActionController::Base
40+
layout 'application'
41+
42+
def new
43+
end
44+
45+
def create
46+
end
47+
end
48+
49+
# ==== IMPORT MAPS ====
50+
UniRails.import_maps(
51+
'stimulus' => 'https://unpkg.com/@hotwired/stimulus/dist/stimulus.js'
52+
)
53+
54+
55+
# ==== JAVASCRTIP ====
56+
UniRails.javascript <<~JAVASCRIPT
57+
import { Application, Controller } from "stimulus"
58+
window.Stimulus = Application.start()
59+
60+
Stimulus.register("hello", class extends Controller {
61+
connect() {
62+
console.log("hello world")
63+
}
64+
})
65+
66+
JAVASCRIPT
67+
68+
# ==== CSS ====
69+
UniRails.css <<~CSS
70+
html { background-color:#EEE; }
71+
body { width:500px; height:700px; margin:auto;
72+
background-color:white; padding:1rem;
73+
}
74+
form {
75+
label { display: block; }
76+
input[type="submit"] { display: block; margin-top:1rem; }
77+
.field_with_errors { color:red; display:inline; }
78+
}
79+
CSS
80+
81+
# ==== VIEWS ====
82+
UniRails.register_view "resource_names/new.html.erb", <<~HTML
83+
HTML
84+
85+
UniRails.register_view "resource_names/show.html.erb", <<~HTML
86+
HTML
87+
88+
UniRails.run(Port: 3000)

exe/unirails

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env ruby
2+
3+
# require "byebug"
4+
# byebug
5+
6+
assets_path = File.expand_path('../assets', __dir__)
7+
8+
options = {}
9+
case ARGV[0]
10+
when "new"
11+
filename = ARGV[1]
12+
File.open(filename, 'wb+') do |f|
13+
f.write File.read File.join(assets_path, 'templates', 'default.txt')
14+
end
15+
else
16+
puts "unknown command"
17+
puts "Usage: unirails new <filename>"
18+
end

lib/uni_rails/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module UniRails
4-
VERSION = "0.3.0"
4+
VERSION = "0.4.0"
55
end

0 commit comments

Comments
 (0)