bullet_train-super_scaffolding 1.0.40 → 1.0.43
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- 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 +25 -13
- data/lib/scaffolding/oauth_providers.rb +8 -3
- data/lib/scaffolding/routes_file_manipulator.rb +15 -16
- data/lib/scaffolding/script.rb +4 -4
- data/lib/scaffolding/transformer.rb +51 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 695ce6d408d1cb821d6fd5672b9877f5387ee1dbd4baaeac04c6f51933fd3ad4
|
4
|
+
data.tar.gz: 22fc5ed6ec8df0617560da233a492835354faf636ac010f007116728bd3a36ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4c8d5afb02e06b48107ef53bd95bdf42632587f45a886c89ed3f3ad938f6db80294e4025a896dac89c7e5ece79aa527ea67514fe8b3bbff3446f6e1acb99c1e
|
7
|
+
data.tar.gz: e7a5bfdbda2bccab756affe5b27f82eb94c5d419127be93e6bca0e8dc3f94f9556e6ae8c1bcebf0801e462d4b57c214a7c0d1527b6d9df90f07aa90ec49643ff
|
@@ -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,35 @@ 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
|
-
|
21
|
-
|
18
|
+
# TODO I was running into an error in a downstream application where it couldn't find silence_logs? We should implement it in this package.
|
19
|
+
def self.silence_logs?
|
20
|
+
ENV["SILENCE_LOGS"].present?
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.replace_line_in_file(file, content, in_place_of, options = {})
|
24
|
+
begin
|
25
|
+
target_file_content = File.read(file)
|
26
|
+
rescue Errno::ENOENT => _
|
27
|
+
puts "Couldn't find '#{file}'".red unless options[:suppress_could_not_find]
|
28
|
+
return false
|
29
|
+
end
|
22
30
|
|
23
31
|
if target_file_content.include?(content)
|
24
32
|
puts "No need to update '#{file}'. It already has '#{content}'."
|
25
33
|
else
|
26
|
-
puts "Updating '#{file}'."
|
34
|
+
puts "Updating '#{file}'." unless silence_logs?
|
27
35
|
target_file_content.gsub!(in_place_of, content)
|
28
36
|
File.write(file, target_file_content)
|
29
37
|
end
|
@@ -62,10 +70,14 @@ module Scaffolding::FileManipulator
|
|
62
70
|
File.write(file, new_lines.join)
|
63
71
|
end
|
64
72
|
|
65
|
-
def self.write(file_name, lines)
|
66
|
-
puts "Updating '#{file_name}'."
|
67
|
-
|
68
|
-
|
73
|
+
def self.write(file_name, lines, strip: true)
|
74
|
+
puts "Updating '#{file_name}'." unless silence_logs?
|
75
|
+
if strip
|
76
|
+
File.open(file_name, "w+") do |file|
|
77
|
+
file.puts(lines.join.strip + "\n")
|
78
|
+
end
|
79
|
+
else
|
80
|
+
File.write(file_name, lines.join)
|
69
81
|
end
|
70
82
|
end
|
71
83
|
end
|
@@ -10,8 +10,13 @@ def legacy_resolve_template_path(file)
|
|
10
10
|
end.compact.first || raise("Couldn't find the Super Scaffolding template for `#{file}` in any of the following locations:\n\n#{BulletTrain::SuperScaffolding.template_paths.join("\n")}")
|
11
11
|
end
|
12
12
|
|
13
|
+
# TODO I was running into an error in a downstream application where it couldn't find silence_logs? We should implement it in this package.
|
14
|
+
def silence_logs?
|
15
|
+
ENV["SILENCE_LOGS"].present?
|
16
|
+
end
|
17
|
+
|
13
18
|
def legacy_replace_in_file(file, before, after)
|
14
|
-
puts "Replacing in '#{file}'."
|
19
|
+
puts "Replacing in '#{file}'." unless silence_logs?
|
15
20
|
target_file_content = File.read(file)
|
16
21
|
target_file_content.gsub!(before, after)
|
17
22
|
File.write(file, target_file_content)
|
@@ -58,7 +63,7 @@ def legacy_add_line_to_file(file, content, hook, child, parent, options = {})
|
|
58
63
|
end
|
59
64
|
end
|
60
65
|
|
61
|
-
puts "Updating '#{transformed_file_name}'."
|
66
|
+
puts "Updating '#{transformed_file_name}'." unless silence_logs?
|
62
67
|
|
63
68
|
File.write(transformed_file_name, new_target_file_content.join("\n") + "\n")
|
64
69
|
end
|
@@ -137,7 +142,7 @@ def oauth_scaffold_file(file, options)
|
|
137
142
|
FileUtils.mkdir_p(transformed_directory_name)
|
138
143
|
end
|
139
144
|
|
140
|
-
puts "Writing '#{transformed_file_name}'."
|
145
|
+
puts "Writing '#{transformed_file_name}'." unless silence_logs?
|
141
146
|
|
142
147
|
File.write(transformed_file_name, transformed_file_content)
|
143
148
|
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.
|
@@ -231,21 +231,29 @@ class Scaffolding::Transformer
|
|
231
231
|
transformed_file_content.join
|
232
232
|
end
|
233
233
|
|
234
|
-
|
234
|
+
# TODO I was running into an error in a downstream application where it couldn't find silence_logs? We should implement it in this package.
|
235
|
+
def silence_logs?
|
236
|
+
ENV["SILENCE_LOGS"].present?
|
237
|
+
end
|
238
|
+
|
239
|
+
def scaffold_file(file, overrides: false)
|
235
240
|
transformed_file_content = get_transformed_file_content(file)
|
236
241
|
transformed_file_name = transform_string(file)
|
237
242
|
|
243
|
+
# Remove `_overrides` from the file name if we're sourcing from a local override folder.
|
244
|
+
transformed_file_name.gsub!("_overrides", "") if overrides
|
245
|
+
|
238
246
|
transformed_directory_name = File.dirname(transformed_file_name)
|
239
247
|
unless File.directory?(transformed_directory_name)
|
240
248
|
FileUtils.mkdir_p(transformed_directory_name)
|
241
249
|
end
|
242
250
|
|
243
|
-
puts "Writing '#{transformed_file_name}'."
|
251
|
+
puts "Writing '#{transformed_file_name}'." unless silence_logs?
|
244
252
|
|
245
253
|
File.write(transformed_file_name, transformed_file_content.strip + "\n")
|
246
254
|
|
247
255
|
if transformed_file_name.split(".").last == "rb"
|
248
|
-
puts "Fixing Standard Ruby on '#{transformed_file_name}'."
|
256
|
+
puts "Fixing Standard Ruby on '#{transformed_file_name}'." unless silence_logs?
|
249
257
|
# `standardrb --fix #{transformed_file_name} 2> /dev/null`
|
250
258
|
end
|
251
259
|
end
|
@@ -266,6 +274,22 @@ class Scaffolding::Transformer
|
|
266
274
|
scaffold_file(file)
|
267
275
|
end
|
268
276
|
end
|
277
|
+
|
278
|
+
# Allow local developers to override just certain files of a directory.
|
279
|
+
override_path = begin
|
280
|
+
resolve_template_path(directory + "_overrides")
|
281
|
+
rescue RuntimeError
|
282
|
+
nil
|
283
|
+
end
|
284
|
+
|
285
|
+
if override_path
|
286
|
+
Dir.foreach(override_path) do |file|
|
287
|
+
file = "#{directory}_overrides/#{file}"
|
288
|
+
unless File.directory?(resolve_template_path(file))
|
289
|
+
scaffold_file(file, overrides: true)
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
269
293
|
end
|
270
294
|
|
271
295
|
def add_line_to_file(file, content, hook, options = {})
|
@@ -285,7 +309,7 @@ class Scaffolding::Transformer
|
|
285
309
|
end
|
286
310
|
|
287
311
|
if target_file_content.include?(transformed_content)
|
288
|
-
puts "No need to update '#{transformed_file_name}'. It already has '#{transformed_content}'."
|
312
|
+
puts "No need to update '#{transformed_file_name}'. It already has '#{transformed_content}'." unless silence_logs?
|
289
313
|
|
290
314
|
else
|
291
315
|
|
@@ -335,7 +359,7 @@ class Scaffolding::Transformer
|
|
335
359
|
end
|
336
360
|
end
|
337
361
|
|
338
|
-
puts "Updating '#{transformed_file_name}'."
|
362
|
+
puts "Updating '#{transformed_file_name}'." unless silence_logs?
|
339
363
|
|
340
364
|
File.write(transformed_file_name, new_target_file_content.join("\n").strip + "\n")
|
341
365
|
|
@@ -353,7 +377,7 @@ class Scaffolding::Transformer
|
|
353
377
|
file = transform_string(file)
|
354
378
|
# we specifically don't transform the content, we assume a builder function created this content.
|
355
379
|
in_place_of = transform_string(in_place_of)
|
356
|
-
Scaffolding::FileManipulator.replace_line_in_file(file, content, in_place_of)
|
380
|
+
Scaffolding::FileManipulator.replace_line_in_file(file, content, in_place_of, suppress_could_not_find: suppress_could_not_find)
|
357
381
|
end
|
358
382
|
|
359
383
|
# if class_name isn't specified, we use `child`.
|
@@ -477,7 +501,7 @@ class Scaffolding::Transformer
|
|
477
501
|
end
|
478
502
|
|
479
503
|
def replace_in_file(file, before, after, target_regexp = nil)
|
480
|
-
puts "Replacing in '#{file}'."
|
504
|
+
puts "Replacing in '#{file}'." unless silence_logs?
|
481
505
|
if target_regexp.present?
|
482
506
|
target_file_content = ""
|
483
507
|
File.open(file).each_line do |l|
|
@@ -1047,14 +1071,14 @@ class Scaffolding::Transformer
|
|
1047
1071
|
|
1048
1072
|
assertion = case type
|
1049
1073
|
when "date_field"
|
1050
|
-
"
|
1074
|
+
"assert_equal_or_nil Date.parse(tangible_thing_data['#{name}']), tangible_thing.#{name}"
|
1051
1075
|
when "date_and_time_field"
|
1052
|
-
"
|
1076
|
+
"assert_equal_or_nil DateTime.parse(tangible_thing_data['#{name}']), tangible_thing.#{name}"
|
1053
1077
|
when "file_field"
|
1054
1078
|
# TODO: If we want to use Cloudinary to handle our files, we should make sure we're getting a URL.
|
1055
1079
|
"assert tangible_thing_data['#{name}'].match?('foo.txt') unless response.status == 201"
|
1056
1080
|
else
|
1057
|
-
"
|
1081
|
+
"assert_equal_or_nil tangible_thing_data['#{name}'], tangible_thing.#{name}"
|
1058
1082
|
end
|
1059
1083
|
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
1084
|
end
|
@@ -1085,6 +1109,20 @@ class Scaffolding::Transformer
|
|
1085
1109
|
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
1110
|
end
|
1087
1111
|
end
|
1112
|
+
|
1113
|
+
# We need to update our new Tangible Thing's
|
1114
|
+
# jbuilder files if it's scoped under "account".
|
1115
|
+
# TODO: Should we run this if `namespace.present?` instead?
|
1116
|
+
if namespace == "account"
|
1117
|
+
target_string = "#{transform_string("scaffolding/completely_concrete/tangible_things")}/#{transform_string("tangible_thing")}"
|
1118
|
+
replacement_string = "#{namespace}/#{target_string}"
|
1119
|
+
[
|
1120
|
+
"app/views/account/completely_concrete/tangible_things/index.json.jbuilder",
|
1121
|
+
"app/views/account/completely_concrete/tangible_things/show.json.jbuilder"
|
1122
|
+
].each do |path|
|
1123
|
+
scaffold_replace_line_in_file(path, replacement_string, target_string)
|
1124
|
+
end
|
1125
|
+
end
|
1088
1126
|
end
|
1089
1127
|
|
1090
1128
|
#
|
@@ -1422,8 +1460,9 @@ class Scaffolding::Transformer
|
|
1422
1460
|
|
1423
1461
|
begin
|
1424
1462
|
routes_manipulator.apply([routes_namespace])
|
1425
|
-
rescue
|
1426
|
-
|
1463
|
+
rescue => e
|
1464
|
+
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)
|
1465
|
+
raise e
|
1427
1466
|
end
|
1428
1467
|
|
1429
1468
|
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.43
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Culver
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: standard
|