roda-project 0.1.10 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/roda/project/bin/generators/migration/action_detector.rb +7 -7
- data/lib/roda/project/bin/generators/migration/code_builder.rb +7 -7
- data/lib/roda/project/bin/generators/migration/field_parser.rb +3 -25
- data/lib/roda/project/bin/generators/migration.rb +7 -5
- data/lib/roda/project/bin/generators/model.rb +119 -0
- data/lib/roda/project/bin/generators/routes.rb +28 -18
- data/lib/roda/project/bin/generators.rb +5 -0
- data/lib/roda/project/cli.rb +11 -1
- data/lib/roda/project/generator.rb +10 -1
- data/lib/roda/project/helpers/inflections.rb +12 -4
- data/lib/roda/project/helpers/interactive_input.rb +0 -4
- data/lib/roda/project/helpers/template.rb +7 -0
- data/lib/roda/project/jeremy_template_creator.rb +33 -0
- data/lib/roda/project/main_context.rb +2 -2
- data/lib/roda/project/templates/base/app/app.rb.erb +1 -1
- data/lib/roda/project/templates/base/scaffold/app/config/config.rb.erb +14 -1
- data/lib/roda/project/version.rb +1 -1
- data/lib/roda/project.rb +3 -1
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ba772c511bc001bfa35bf4345638652b7291dd2e144003922fa85880e7dc03f3
|
|
4
|
+
data.tar.gz: be9c85ed58652607a5614d7f37d0878085f7834f257cd2053d766d067fd71a44
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 63ef03a38f04ae88bda73eb7d890c3d80fda95521695a4e7ad6f19bd30a84630bff9f4daa4b7a8d08818fe77a235241bcb60f48e58e060646b2cd8c3dad62fd0
|
|
7
|
+
data.tar.gz: 9737a1545992102d0e82c5563cc0a29ae6c0c15d6b24bf07f16f493f5421b043b77be2b15ca2894157358f89b077e9cc9e7f42f84ed114fb9e59d8da0c92be38
|
|
@@ -19,18 +19,18 @@ class Roda
|
|
|
19
19
|
camel_name = camelize(name)
|
|
20
20
|
|
|
21
21
|
if (m = camel_name.match(/^CreateJoinTable(?<t1>[A-Z][a-zA-Z0-9]*?)(?<t2>[A-Z][a-zA-Z0-9]*)$/)) ||
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
(m = camel_name.match(/JoinTable(?<t1>[A-Z][a-zA-Z0-9]*?)(?<t2>[A-Z][a-zA-Z0-9]*)$/)) ||
|
|
23
|
+
camel_name.start_with?("CreateJoinTable") || camel_name.include?("JoinTable")
|
|
24
24
|
tables = parse_join_tables(m)
|
|
25
|
-
{
|
|
25
|
+
{action: :create_join_table, tables: tables}
|
|
26
26
|
elsif (m = camel_name.match(/^Create(?<table_name>[A-Z0-9].*)$/))
|
|
27
|
-
{
|
|
27
|
+
{action: :create_table, table_name: pluralize(underscore(m[:table_name]))}
|
|
28
28
|
elsif (m = camel_name.match(/^Add.+To(?<table_name>[A-Z0-9].*)$/))
|
|
29
|
-
{
|
|
29
|
+
{action: :add_columns, table_name: pluralize(underscore(m[:table_name]))}
|
|
30
30
|
elsif (m = camel_name.match(/^Remove.+From(?<table_name>[A-Z0-9].*)$/))
|
|
31
|
-
{
|
|
31
|
+
{action: :drop_columns, table_name: pluralize(underscore(m[:table_name]))}
|
|
32
32
|
else
|
|
33
|
-
{
|
|
33
|
+
{action: :generic, table_name: nil}
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
|
|
@@ -166,13 +166,13 @@ class Roda
|
|
|
166
166
|
|
|
167
167
|
formatted = opts.map do |k, v|
|
|
168
168
|
val_str = case v
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
169
|
+
when Array
|
|
170
|
+
"[#{v.join(", ")}]"
|
|
171
|
+
when Symbol
|
|
172
|
+
":#{v}"
|
|
173
|
+
else
|
|
174
|
+
v.inspect
|
|
175
|
+
end
|
|
176
176
|
"#{k}: #{val_str}"
|
|
177
177
|
end.join(", ")
|
|
178
178
|
|
|
@@ -6,6 +6,8 @@ class Roda
|
|
|
6
6
|
class Generators
|
|
7
7
|
class Migration
|
|
8
8
|
class FieldParser
|
|
9
|
+
include Roda::Project::Helpers::Inflections
|
|
10
|
+
|
|
9
11
|
TYPE_MAP = {
|
|
10
12
|
"string" => "String",
|
|
11
13
|
"text" => "String",
|
|
@@ -80,7 +82,7 @@ class Roda
|
|
|
80
82
|
if modifier.include?(".")
|
|
81
83
|
prec, scale = modifier.split(".").map(&:to_i)
|
|
82
84
|
options[:size] = [prec, scale]
|
|
83
|
-
elsif
|
|
85
|
+
elsif /^\d+$/.match?(modifier)
|
|
84
86
|
options[:size] = modifier.to_i
|
|
85
87
|
end
|
|
86
88
|
end
|
|
@@ -119,30 +121,6 @@ class Roda
|
|
|
119
121
|
false
|
|
120
122
|
end
|
|
121
123
|
end
|
|
122
|
-
|
|
123
|
-
def singularize(str)
|
|
124
|
-
if str.end_with?("ies")
|
|
125
|
-
"#{str[0..-4]}y"
|
|
126
|
-
elsif str.end_with?("es") && !str.end_with?("ques")
|
|
127
|
-
str[0..-3]
|
|
128
|
-
elsif str.end_with?("s") && !str.end_with?("ss")
|
|
129
|
-
str[0..-2]
|
|
130
|
-
else
|
|
131
|
-
str
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
def pluralize(str)
|
|
136
|
-
return str if str.end_with?("s")
|
|
137
|
-
|
|
138
|
-
if str.end_with?("y") && !str.end_with?("ay", "ey", "oy", "uy")
|
|
139
|
-
"#{str[0..-2]}ies"
|
|
140
|
-
elsif str.end_with?("s", "x", "z", "ch", "sh")
|
|
141
|
-
"#{str}es"
|
|
142
|
-
else
|
|
143
|
-
"#{str}s"
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
124
|
end
|
|
147
125
|
end
|
|
148
126
|
end
|
|
@@ -11,6 +11,7 @@ class Roda
|
|
|
11
11
|
exit 1
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
+
puts "* creating migration"
|
|
14
15
|
FileUtils.mkdir_p(migrations_path) unless File.directory?(migrations_path)
|
|
15
16
|
|
|
16
17
|
existing_migrations = Dir.glob(File.join(migrations_path, "*.rb"))
|
|
@@ -27,7 +28,8 @@ class Roda
|
|
|
27
28
|
content = CodeBuilder.new(detection: detection, fields: fields).build
|
|
28
29
|
|
|
29
30
|
File.write(filename, content)
|
|
30
|
-
|
|
31
|
+
|
|
32
|
+
action_success_message(filename)
|
|
31
33
|
end
|
|
32
34
|
|
|
33
35
|
def migrations_path
|
|
@@ -39,16 +41,16 @@ class Roda
|
|
|
39
41
|
end
|
|
40
42
|
|
|
41
43
|
def field_args
|
|
42
|
-
@field_args ||=
|
|
44
|
+
@field_args ||= @args[1..] || []
|
|
43
45
|
end
|
|
44
46
|
|
|
45
47
|
private
|
|
46
48
|
|
|
47
49
|
def underscore(str)
|
|
48
50
|
str.to_s.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
|
52
|
+
.tr("-", "_")
|
|
53
|
+
.downcase
|
|
52
54
|
end
|
|
53
55
|
end
|
|
54
56
|
end
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
class Roda
|
|
2
|
+
module Project
|
|
3
|
+
module Bin
|
|
4
|
+
class Generators < ::Thor
|
|
5
|
+
class Model < Roda::Project::Bin::Generator
|
|
6
|
+
include Roda::Project::Helpers::Inflections
|
|
7
|
+
|
|
8
|
+
def call
|
|
9
|
+
if model_name.nil? || field_args == []
|
|
10
|
+
puts "Usage: bin/roda g model name field1 field2"
|
|
11
|
+
exit 1
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
puts "* creating model"
|
|
15
|
+
create_model
|
|
16
|
+
create_model_test
|
|
17
|
+
Migration.new(args: [migration_name].concat(field_args)).call
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def create_model_test
|
|
21
|
+
ensure_and_get_path("spec/app/models", model_relative_path)
|
|
22
|
+
filename = File.join("spec/app/models", *name_segments[0..-2], "#{model_file_basename}_spec.rb")
|
|
23
|
+
File.write(filename, spec_code)
|
|
24
|
+
|
|
25
|
+
action_success_message(filename)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def create_model
|
|
29
|
+
ensure_and_get_path("app/models", model_relative_path)
|
|
30
|
+
filename = File.join("app/models", *name_segments[0..-2], "#{model_file_basename}.rb")
|
|
31
|
+
File.write(filename, code)
|
|
32
|
+
|
|
33
|
+
action_success_message(filename)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def spec_code
|
|
37
|
+
depth = 2 + name_segments.length - 1
|
|
38
|
+
relative_prefix = "../" * depth
|
|
39
|
+
<<~RUBY
|
|
40
|
+
require_relative "#{relative_prefix}spec_helper"
|
|
41
|
+
|
|
42
|
+
describe #{qualified_class_name} do
|
|
43
|
+
end
|
|
44
|
+
RUBY
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def code
|
|
48
|
+
if name_segments.length == 1
|
|
49
|
+
<<~RUBY
|
|
50
|
+
class #{qualified_class_name}
|
|
51
|
+
end
|
|
52
|
+
RUBY
|
|
53
|
+
else
|
|
54
|
+
depth = name_segments.length - 1
|
|
55
|
+
class_indent = " " * depth
|
|
56
|
+
lines = [
|
|
57
|
+
"#{class_indent}class #{camelize(name_segments.last)} < Sequel::Model(:#{table_name})",
|
|
58
|
+
"#{class_indent}end"
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
name_segments[0..-2].map { |s| camelize(s) }.reverse.each_with_index do |mod, idx|
|
|
62
|
+
mod_indent = " " * (depth - 1 - idx)
|
|
63
|
+
lines = ["#{mod_indent}class #{mod}"] + lines + ["#{mod_indent}end"]
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
lines.join("\n") + "\n"
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def migration_name
|
|
71
|
+
segs = name_segments.map { |s| camelize(s) }
|
|
72
|
+
segs[-1] = pluralize(segs[-1])
|
|
73
|
+
"Create" + segs.join("_")
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def name_segments
|
|
77
|
+
@name_segments ||= @args[0].to_s.split("/")
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def qualified_class_name
|
|
81
|
+
@qualified_class_name ||= name_segments.map { |s| camelize(s) }.join("::")
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def flat_class_name
|
|
85
|
+
@flat_class_name ||= name_segments.map { |s| camelize(s) }.join
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def table_name
|
|
89
|
+
@table_name ||= begin
|
|
90
|
+
segs = name_segments.map { |s| underscore(camelize(s)) }
|
|
91
|
+
segs[-1] = pluralize(segs[-1])
|
|
92
|
+
segs.join("_")
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def model_relative_path
|
|
97
|
+
@model_relative_path ||= if name_segments.length > 1
|
|
98
|
+
File.join(*name_segments[0..-2], model_file_basename)
|
|
99
|
+
else
|
|
100
|
+
model_file_basename
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def model_file_basename
|
|
105
|
+
@model_file_basename ||= underscore(name_segments.last)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def model_name
|
|
109
|
+
@model_name ||= @args[0].nil? ? nil : qualified_class_name
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def field_args
|
|
113
|
+
@field_args ||= @args[1..] || []
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
@@ -10,6 +10,7 @@ class Roda
|
|
|
10
10
|
exit 1
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
+
puts "* creating routes"
|
|
13
14
|
generate_routes
|
|
14
15
|
generate_views
|
|
15
16
|
generate_tests
|
|
@@ -19,11 +20,18 @@ class Roda
|
|
|
19
20
|
private
|
|
20
21
|
|
|
21
22
|
def generate_routes
|
|
22
|
-
filename = File.join(ensure_and_get_path("app/routes"), "#{branch_name}.rb")
|
|
23
|
+
filename = File.join(ensure_and_get_path("app/routes", branch_name), "#{branch_name}.rb")
|
|
23
24
|
route_definitions = routes_list.map do |route_str|
|
|
24
25
|
method, name = parse_route_string(route_str)
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
view_name = name
|
|
27
|
+
view_name = "index" if view_name == ""
|
|
28
|
+
view_line = (method == "get" && must_generate_views?) ? "\n view('#{view_name}')" : ""
|
|
29
|
+
|
|
30
|
+
if name != ""
|
|
31
|
+
" r.#{method} \"#{name}\" do#{view_line}\n end"
|
|
32
|
+
else
|
|
33
|
+
" r.#{method} do#{view_line}\n end"
|
|
34
|
+
end
|
|
27
35
|
end.join("\n\n")
|
|
28
36
|
|
|
29
37
|
hash_branch_header = if branch_name.include?("/")
|
|
@@ -44,7 +52,7 @@ class Roda
|
|
|
44
52
|
end
|
|
45
53
|
RUBY
|
|
46
54
|
File.write(filename, content)
|
|
47
|
-
|
|
55
|
+
action_success_message(filename)
|
|
48
56
|
end
|
|
49
57
|
|
|
50
58
|
def generate_views
|
|
@@ -54,25 +62,34 @@ class Roda
|
|
|
54
62
|
routes_list.each do |route_str|
|
|
55
63
|
method, name = parse_route_string(route_str)
|
|
56
64
|
if method == "get"
|
|
65
|
+
name = "index" if name == ""
|
|
57
66
|
view_filename = File.join(branch_views_dir, "#{name}.erb")
|
|
58
67
|
File.write(view_filename, "")
|
|
59
|
-
|
|
68
|
+
action_success_message(view_filename)
|
|
60
69
|
end
|
|
61
70
|
end
|
|
62
71
|
end
|
|
63
72
|
end
|
|
64
73
|
|
|
65
74
|
def generate_tests
|
|
66
|
-
test_filename = File.join(ensure_and_get_path("spec/app/routes"), "#{branch_name}_spec.rb")
|
|
75
|
+
test_filename = File.join(ensure_and_get_path("spec/app/routes", branch_name), "#{branch_name}_spec.rb")
|
|
67
76
|
nesting_level = branch_name.count("/")
|
|
68
77
|
relative_spec_helper_path = "../" * (2 + nesting_level) + "spec_helper"
|
|
69
78
|
|
|
70
79
|
test_route_definitions = routes_list.map do |route_str|
|
|
71
80
|
method, name = parse_route_string(route_str)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
"
|
|
75
|
-
|
|
81
|
+
|
|
82
|
+
if name != ""
|
|
83
|
+
" it \"responds to #{method.upcase} /#{branch_name}/#{name}\" do\n" \
|
|
84
|
+
" #{method} \"/#{branch_name}/#{name}\"\n" \
|
|
85
|
+
" expect(last_response.status).to eq(200)\n" \
|
|
86
|
+
" end"
|
|
87
|
+
else
|
|
88
|
+
" it \"responds to #{method.upcase} /#{branch_name} do\n" \
|
|
89
|
+
" #{method} \"/#{branch_name}\n" \
|
|
90
|
+
" expect(last_response.status).to eq(200)\n" \
|
|
91
|
+
" end"
|
|
92
|
+
end
|
|
76
93
|
end.join("\n")
|
|
77
94
|
|
|
78
95
|
test_content = <<~RUBY
|
|
@@ -83,7 +100,7 @@ class Roda
|
|
|
83
100
|
end
|
|
84
101
|
RUBY
|
|
85
102
|
File.write(test_filename, test_content)
|
|
86
|
-
|
|
103
|
+
action_success_message(test_filename)
|
|
87
104
|
end
|
|
88
105
|
|
|
89
106
|
def must_generate_views?
|
|
@@ -96,13 +113,6 @@ class Roda
|
|
|
96
113
|
[method, name]
|
|
97
114
|
end
|
|
98
115
|
|
|
99
|
-
def ensure_and_get_path(path)
|
|
100
|
-
full_path_dir = File.join(path, File.dirname(branch_name))
|
|
101
|
-
FileUtils.mkdir_p(full_path_dir) unless File.directory?(full_path_dir)
|
|
102
|
-
|
|
103
|
-
path
|
|
104
|
-
end
|
|
105
|
-
|
|
106
116
|
def routes_list
|
|
107
117
|
@routes_list ||= @args[1..]
|
|
108
118
|
end
|
data/lib/roda/project/cli.rb
CHANGED
|
@@ -10,8 +10,8 @@ class Roda
|
|
|
10
10
|
puts pastel.italic("#{Roda::Project.messages.sample.first}\n")
|
|
11
11
|
|
|
12
12
|
get_user_context
|
|
13
|
-
|
|
14
13
|
puts pastel.bright_black("\n[project: #{@context.project_name}]\n")
|
|
14
|
+
return JeremyTemplateCreator.new(context: @context).call if jeremy?
|
|
15
15
|
|
|
16
16
|
create_base_project
|
|
17
17
|
add_front_end
|
|
@@ -44,6 +44,8 @@ class Roda
|
|
|
44
44
|
|
|
45
45
|
def get_user_context
|
|
46
46
|
retry_on_error { @context.project_name = read_line("Project name › ", "project") }
|
|
47
|
+
return if jeremy?
|
|
48
|
+
|
|
47
49
|
retry_on_error { @context.base = read_line("(#{fullstack_id}) Fullstack (#{api_id}) API (#{minimal_id}) Minimal › ", fullstack_id).to_i }
|
|
48
50
|
retry_on_error { @context.tests = read_line("(#{rspec_id}) RSpec (#{minitest_id}) Minitest › ", rspec_id).to_i }
|
|
49
51
|
|
|
@@ -63,6 +65,10 @@ class Roda
|
|
|
63
65
|
end
|
|
64
66
|
end
|
|
65
67
|
|
|
68
|
+
def jeremy?
|
|
69
|
+
@jeremy ||= ARGV[0] == "--jeremy"
|
|
70
|
+
end
|
|
71
|
+
|
|
66
72
|
def create_base_project
|
|
67
73
|
puts "* creating base project"
|
|
68
74
|
if @context.minimal?
|
|
@@ -97,8 +103,11 @@ class Roda
|
|
|
97
103
|
erb_cp_file("front-end", "esbuild.js")
|
|
98
104
|
erb_cp_file("front-end", "package.json")
|
|
99
105
|
cp_dir("front-end", "app/views")
|
|
106
|
+
action_success_message("app/views")
|
|
100
107
|
cp_dir("front-end", "public/assets")
|
|
108
|
+
action_success_message("public/assets")
|
|
101
109
|
cp_dir("front-end", "public/images")
|
|
110
|
+
action_success_message("public/images")
|
|
102
111
|
end
|
|
103
112
|
end
|
|
104
113
|
|
|
@@ -118,6 +127,7 @@ class Roda
|
|
|
118
127
|
erb_cp_file("rodauth", "db/migrations/001_add_rodauth.rb")
|
|
119
128
|
if @context.fullstack?
|
|
120
129
|
cp_file("rodauth", "app/views/create-account.erb")
|
|
130
|
+
action_success_message("app/views/create-account.erb")
|
|
121
131
|
end
|
|
122
132
|
end
|
|
123
133
|
end
|
|
@@ -4,16 +4,25 @@ class Roda
|
|
|
4
4
|
include Helpers::Template
|
|
5
5
|
include Helpers::Ids
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
attr_reader :pastel
|
|
8
|
+
|
|
9
|
+
def initialize(context: MainContext.new, args: [], options: {}, dir: nil, pastel: Pastel.new)
|
|
8
10
|
@context = context
|
|
9
11
|
@args = args
|
|
10
12
|
@options = options
|
|
11
13
|
@dir = dir
|
|
14
|
+
@pastel = pastel
|
|
12
15
|
end
|
|
13
16
|
|
|
14
17
|
def call
|
|
15
18
|
false
|
|
16
19
|
end
|
|
20
|
+
|
|
21
|
+
protected
|
|
22
|
+
|
|
23
|
+
def action_success_message(path, action = "create")
|
|
24
|
+
puts(pastel.green(" #{action} ") + path)
|
|
25
|
+
end
|
|
17
26
|
end
|
|
18
27
|
end
|
|
19
28
|
end
|
|
@@ -7,16 +7,16 @@ class Roda
|
|
|
7
7
|
module_function
|
|
8
8
|
|
|
9
9
|
def camelize(str)
|
|
10
|
-
return str if
|
|
10
|
+
return str if /[A-Z]/.match?(str)
|
|
11
11
|
|
|
12
12
|
str.split("_").map(&:capitalize).join
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def underscore(str)
|
|
16
16
|
str.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
|
18
|
+
.tr("-", "_")
|
|
19
|
+
.downcase
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def pluralize(str)
|
|
@@ -42,6 +42,14 @@ class Roda
|
|
|
42
42
|
str
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
|
+
|
|
46
|
+
def singular?(str)
|
|
47
|
+
str == singularize(str)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def plural?(str)
|
|
51
|
+
str == pluralize(str)
|
|
52
|
+
end
|
|
45
53
|
end
|
|
46
54
|
end
|
|
47
55
|
end
|
|
@@ -34,6 +34,13 @@ class Roda
|
|
|
34
34
|
)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
+
def ensure_and_get_path(path, name)
|
|
38
|
+
full_path_dir = File.join(path, File.dirname(name))
|
|
39
|
+
FileUtils.mkdir_p(full_path_dir) unless File.directory?(full_path_dir)
|
|
40
|
+
|
|
41
|
+
path
|
|
42
|
+
end
|
|
43
|
+
|
|
37
44
|
def templates_root
|
|
38
45
|
@templates_root ||= "../templates"
|
|
39
46
|
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'fileutils'
|
|
2
|
+
|
|
3
|
+
class Roda
|
|
4
|
+
module Project
|
|
5
|
+
class JeremyTemplateCreator < Generator
|
|
6
|
+
include Helpers::Inflections
|
|
7
|
+
|
|
8
|
+
def call
|
|
9
|
+
repo_url = "https://github.com/jeremyevans/roda-sequel-stack"
|
|
10
|
+
puts "* Downloading template with git...\n\n"
|
|
11
|
+
|
|
12
|
+
success = system("git clone --depth 1 #{repo_url} #{@context.project_name}")
|
|
13
|
+
abort("\nCould not download the template.") unless success
|
|
14
|
+
|
|
15
|
+
git_dir = File.join(@context.project_name, '.git')
|
|
16
|
+
if Dir.exist?(git_dir)
|
|
17
|
+
FileUtils.rm_rf(git_dir)
|
|
18
|
+
puts "\n* Cleaned up template git history.\n\n"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
action_success_message("./#{@context.project_name}")
|
|
22
|
+
|
|
23
|
+
setup_command = "cd #{@context.project_name} && rake setup[#{camelize(@context.project_name)}]"
|
|
24
|
+
system(setup_command)
|
|
25
|
+
|
|
26
|
+
action_success_message(setup_command, "run")
|
|
27
|
+
puts "\n Setup is done! follow the link below to learn about this template:"
|
|
28
|
+
puts "\n #{repo}"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
@@ -23,9 +23,9 @@ class Roda
|
|
|
23
23
|
option :main_context, type: :hash, default: {
|
|
24
24
|
project_name: "#{project_name}",
|
|
25
25
|
base: #{id_to_string(base, :base)},
|
|
26
|
-
rodauth: #{rodauth},
|
|
26
|
+
rodauth: #{rodauth || false},
|
|
27
27
|
tests: #{id_to_string(tests, :tests)},
|
|
28
|
-
database: #{database},
|
|
28
|
+
database: #{database || false},
|
|
29
29
|
RUBY
|
|
30
30
|
if database?
|
|
31
31
|
option << " database_type: #{id_to_string(database_type, :database)},"
|
|
@@ -8,7 +8,7 @@ class <%= context.const_project_name %> < Roda
|
|
|
8
8
|
<% if context.fullstack? %>
|
|
9
9
|
# Views
|
|
10
10
|
plugin :partials, views: "app/views"
|
|
11
|
-
plugin :render,
|
|
11
|
+
plugin :render, **Config.get[:render]
|
|
12
12
|
plugin :content_for, append: false
|
|
13
13
|
plugin :flash
|
|
14
14
|
plugin :assets_manifest
|
|
@@ -12,7 +12,20 @@ module Config
|
|
|
12
12
|
}<% end %><% if context.database? %>,
|
|
13
13
|
db: {
|
|
14
14
|
url: not_production? ? <%= context.default_db_url %> : ENV["DATABASE_URL"]
|
|
15
|
-
}<% end
|
|
15
|
+
}<% end %><% if context.fullstack? %>,
|
|
16
|
+
render: {
|
|
17
|
+
layout: "./layout",
|
|
18
|
+
assume_fixed_locals: true, # Optimize plugin by assuming all templates use fixed locals
|
|
19
|
+
template_opts: {
|
|
20
|
+
scope_class: self, # Always uses current class as scope class for compiled templates
|
|
21
|
+
freeze: true, # Freeze string literals in templates
|
|
22
|
+
extract_fixed_locals: true, # Support fixed locals in templates
|
|
23
|
+
default_fixed_locals: '()', # Default to templates not supporting local variables
|
|
24
|
+
escape: true, # For Erubi templates, escapes %= by default (use %== for unescaped
|
|
25
|
+
chain_appends: true, # For Erubi templates, improves performance
|
|
26
|
+
skip_compiled_encoding_detection: true, # Unless you need encodings explicitly specified
|
|
27
|
+
}<% end %>
|
|
28
|
+
}
|
|
16
29
|
}
|
|
17
30
|
end
|
|
18
31
|
|
data/lib/roda/project/version.rb
CHANGED
data/lib/roda/project.rb
CHANGED
|
@@ -59,14 +59,16 @@ require_relative "project/helpers/inflections"
|
|
|
59
59
|
# Base
|
|
60
60
|
require_relative "project/main_context"
|
|
61
61
|
require_relative "project/generator"
|
|
62
|
+
require_relative "project/jeremy_template_creator"
|
|
62
63
|
require_relative "project/cli"
|
|
63
|
-
# Generators/base
|
|
64
64
|
require_relative "project/bin/generator"
|
|
65
65
|
# Generators/migration
|
|
66
66
|
require_relative "project/bin/generators/migration"
|
|
67
67
|
require_relative "project/bin/generators/migration/action_detector"
|
|
68
68
|
require_relative "project/bin/generators/migration/field_parser"
|
|
69
69
|
require_relative "project/bin/generators/migration/code_builder"
|
|
70
|
+
# Generators/model
|
|
71
|
+
require_relative "project/bin/generators/model"
|
|
70
72
|
# Generators/routes
|
|
71
73
|
require_relative "project/bin/generators/routes"
|
|
72
74
|
# Generators/base
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: roda-project
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.12
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Henrique F. Teixeira
|
|
@@ -83,6 +83,7 @@ files:
|
|
|
83
83
|
- lib/roda/project/bin/generators/migration/action_detector.rb
|
|
84
84
|
- lib/roda/project/bin/generators/migration/code_builder.rb
|
|
85
85
|
- lib/roda/project/bin/generators/migration/field_parser.rb
|
|
86
|
+
- lib/roda/project/bin/generators/model.rb
|
|
86
87
|
- lib/roda/project/bin/generators/routes.rb
|
|
87
88
|
- lib/roda/project/cli.rb
|
|
88
89
|
- lib/roda/project/generator.rb
|
|
@@ -90,6 +91,7 @@ files:
|
|
|
90
91
|
- lib/roda/project/helpers/inflections.rb
|
|
91
92
|
- lib/roda/project/helpers/interactive_input.rb
|
|
92
93
|
- lib/roda/project/helpers/template.rb
|
|
94
|
+
- lib/roda/project/jeremy_template_creator.rb
|
|
93
95
|
- lib/roda/project/main_context.rb
|
|
94
96
|
- lib/roda/project/templates/base/app/app.rb.erb
|
|
95
97
|
- lib/roda/project/templates/base/minimal/AGENTS.md
|
|
@@ -163,7 +165,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
163
165
|
requirements:
|
|
164
166
|
- - ">="
|
|
165
167
|
- !ruby/object:Gem::Version
|
|
166
|
-
version: 3.
|
|
168
|
+
version: 3.0.0
|
|
167
169
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
170
|
requirements:
|
|
169
171
|
- - ">="
|