roda-project 0.1.15 → 0.1.16
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/routes.rb +55 -19
- data/lib/roda/project/templates/base/app/app.rb.erb +3 -2
- data/lib/roda/project/templates/base/scaffold/Gemfile.erb +0 -1
- data/lib/roda/project/templates/base/scaffold/boot.rb.erb +16 -4
- data/lib/roda/project/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: beb637fce10cb01a9d71fbcceca4b10ccc6e04aa05bac094fc6327ed1854643e
|
|
4
|
+
data.tar.gz: 1ac1a13838ba8a5f5e6c65409e192ab9b15fe3f5ad9ee14dbc9d5b648a195434
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 471336f81ca6fd96226a001e599debeeb22302a284a78e8911a5bf0be02dd78c8010272b061f868d185ed82f3c943f84f6f90e2b35f44c807b2778027a24c019
|
|
7
|
+
data.tar.gz: 4ced8204c150d5208961c2315256151cd0eca3f2bd48905979684490450decc760f8d1b3828ac075fa1539d8e542ff4821cebfe0f70aa4df281efc0cc874e63a
|
|
@@ -12,9 +12,9 @@ class Roda
|
|
|
12
12
|
|
|
13
13
|
puts "* creating routes"
|
|
14
14
|
generate_routes
|
|
15
|
+
generate_nested_branch_files
|
|
15
16
|
generate_views
|
|
16
17
|
generate_tests
|
|
17
|
-
print_nested_branch_reminder
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
private
|
|
@@ -37,9 +37,8 @@ class Roda
|
|
|
37
37
|
hash_branch_header = if branch_name.include?("/")
|
|
38
38
|
parts = branch_name.split("/")
|
|
39
39
|
sub_path = parts[0..-2].join("/")
|
|
40
|
-
namespace = sub_path.include?("/") ? ":\"#{sub_path}\"" : ":#{sub_path}"
|
|
41
40
|
branch_segment = parts.last
|
|
42
|
-
"hash_branch #{
|
|
41
|
+
"hash_branch #{namespace_for(sub_path)}, \"#{branch_segment}\" do |r|"
|
|
43
42
|
else
|
|
44
43
|
"hash_branch \"#{branch_name}\" do |r|"
|
|
45
44
|
end
|
|
@@ -85,8 +84,8 @@ class Roda
|
|
|
85
84
|
" expect(last_response.status).to eq(200)\n" \
|
|
86
85
|
" end"
|
|
87
86
|
else
|
|
88
|
-
" it \"responds to #{method.upcase} /#{branch_name} do\n" \
|
|
89
|
-
" #{method} \"/#{branch_name}\n" \
|
|
87
|
+
" it \"responds to #{method.upcase} /#{branch_name}\" do\n" \
|
|
88
|
+
" #{method} \"/#{branch_name}\"\n" \
|
|
90
89
|
" expect(last_response.status).to eq(200)\n" \
|
|
91
90
|
" end"
|
|
92
91
|
end
|
|
@@ -103,6 +102,57 @@ class Roda
|
|
|
103
102
|
action_success_message(test_filename)
|
|
104
103
|
end
|
|
105
104
|
|
|
105
|
+
def generate_nested_branch_files
|
|
106
|
+
return unless branch_name.include?("/")
|
|
107
|
+
|
|
108
|
+
parts = branch_name.split("/")
|
|
109
|
+
parts[0..-2].each_with_index do |_segment, index|
|
|
110
|
+
prefix = parts[0..index].join("/")
|
|
111
|
+
filename = File.join("app/routes", "#{prefix}.rb")
|
|
112
|
+
|
|
113
|
+
if File.exist?(filename)
|
|
114
|
+
ensure_hash_branches_line(filename, namespace_for(prefix))
|
|
115
|
+
next
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
dir = File.dirname(filename)
|
|
119
|
+
FileUtils.mkdir_p(dir) unless File.directory?(dir)
|
|
120
|
+
File.write(filename, nested_branch_file_content(prefix, index))
|
|
121
|
+
action_success_message(filename)
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def nested_branch_file_content(prefix, index)
|
|
126
|
+
parts = prefix.split("/")
|
|
127
|
+
segment = parts.last
|
|
128
|
+
header = if index.zero?
|
|
129
|
+
"hash_branch \"#{segment}\" do |r|"
|
|
130
|
+
else
|
|
131
|
+
parent_path = parts[0..-2].join("/")
|
|
132
|
+
"hash_branch #{namespace_for(parent_path)}, \"#{segment}\" do |r|"
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
<<~RUBY
|
|
136
|
+
class #{@context.const_project_name}
|
|
137
|
+
#{header} # #{prefix} branch
|
|
138
|
+
r.hash_branches(#{namespace_for(prefix)}) # #{prefix}/ +1 routes
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
RUBY
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def ensure_hash_branches_line(filename, namespace)
|
|
145
|
+
expected_line = "r.hash_branches(#{namespace})"
|
|
146
|
+
return if File.read(filename).include?(expected_line)
|
|
147
|
+
|
|
148
|
+
puts " warning: #{filename} already exists — please add:"
|
|
149
|
+
puts " #{expected_line}"
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def namespace_for(sub_path)
|
|
153
|
+
sub_path.include?("/") ? ":\"#{sub_path}\"" : ":#{sub_path}"
|
|
154
|
+
end
|
|
155
|
+
|
|
106
156
|
def must_generate_views?
|
|
107
157
|
@options[:views] && Dir.exist?("app/views")
|
|
108
158
|
end
|
|
@@ -120,20 +170,6 @@ class Roda
|
|
|
120
170
|
def branch_name
|
|
121
171
|
@branch_name ||= @args[0]
|
|
122
172
|
end
|
|
123
|
-
|
|
124
|
-
def print_nested_branch_reminder
|
|
125
|
-
return unless branch_name.include?("/")
|
|
126
|
-
|
|
127
|
-
parts = branch_name.split("/")
|
|
128
|
-
sub_path = parts[0..-2].join("/")
|
|
129
|
-
namespace = sub_path.include?("/") ? ":\"#{sub_path}\"" : ":#{sub_path}"
|
|
130
|
-
|
|
131
|
-
puts "\ndont forget to add:\n\n" \
|
|
132
|
-
"autoload_hash_branch_dir(#{namespace}, \"./app/routes/#{sub_path}\")\n\n" \
|
|
133
|
-
"route do |r|\n" \
|
|
134
|
-
" r.on(\"#{sub_path}\") { r.hash_branches(#{namespace}) }\n" \
|
|
135
|
-
"end\n"
|
|
136
|
-
end
|
|
137
173
|
end
|
|
138
174
|
end
|
|
139
175
|
end
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
class <%= context.const_project_name %> < Roda
|
|
2
2
|
# Routing<% if context.fullstack? %>
|
|
3
|
-
plugin :
|
|
3
|
+
plugin :hash_branch_view_subdir<% end %>
|
|
4
4
|
plugin :autoload_hash_branches
|
|
5
|
-
autoload_hash_branch_dir(
|
|
5
|
+
HASH_BRANCHES.each { |args| autoload_hash_branch_dir(*args) }
|
|
6
|
+
|
|
6
7
|
plugin :all_verbs
|
|
7
8
|
plugin :not_found
|
|
8
9
|
<% if context.fullstack? %>
|
|
@@ -31,11 +31,23 @@ Providers::Mailer.boot
|
|
|
31
31
|
Providers::Logger.boot
|
|
32
32
|
|
|
33
33
|
# Consts<% if context.database %>
|
|
34
|
-
DB = Providers::DB::Conn.get
|
|
34
|
+
DB = Providers::DB::Conn.get<% end %>
|
|
35
|
+
ROUTES_DIR = "./app/routes"
|
|
36
|
+
base_path = Pathname.new(ROUTES_DIR)
|
|
37
|
+
HASH_BRANCHES = []
|
|
38
|
+
HASH_BRANCHES << [base_path]
|
|
39
|
+
Dir.glob(File.join(ROUTES_DIR, "**/*")).each do |dir_path|
|
|
40
|
+
next unless File.directory?(dir_path)
|
|
41
|
+
|
|
42
|
+
path = Pathname.new(dir_path)
|
|
43
|
+
relative_path = path.relative_path_from(base_path).to_s
|
|
44
|
+
|
|
45
|
+
HASH_BRANCHES << [relative_path.to_sym, path.to_s]
|
|
46
|
+
end
|
|
35
47
|
|
|
36
48
|
if Config.not_production?
|
|
37
|
-
require "debug"
|
|
49
|
+
require "debug"<% if context.database %>
|
|
38
50
|
# Automatic models annotations in dev environment
|
|
39
51
|
require 'sequel/annotate'
|
|
40
|
-
Sequel::Annotate.annotate(Dir['app/models/*.rb'], position: :before, border: true) rescue nil
|
|
41
|
-
end
|
|
52
|
+
Sequel::Annotate.annotate(Dir['app/models/*.rb'], position: :before, border: true) rescue nil<% end %>
|
|
53
|
+
end
|
data/lib/roda/project/version.rb
CHANGED