bullet_train-super_scaffolding 1.0.39 → 1.0.42
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/views/account/scaffolding/completely_concrete/tangible_things/_index.html.erb +1 -0
- data/lib/bullet_train/super_scaffolding/scaffolders/crud_field_scaffolder.rb +1 -1
- data/lib/bullet_train/super_scaffolding/scaffolders/crud_scaffolder.rb +4 -4
- data/lib/bullet_train/super_scaffolding/version.rb +1 -1
- data/lib/scaffolding/block_manipulator.rb +37 -45
- data/lib/scaffolding/file_manipulator.rb +20 -13
- data/lib/scaffolding/oauth_providers.rb +3 -3
- data/lib/scaffolding/routes_file_manipulator.rb +15 -16
- data/lib/scaffolding/script.rb +4 -4
- data/lib/scaffolding/transformer.rb +26 -11
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20c44af78ae7911fc2ef90a78db8d76d7f52f8535b6931a3c1719a84ee8b1104
|
4
|
+
data.tar.gz: 12cabbb8f6530d809d17d9fe9ff3c742e5ac705e296b982df33c55763afb7518
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89ffc20c1fae91cde0bd62b490d1d86aba8ed8ec3dd2f30445c260bab4e326bc9c026a0331d199e6a7942610a5ef5d926ffca38ce0e39bc68129155ec003c8e7
|
7
|
+
data.tar.gz: 1f0ff6f2b787dc6c5aa8d60fbfdacaf70a1f892494ae9e103fd8879ea25113374364cbbd69c172e26e9102e947dd10963f1eb1fef5ec7e8007a0f83e9991dbf8
|
@@ -72,6 +72,7 @@
|
|
72
72
|
<% end %>
|
73
73
|
<% end %>
|
74
74
|
|
75
|
+
<%# 🚅 super scaffolding will insert new targets one parent action model buttons above this line. %>
|
75
76
|
<%# 🚅 super scaffolding will insert new bulk action model buttons above this line. %>
|
76
77
|
<%= render "shared/bulk_action_select" %>
|
77
78
|
|
@@ -36,14 +36,14 @@ module BulletTrain
|
|
36
36
|
parent = parents.first
|
37
37
|
|
38
38
|
unless parents.include?("Team")
|
39
|
-
raise "Parents for #{child} should trace back to the Team model, but Team wasn't provided. Please confirm that all of the parents tracing back to the Team model are present and try again.\n"
|
40
|
-
"E.g.:\n"
|
41
|
-
"rails g model Section page:references title:text body:text\n"
|
39
|
+
raise "Parents for #{child} should trace back to the Team model, but Team wasn't provided. Please confirm that all of the parents tracing back to the Team model are present and try again.\n" \
|
40
|
+
"E.g.:\n" \
|
41
|
+
"rails g model Section page:references title:text body:text\n" \
|
42
42
|
"bin/super-scaffold crud Section Page,Site,Team title:text body:text\n"
|
43
43
|
end
|
44
44
|
|
45
45
|
# get all the attributes.
|
46
|
-
attributes = argv[2
|
46
|
+
attributes = argv[2..]
|
47
47
|
|
48
48
|
check_required_options_for_attributes("crud", attributes, child, parent)
|
49
49
|
|
@@ -1,27 +1,22 @@
|
|
1
|
-
|
2
|
-
attr_accessor :lines
|
3
|
-
|
4
|
-
def initialize(filepath)
|
5
|
-
@filepath = filepath
|
6
|
-
@lines = File.readlines(filepath)
|
7
|
-
end
|
1
|
+
require "scaffolding/file_manipulator"
|
8
2
|
|
3
|
+
module Scaffolding::BlockManipulator
|
9
4
|
#
|
10
5
|
# Wrap a block of ruby code with another block on the outside.
|
11
6
|
#
|
12
7
|
# @param [String] `starting` A string to search for at the start of the block. Eg "<%= updates_for context, collection do"
|
13
8
|
# @param [Array] `with` An array with two String elements. The text that should wrap the block. Eg ["<%= action_model_select_controller do %>", "<% end %>"]
|
14
9
|
#
|
15
|
-
def wrap_block(starting:, with:)
|
10
|
+
def self.wrap_block(starting:, with:, lines:)
|
16
11
|
with[0] += "\n" unless with[0].match?(/\n$/)
|
17
12
|
with[1] += "\n" unless with[1].match?(/\n$/)
|
18
|
-
starting_line = find_block_start(starting)
|
19
|
-
end_line = find_block_end(starting_from: starting_line, lines:
|
13
|
+
starting_line = find_block_start(starting_from: starting, lines: lines)
|
14
|
+
end_line = find_block_end(starting_from: starting_line, lines: lines)
|
20
15
|
|
21
16
|
final = []
|
22
17
|
block_indent = ""
|
23
18
|
spacer = " "
|
24
|
-
|
19
|
+
lines.each_with_index do |line, index|
|
25
20
|
line += "\n" unless line.match?(/\n$/)
|
26
21
|
if index < starting_line
|
27
22
|
final << line
|
@@ -39,80 +34,77 @@ class Scaffolding::BlockManipulator
|
|
39
34
|
end
|
40
35
|
end
|
41
36
|
|
42
|
-
|
43
|
-
unless
|
44
|
-
|
37
|
+
lines = final
|
38
|
+
unless lines.last.match?(/\n$/)
|
39
|
+
lines[-1] += "\n"
|
45
40
|
end
|
41
|
+
lines
|
46
42
|
end
|
47
43
|
|
48
|
-
def insert(content, within: nil, after: nil, before: nil, after_block: nil, append: false)
|
44
|
+
def self.insert(content, lines:, within: nil, after: nil, before: nil, after_block: nil, append: false)
|
49
45
|
# Search for before like we do after, we'll just inject before it.
|
50
46
|
after ||= before
|
51
47
|
|
52
48
|
# If within is given, find the start and end lines of the block
|
53
49
|
content += "\n" unless content.match?(/\n$/)
|
54
50
|
start_line = 0
|
55
|
-
end_line =
|
51
|
+
end_line = lines.count - 1
|
56
52
|
if within.present?
|
57
|
-
start_line = find_block_start(within)
|
58
|
-
end_line = find_block_end(starting_from: start_line, lines:
|
53
|
+
start_line = find_block_start(starting_from: within, lines: lines)
|
54
|
+
end_line = find_block_end(starting_from: start_line, lines: lines)
|
59
55
|
# start_line += 1 # ensure we actually insert the content _within_ the given block
|
60
56
|
# end_line += 1 if end_line == start_line
|
61
57
|
end
|
62
58
|
if after_block.present?
|
63
|
-
block_start = find_block_start(after_block)
|
64
|
-
block_end = find_block_end(starting_from: block_start, lines:
|
59
|
+
block_start = find_block_start(starting_from: after_block, lines: lines)
|
60
|
+
block_end = find_block_end(starting_from: block_start, lines: lines)
|
65
61
|
start_line = block_end
|
66
|
-
end_line =
|
62
|
+
end_line = lines.count - 1
|
67
63
|
end
|
68
64
|
index = start_line
|
69
65
|
match = false
|
70
66
|
while index < end_line && !match
|
71
|
-
line =
|
67
|
+
line = lines[index]
|
72
68
|
if after.nil? || line.match?(after)
|
73
69
|
unless append
|
74
70
|
match = true
|
75
71
|
# We adjust the injection point if we really wanted to insert before.
|
76
|
-
insert_line(content, index - (before ? 1 : 0))
|
72
|
+
lines = insert_line(content, index - (before ? 1 : 0), lines)
|
77
73
|
end
|
78
74
|
end
|
79
75
|
index += 1
|
80
76
|
end
|
81
77
|
|
82
|
-
return if match
|
78
|
+
return lines if match
|
83
79
|
|
84
80
|
# Match should always be false here.
|
85
81
|
if append && !match
|
86
|
-
insert_line(content, index - 1)
|
82
|
+
lines = insert_line(content, index - 1, lines)
|
87
83
|
end
|
84
|
+
lines
|
88
85
|
end
|
89
86
|
|
90
|
-
def insert_line(content, insert_at_index)
|
87
|
+
def self.insert_line(content, insert_at_index, lines)
|
91
88
|
content += "\n" unless content.match?(/\n$/)
|
92
89
|
final = []
|
93
|
-
|
90
|
+
lines.each_with_index do |line, index|
|
94
91
|
indent = line.match(/^\s*/).to_s
|
95
92
|
final << line
|
96
93
|
if index == insert_at_index
|
97
94
|
final << indent + content
|
98
95
|
end
|
99
96
|
end
|
100
|
-
|
101
|
-
end
|
102
|
-
|
103
|
-
def insert_block(block_content, after_block:)
|
104
|
-
block_start = find_block_start(after_block)
|
105
|
-
block_end = find_block_end(starting_from: block_start, lines: @lines)
|
106
|
-
insert_line(block_content[0], block_end)
|
107
|
-
insert_line(block_content[1], block_end + 1)
|
97
|
+
final
|
108
98
|
end
|
109
99
|
|
110
|
-
|
111
|
-
|
112
|
-
|
100
|
+
def self.insert_block(block_content, after_block:, lines:)
|
101
|
+
block_start = find_block_start(starting_from: after_block, lines: lines)
|
102
|
+
block_end = find_block_end(starting_from: block_start, lines: lines)
|
103
|
+
lines = insert_line(block_content[0], block_end, lines)
|
104
|
+
insert_line(block_content[1], block_end + 1, lines)
|
113
105
|
end
|
114
106
|
|
115
|
-
def find_block_parent(starting_line_number, lines)
|
107
|
+
def self.find_block_parent(starting_line_number, lines)
|
116
108
|
return nil unless indentation_of(starting_line_number, lines)
|
117
109
|
cursor = starting_line_number
|
118
110
|
while cursor >= 0
|
@@ -124,11 +116,11 @@ class Scaffolding::BlockManipulator
|
|
124
116
|
nil
|
125
117
|
end
|
126
118
|
|
127
|
-
def find_block_start(
|
128
|
-
matcher = Regexp.escape(
|
119
|
+
def self.find_block_start(starting_from:, lines:)
|
120
|
+
matcher = Regexp.escape(starting_from)
|
129
121
|
starting_line = 0
|
130
122
|
|
131
|
-
|
123
|
+
lines.each_with_index do |line, index|
|
132
124
|
if line.match?(matcher)
|
133
125
|
starting_line = index
|
134
126
|
break
|
@@ -137,7 +129,7 @@ class Scaffolding::BlockManipulator
|
|
137
129
|
starting_line
|
138
130
|
end
|
139
131
|
|
140
|
-
def find_block_end(starting_from:, lines:)
|
132
|
+
def self.find_block_end(starting_from:, lines:)
|
141
133
|
# This loop was previously in the RoutesFileManipulator.
|
142
134
|
lines.each_with_index do |line, line_number|
|
143
135
|
next unless line_number > starting_from
|
@@ -148,7 +140,7 @@ class Scaffolding::BlockManipulator
|
|
148
140
|
|
149
141
|
depth = 0
|
150
142
|
current_line = starting_from
|
151
|
-
|
143
|
+
lines[starting_from..lines.count].each_with_index do |line, index|
|
152
144
|
current_line = starting_from + index
|
153
145
|
depth += 1 if line.match?(/\s*<%.+ do .*%>/)
|
154
146
|
depth += 1 if line.match?(/\s*<% if .*%>/)
|
@@ -162,7 +154,7 @@ class Scaffolding::BlockManipulator
|
|
162
154
|
# TODO: We shouldn't need this second argument, but since
|
163
155
|
# we have `lines` here and in the RoutesFileManipulator,
|
164
156
|
# the lines diverge from one another when we edit them individually.
|
165
|
-
def indentation_of(line_number, lines)
|
157
|
+
def self.indentation_of(line_number, lines)
|
166
158
|
lines[line_number].match(/^( +)/)[1]
|
167
159
|
rescue
|
168
160
|
nil
|
@@ -3,27 +3,30 @@ require "scaffolding/block_manipulator"
|
|
3
3
|
# TODO: If we move this and the BlockManipulator into their own gems,
|
4
4
|
# we can probably call these methods with something shorter without `Scaffolding::`.
|
5
5
|
module Scaffolding::FileManipulator
|
6
|
-
|
7
|
-
|
8
|
-
lines_within(lines, within, block_manipulator).each_with_index do |line, line_number|
|
6
|
+
def self.find(lines, needle, within = nil)
|
7
|
+
lines_within(lines, within).each_with_index do |line, line_number|
|
9
8
|
return (within + (within ? 1 : 0) + line_number) if line.match?(needle)
|
10
9
|
end
|
11
10
|
nil
|
12
11
|
end
|
13
12
|
|
14
|
-
|
15
|
-
def self.lines_within(lines, within, block_manipulator)
|
13
|
+
def self.lines_within(lines, within)
|
16
14
|
return lines unless within
|
17
|
-
lines[(within + 1)..(
|
15
|
+
lines[(within + 1)..(Scaffolding::BlockManipulator.find_block_end(starting_from: within, lines: lines) + 1)]
|
18
16
|
end
|
19
17
|
|
20
|
-
def self.replace_line_in_file(file, content, in_place_of)
|
21
|
-
|
18
|
+
def self.replace_line_in_file(file, content, in_place_of, options = {})
|
19
|
+
begin
|
20
|
+
target_file_content = File.read(file)
|
21
|
+
rescue Errno::ENOENT => _
|
22
|
+
puts "Couldn't find '#{file}'".red unless options[:suppress_could_not_find]
|
23
|
+
return false
|
24
|
+
end
|
22
25
|
|
23
26
|
if target_file_content.include?(content)
|
24
27
|
puts "No need to update '#{file}'. It already has '#{content}'."
|
25
28
|
else
|
26
|
-
puts "Updating '#{file}'."
|
29
|
+
puts "Updating '#{file}'." unless silence_logs?
|
27
30
|
target_file_content.gsub!(in_place_of, content)
|
28
31
|
File.write(file, target_file_content)
|
29
32
|
end
|
@@ -62,10 +65,14 @@ module Scaffolding::FileManipulator
|
|
62
65
|
File.write(file, new_lines.join)
|
63
66
|
end
|
64
67
|
|
65
|
-
def self.write(file_name, lines)
|
66
|
-
puts "Updating '#{file_name}'."
|
67
|
-
|
68
|
-
|
68
|
+
def self.write(file_name, lines, strip: true)
|
69
|
+
puts "Updating '#{file_name}'." unless ENV["SILENCE_LOGS"].present?
|
70
|
+
if strip
|
71
|
+
File.open(file_name, "w+") do |file|
|
72
|
+
file.puts(lines.join.strip + "\n")
|
73
|
+
end
|
74
|
+
else
|
75
|
+
File.write(file_name, lines.join)
|
69
76
|
end
|
70
77
|
end
|
71
78
|
end
|
@@ -11,7 +11,7 @@ def legacy_resolve_template_path(file)
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def legacy_replace_in_file(file, before, after)
|
14
|
-
puts "Replacing in '#{file}'."
|
14
|
+
puts "Replacing in '#{file}'." unless silence_logs?
|
15
15
|
target_file_content = File.read(file)
|
16
16
|
target_file_content.gsub!(before, after)
|
17
17
|
File.write(file, target_file_content)
|
@@ -58,7 +58,7 @@ def legacy_add_line_to_file(file, content, hook, child, parent, options = {})
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
puts "Updating '#{transformed_file_name}'."
|
61
|
+
puts "Updating '#{transformed_file_name}'." unless silence_logs?
|
62
62
|
|
63
63
|
File.write(transformed_file_name, new_target_file_content.join("\n") + "\n")
|
64
64
|
end
|
@@ -137,7 +137,7 @@ def oauth_scaffold_file(file, options)
|
|
137
137
|
FileUtils.mkdir_p(transformed_directory_name)
|
138
138
|
end
|
139
139
|
|
140
|
-
puts "Writing '#{transformed_file_name}'."
|
140
|
+
puts "Writing '#{transformed_file_name}'." unless silence_logs?
|
141
141
|
|
142
142
|
File.write(transformed_file_name, transformed_file_content)
|
143
143
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "scaffolding/block_manipulator"
|
2
2
|
|
3
3
|
class Scaffolding::RoutesFileManipulator
|
4
|
-
attr_accessor :child, :parent, :lines, :transformer_options
|
4
|
+
attr_accessor :child, :parent, :lines, :transformer_options
|
5
5
|
|
6
6
|
def initialize(filename, child, parent, transformer_options = {})
|
7
7
|
self.child = child
|
@@ -9,7 +9,6 @@ class Scaffolding::RoutesFileManipulator
|
|
9
9
|
@filename = filename
|
10
10
|
self.lines = File.readlines(@filename)
|
11
11
|
self.transformer_options = transformer_options
|
12
|
-
self.block_manipulator = Scaffolding::BlockManipulator.new(@filename)
|
13
12
|
end
|
14
13
|
|
15
14
|
def child_parts
|
@@ -68,7 +67,7 @@ class Scaffolding::RoutesFileManipulator
|
|
68
67
|
def find_namespaces(namespaces, within = nil)
|
69
68
|
namespaces = namespaces.dup
|
70
69
|
results = {}
|
71
|
-
block_end =
|
70
|
+
block_end = Scaffolding::BlockManipulator.find_block_end(starting_from: within, lines: lines) if within
|
72
71
|
lines.each_with_index do |line, line_number|
|
73
72
|
if within
|
74
73
|
next unless line_number > within
|
@@ -86,7 +85,7 @@ class Scaffolding::RoutesFileManipulator
|
|
86
85
|
def insert_before(new_lines, line_number, options = {})
|
87
86
|
options[:indent] ||= false
|
88
87
|
before = lines[0..(line_number - 1)]
|
89
|
-
new_lines = new_lines.map { |line| (
|
88
|
+
new_lines = new_lines.map { |line| (Scaffolding::BlockManipulator.indentation_of(line_number, lines) + (options[:indent] ? " " : "") + line).gsub(/\s+$/, "") + "\n" }
|
90
89
|
after = lines[line_number..]
|
91
90
|
self.lines = before + (options[:prepend_newline] ? ["\n"] : []) + new_lines + after
|
92
91
|
end
|
@@ -95,7 +94,7 @@ class Scaffolding::RoutesFileManipulator
|
|
95
94
|
def insert_after(new_lines, line_number, options = {})
|
96
95
|
options[:indent] ||= false
|
97
96
|
before = lines[0..line_number]
|
98
|
-
new_lines = new_lines.map { |line| (
|
97
|
+
new_lines = new_lines.map { |line| (Scaffolding::BlockManipulator.indentation_of(line_number, lines) + (options[:indent] ? " " : "") + line).gsub(/\s+$/, "") + "\n" }
|
99
98
|
after = lines[(line_number + 1)..]
|
100
99
|
self.lines = before + new_lines + (options[:append_newline] ? ["\n"] : []) + after
|
101
100
|
end
|
@@ -104,7 +103,7 @@ class Scaffolding::RoutesFileManipulator
|
|
104
103
|
namespace_lines = find_namespaces(namespaces, within)
|
105
104
|
if namespace_lines[namespaces.last]
|
106
105
|
block_start = namespace_lines[namespaces.last]
|
107
|
-
insertion_point =
|
106
|
+
insertion_point = Scaffolding::BlockManipulator.find_block_end(starting_from: block_start, lines: lines)
|
108
107
|
insert_before(new_lines, insertion_point, indent: true, prepend_newline: (insertion_point > block_start + 1))
|
109
108
|
else
|
110
109
|
raise "we weren't able to insert the following lines into the namespace block for #{namespaces.join(" -> ")}:\n\n#{new_lines.join("\n")}"
|
@@ -172,7 +171,7 @@ class Scaffolding::RoutesFileManipulator
|
|
172
171
|
within = namespace_lines[namespaces.last]
|
173
172
|
end
|
174
173
|
|
175
|
-
Scaffolding::FileManipulator.lines_within(lines, within
|
174
|
+
Scaffolding::FileManipulator.lines_within(lines, within).each_with_index do |line, line_number|
|
176
175
|
# + 2 because line_number starts from 0, and within starts one line after
|
177
176
|
actual_line_number = (within + line_number + 2)
|
178
177
|
|
@@ -226,7 +225,7 @@ class Scaffolding::RoutesFileManipulator
|
|
226
225
|
# However, will not find namespace blocks inside namespace blocks.
|
227
226
|
def top_level_namespace_block_lines(within)
|
228
227
|
local_namespace_blocks = []
|
229
|
-
Scaffolding::FileManipulator.lines_within(lines, within
|
228
|
+
Scaffolding::FileManipulator.lines_within(lines, within).each do |line|
|
230
229
|
# i.e. - Retrieve "foo" from "namespace :foo do"
|
231
230
|
match_data = line.match(/(\s*namespace\s:)(.*)(\sdo$)/)
|
232
231
|
|
@@ -236,7 +235,7 @@ class Scaffolding::RoutesFileManipulator
|
|
236
235
|
namespace_name = match_data[2]
|
237
236
|
local_namespace = find_namespaces([namespace_name], within)
|
238
237
|
starting_line_number = local_namespace[namespace_name]
|
239
|
-
local_namespace_block = ((starting_line_number + 1)..(
|
238
|
+
local_namespace_block = ((starting_line_number + 1)..(Scaffolding::BlockManipulator.find_block_end(starting_from: starting_line_number, lines: lines) + 1))
|
240
239
|
|
241
240
|
if local_namespace_blocks.empty?
|
242
241
|
local_namespace_blocks << local_namespace_block
|
@@ -263,11 +262,11 @@ class Scaffolding::RoutesFileManipulator
|
|
263
262
|
def namespace_blocks_directly_under_parent(within)
|
264
263
|
blocks = []
|
265
264
|
if lines[within].match?(/do$/)
|
266
|
-
parent_indentation_size =
|
267
|
-
within_block_end =
|
265
|
+
parent_indentation_size = Scaffolding::BlockManipulator.indentation_of(within, lines).length
|
266
|
+
within_block_end = Scaffolding::BlockManipulator.find_block_end(starting_from: within, lines: lines)
|
268
267
|
within.upto(within_block_end) do |line_number|
|
269
268
|
if lines[line_number].match?(/^#{" " * (parent_indentation_size + 2)}namespace/)
|
270
|
-
namespace_block_lines = line_number..
|
269
|
+
namespace_block_lines = line_number..Scaffolding::BlockManipulator.find_block_end(starting_from: line_number, lines: lines)
|
271
270
|
blocks << namespace_block_lines
|
272
271
|
end
|
273
272
|
end
|
@@ -301,7 +300,7 @@ class Scaffolding::RoutesFileManipulator
|
|
301
300
|
|
302
301
|
# TODO: Remove this and use the BlockManipulator
|
303
302
|
def insert(lines_to_add, within)
|
304
|
-
insertion_line =
|
303
|
+
insertion_line = Scaffolding::BlockManipulator.find_block_end(starting_from: within, lines: lines)
|
305
304
|
result_line = insertion_line
|
306
305
|
unless insertion_line == within + 1
|
307
306
|
# only put the extra space if we're adding this line after a block
|
@@ -333,7 +332,7 @@ class Scaffolding::RoutesFileManipulator
|
|
333
332
|
# add the new resource within that namespace.
|
334
333
|
line = "scope module: '#{parent_resource}' do"
|
335
334
|
# TODO you haven't tested this yet.
|
336
|
-
unless (scope_within = Scaffolding::FileManipulator.find(lines, /#{line}/, parent_within
|
335
|
+
unless (scope_within = Scaffolding::FileManipulator.find(lines, /#{line}/, parent_within))
|
337
336
|
scope_within = insert([line, "end"], parent_within)
|
338
337
|
end
|
339
338
|
|
@@ -345,7 +344,7 @@ class Scaffolding::RoutesFileManipulator
|
|
345
344
|
|
346
345
|
# We want to see if there are any namespaces one level above the parent itself,
|
347
346
|
# because namespaces with the same name as the resource can exist on the same level.
|
348
|
-
parent_block_start =
|
347
|
+
parent_block_start = Scaffolding::BlockManipulator.find_block_parent(parent_within, lines)
|
349
348
|
namespace_line_within = find_or_create_namespaces(child_namespaces, parent_block_start)
|
350
349
|
find_or_create_resource([child_resource], options: "except: collection_actions", within: namespace_line_within)
|
351
350
|
unless find_namespaces(child_namespaces, within)[child_namespaces.last]
|
@@ -364,7 +363,7 @@ class Scaffolding::RoutesFileManipulator
|
|
364
363
|
# resources :projects_deliverables, path: 'projects/deliverables' do
|
365
364
|
# resources :objectives
|
366
365
|
# end
|
367
|
-
block_parent_within =
|
366
|
+
block_parent_within = Scaffolding::BlockManipulator.find_block_parent(top_parent_namespace, lines)
|
368
367
|
parent_namespaces_and_resource = (parent_namespaces + [parent_resource]).join("_")
|
369
368
|
parent_within = find_or_create_resource_block([parent_namespaces_and_resource], options: "path: '#{parent_namespaces_and_resource.tr("_", "/")}'", within: block_parent_within)
|
370
369
|
find_or_create_resource(child_namespaces + [child_resource], within: parent_within)
|
data/lib/scaffolding/script.rb
CHANGED
@@ -15,7 +15,7 @@ argv = []
|
|
15
15
|
@options = {}
|
16
16
|
ARGV.each do |arg|
|
17
17
|
if arg[0..1] == "--"
|
18
|
-
arg = arg[2
|
18
|
+
arg = arg[2..]
|
19
19
|
if arg.split("=").count > 1
|
20
20
|
@options[arg.split("=")[0]] = arg.split("=")[1]
|
21
21
|
else
|
@@ -38,9 +38,9 @@ def check_required_options_for_attributes(scaffolding_type, attributes, child, p
|
|
38
38
|
type = parts.join(":")
|
39
39
|
|
40
40
|
unless Scaffolding.valid_attribute_type?(type)
|
41
|
-
raise "You have entered an invalid attribute type: #{type}. General data types are used when creating new models, but Bullet Train "
|
42
|
-
|
43
|
-
|
41
|
+
raise "You have entered an invalid attribute type: #{type}. General data types are used when creating new models, but Bullet Train " \
|
42
|
+
"uses field partials when Super Scaffolding, i.e. - `name:text_field` as opposed to `name:string`. " \
|
43
|
+
"Please refer to the Field Partial documentation to view which attribute types are available."
|
44
44
|
end
|
45
45
|
|
46
46
|
# extract any options they passed in with the field.
|
@@ -240,12 +240,12 @@ class Scaffolding::Transformer
|
|
240
240
|
FileUtils.mkdir_p(transformed_directory_name)
|
241
241
|
end
|
242
242
|
|
243
|
-
puts "Writing '#{transformed_file_name}'."
|
243
|
+
puts "Writing '#{transformed_file_name}'." unless silence_logs?
|
244
244
|
|
245
245
|
File.write(transformed_file_name, transformed_file_content.strip + "\n")
|
246
246
|
|
247
247
|
if transformed_file_name.split(".").last == "rb"
|
248
|
-
puts "Fixing Standard Ruby on '#{transformed_file_name}'."
|
248
|
+
puts "Fixing Standard Ruby on '#{transformed_file_name}'." unless silence_logs?
|
249
249
|
# `standardrb --fix #{transformed_file_name} 2> /dev/null`
|
250
250
|
end
|
251
251
|
end
|
@@ -285,7 +285,7 @@ class Scaffolding::Transformer
|
|
285
285
|
end
|
286
286
|
|
287
287
|
if target_file_content.include?(transformed_content)
|
288
|
-
puts "No need to update '#{transformed_file_name}'. It already has '#{transformed_content}'."
|
288
|
+
puts "No need to update '#{transformed_file_name}'. It already has '#{transformed_content}'." unless silence_logs?
|
289
289
|
|
290
290
|
else
|
291
291
|
|
@@ -335,7 +335,7 @@ class Scaffolding::Transformer
|
|
335
335
|
end
|
336
336
|
end
|
337
337
|
|
338
|
-
puts "Updating '#{transformed_file_name}'."
|
338
|
+
puts "Updating '#{transformed_file_name}'." unless silence_logs?
|
339
339
|
|
340
340
|
File.write(transformed_file_name, new_target_file_content.join("\n").strip + "\n")
|
341
341
|
|
@@ -353,7 +353,7 @@ class Scaffolding::Transformer
|
|
353
353
|
file = transform_string(file)
|
354
354
|
# we specifically don't transform the content, we assume a builder function created this content.
|
355
355
|
in_place_of = transform_string(in_place_of)
|
356
|
-
Scaffolding::FileManipulator.replace_line_in_file(file, content, in_place_of)
|
356
|
+
Scaffolding::FileManipulator.replace_line_in_file(file, content, in_place_of, suppress_could_not_find: suppress_could_not_find)
|
357
357
|
end
|
358
358
|
|
359
359
|
# if class_name isn't specified, we use `child`.
|
@@ -477,7 +477,7 @@ class Scaffolding::Transformer
|
|
477
477
|
end
|
478
478
|
|
479
479
|
def replace_in_file(file, before, after, target_regexp = nil)
|
480
|
-
puts "Replacing in '#{file}'."
|
480
|
+
puts "Replacing in '#{file}'." unless silence_logs?
|
481
481
|
if target_regexp.present?
|
482
482
|
target_file_content = ""
|
483
483
|
File.open(file).each_line do |l|
|
@@ -1047,14 +1047,14 @@ class Scaffolding::Transformer
|
|
1047
1047
|
|
1048
1048
|
assertion = case type
|
1049
1049
|
when "date_field"
|
1050
|
-
"
|
1050
|
+
"assert_equal_or_nil Date.parse(tangible_thing_data['#{name}']), tangible_thing.#{name}"
|
1051
1051
|
when "date_and_time_field"
|
1052
|
-
"
|
1052
|
+
"assert_equal_or_nil DateTime.parse(tangible_thing_data['#{name}']), tangible_thing.#{name}"
|
1053
1053
|
when "file_field"
|
1054
1054
|
# TODO: If we want to use Cloudinary to handle our files, we should make sure we're getting a URL.
|
1055
1055
|
"assert tangible_thing_data['#{name}'].match?('foo.txt') unless response.status == 201"
|
1056
1056
|
else
|
1057
|
-
"
|
1057
|
+
"assert_equal_or_nil tangible_thing_data['#{name}'], tangible_thing.#{name}"
|
1058
1058
|
end
|
1059
1059
|
scaffold_add_line_to_file("./test/controllers/api/v1/scaffolding/completely_concrete/tangible_things_endpoint_test.rb", assertion, RUBY_NEW_FIELDS_HOOK, prepend: true)
|
1060
1060
|
end
|
@@ -1085,6 +1085,20 @@ class Scaffolding::Transformer
|
|
1085
1085
|
scaffold_add_line_to_file("./test/controllers/api/v1/scaffolding/completely_concrete/tangible_things_endpoint_test.rb", "assert_equal @tangible_thing.#{name}, #{attribute_assignment}", RUBY_EVEN_MORE_NEW_FIELDS_HOOK, prepend: true)
|
1086
1086
|
end
|
1087
1087
|
end
|
1088
|
+
|
1089
|
+
# We need to update our new Tangible Thing's
|
1090
|
+
# jbuilder files if it's scoped under "account".
|
1091
|
+
# TODO: Should we run this if `namespace.present?` instead?
|
1092
|
+
if namespace == "account"
|
1093
|
+
target_string = "#{transform_string("scaffolding/completely_concrete/tangible_things")}/#{transform_string("tangible_thing")}"
|
1094
|
+
replacement_string = "#{namespace}/#{target_string}"
|
1095
|
+
[
|
1096
|
+
"app/views/account/completely_concrete/tangible_things/index.json.jbuilder",
|
1097
|
+
"app/views/account/completely_concrete/tangible_things/show.json.jbuilder"
|
1098
|
+
].each do |path|
|
1099
|
+
scaffold_replace_line_in_file(path, replacement_string, target_string)
|
1100
|
+
end
|
1101
|
+
end
|
1088
1102
|
end
|
1089
1103
|
|
1090
1104
|
#
|
@@ -1422,8 +1436,9 @@ class Scaffolding::Transformer
|
|
1422
1436
|
|
1423
1437
|
begin
|
1424
1438
|
routes_manipulator.apply([routes_namespace])
|
1425
|
-
rescue
|
1426
|
-
|
1439
|
+
rescue => e
|
1440
|
+
puts "We weren't able to automatically add your `#{routes_namespace}` routes for you. In theory this should be very rare, so if you could reach out on Slack, you could probably provide context that will help us fix whatever the problem was. In the meantime, to add the routes manually, we've got a guide at https://blog.bullettrain.co/nested-namespaced-rails-routing-examples/ .".send(:yellow)
|
1441
|
+
raise e
|
1427
1442
|
end
|
1428
1443
|
|
1429
1444
|
Scaffolding::FileManipulator.write("config/routes.rb", routes_manipulator.lines)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bullet_train-super_scaffolding
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.42
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Culver
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: standard
|
@@ -178,7 +178,7 @@ licenses:
|
|
178
178
|
metadata:
|
179
179
|
homepage_uri: https://github.com/bullet-train-co/bullet_train-super_scaffolding
|
180
180
|
source_code_uri: https://github.com/bullet-train-co/bullet_train-super_scaffolding
|
181
|
-
post_install_message:
|
181
|
+
post_install_message:
|
182
182
|
rdoc_options: []
|
183
183
|
require_paths:
|
184
184
|
- lib
|
@@ -193,8 +193,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
195
|
requirements: []
|
196
|
-
rubygems_version: 3.
|
197
|
-
signing_key:
|
196
|
+
rubygems_version: 3.3.7
|
197
|
+
signing_key:
|
198
198
|
specification_version: 4
|
199
199
|
summary: Bullet Train Super Scaffolding
|
200
200
|
test_files: []
|