bullet_train-super_scaffolding 1.0.4 → 1.0.8
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/engine.rb +8 -0
- data/lib/bullet_train/super_scaffolding/scaffolders/crud_field_scaffolder.rb +1 -1
- data/lib/bullet_train/super_scaffolding/scaffolders/crud_scaffolder.rb +1 -3
- data/lib/bullet_train/super_scaffolding/version.rb +1 -1
- data/lib/bullet_train/super_scaffolding.rb +1 -1
- data/lib/scaffolding/block_manipulator.rb +140 -0
- data/lib/scaffolding/script.rb +1 -0
- data/lib/scaffolding/transformer.rb +4 -3
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfdc2fb6d3d94d5db53ecf46bd69b01cb429fa35d3e3d73439e98baf37badee6
|
4
|
+
data.tar.gz: bb887c194a7c8e0bba622991344f846db4aa420b1474927fd2f4ad4d5a57de7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcb7b79415897ad6e756d102295ddc78b59c2015e3410c6a31fb681c7b92066bf82bc9cf758e7a9d3e57b8dc2623e3402d9380c6f4434661b50476a345a21fe2
|
7
|
+
data.tar.gz: 14ff4eaad35e66d4c7cc55f06c753b4a9e008457956f124603a722308d81520c97ee34cbefdbf27bdd45050f6c41d13d4ac01eb0fbe9c18d93cf9a8517032046
|
@@ -1,6 +1,14 @@
|
|
1
1
|
module BulletTrain
|
2
2
|
module SuperScaffolding
|
3
3
|
class Engine < ::Rails::Engine
|
4
|
+
initializer "bullet_train.super_scaffolding.register_template_path" do |app|
|
5
|
+
# Templates from the application itself should always be highest priority.
|
6
|
+
# This allows application developers to locally overload any template from any package.
|
7
|
+
BulletTrain::SuperScaffolding.template_paths << Rails.root.to_s
|
8
|
+
|
9
|
+
# Register the base path of this package with the Super Scaffolding engine.
|
10
|
+
BulletTrain::SuperScaffolding.template_paths << File.expand_path("../../../..", __FILE__)
|
11
|
+
end
|
4
12
|
end
|
5
13
|
end
|
6
14
|
end
|
@@ -26,7 +26,7 @@ module BulletTrain
|
|
26
26
|
# get all the attributes.
|
27
27
|
attributes = argv[1..-1]
|
28
28
|
|
29
|
-
check_required_options_for_attributes(
|
29
|
+
check_required_options_for_attributes("crud-field", attributes, child)
|
30
30
|
|
31
31
|
transformer = Scaffolding::Transformer.new(child, parents, @options)
|
32
32
|
transformer.add_attributes_to_various_views(attributes, type: :crud_field)
|
@@ -45,9 +45,7 @@ module BulletTrain
|
|
45
45
|
# get all the attributes.
|
46
46
|
attributes = argv[2..-1]
|
47
47
|
|
48
|
-
check_required_options_for_attributes(
|
49
|
-
|
50
|
-
binding.pry
|
48
|
+
check_required_options_for_attributes("crud", attributes, child, parent)
|
51
49
|
|
52
50
|
transformer = Scaffolding::Transformer.new(child, parents, @options)
|
53
51
|
transformer.scaffold_crud(attributes)
|
@@ -13,7 +13,7 @@ module BulletTrain
|
|
13
13
|
"crud" => "BulletTrain::SuperScaffolding::Scaffolders::CrudScaffolder",
|
14
14
|
"crud-field" => "BulletTrain::SuperScaffolding::Scaffolders::CrudFieldScaffolder",
|
15
15
|
"join-model" => "BulletTrain::SuperScaffolding::Scaffolders::JoinModelScaffolder",
|
16
|
-
"oauth-provider" => "BulletTrain::SuperScaffolding::Scaffolders::OauthProviderScaffolder"
|
16
|
+
"oauth-provider" => "BulletTrain::SuperScaffolding::Scaffolders::OauthProviderScaffolder"
|
17
17
|
}
|
18
18
|
|
19
19
|
class Runner
|
@@ -0,0 +1,140 @@
|
|
1
|
+
class Scaffolding::BlockManipulator
|
2
|
+
attr_accessor :lines
|
3
|
+
|
4
|
+
def initialize(filepath)
|
5
|
+
@filepath = filepath
|
6
|
+
@lines = File.readlines(filepath)
|
7
|
+
end
|
8
|
+
|
9
|
+
#
|
10
|
+
# Wrap a block of ruby code inside another block
|
11
|
+
#
|
12
|
+
# @param [String] starting A string to search for at the start of the block. Eg "<%= updates_for context, collection do"
|
13
|
+
# @param [Array] with An array with two String elements. The text that should wrap the block. Eg ["<%= action_model_select_controller do %>", "<% end %>"]
|
14
|
+
#
|
15
|
+
def wrap_block(starting:, with:)
|
16
|
+
with[0] += "\n" unless with[0].match?(/\n$/)
|
17
|
+
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)
|
20
|
+
|
21
|
+
final = []
|
22
|
+
block_indent = ""
|
23
|
+
spacer = " "
|
24
|
+
@lines.each_with_index do |line, index|
|
25
|
+
line += "\n" unless line.match?(/\n$/)
|
26
|
+
if index < starting_line
|
27
|
+
final << line
|
28
|
+
elsif index == starting_line
|
29
|
+
block_indent = line.match(/^\s*/).to_s
|
30
|
+
final << block_indent + with[0]
|
31
|
+
final << (line.blank? ? "\n" : "#{spacer}#{line}")
|
32
|
+
elsif index > starting_line && index < end_line
|
33
|
+
final << (line.blank? ? "\n" : "#{spacer}#{line}")
|
34
|
+
elsif index == end_line
|
35
|
+
final << (line.blank? ? "\n" : "#{spacer}#{line}")
|
36
|
+
final << block_indent + with[1]
|
37
|
+
else
|
38
|
+
final << line
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
@lines = final
|
43
|
+
unless @lines.last.match?(/\n$/)
|
44
|
+
@lines.last += "\n"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def insert(content, within: nil, after: nil, before: nil, after_block: nil, append: false)
|
49
|
+
# Search for before like we do after, we'll just inject before it.
|
50
|
+
after ||= before
|
51
|
+
|
52
|
+
# If within is given, find the start and end lines of the block
|
53
|
+
content += "\n" unless content.match?(/\n$/)
|
54
|
+
start_line = 0
|
55
|
+
end_line = @lines.count - 1
|
56
|
+
if within.present?
|
57
|
+
start_line = find_block_start(within)
|
58
|
+
end_line = find_block_end(starting_from: start_line)
|
59
|
+
# start_line += 1 # ensure we actually insert the content _within_ the given block
|
60
|
+
# end_line += 1 if end_line == start_line
|
61
|
+
end
|
62
|
+
if after_block.present?
|
63
|
+
block_start = find_block_start(after_block)
|
64
|
+
block_end = find_block_end(starting_from: block_start)
|
65
|
+
start_line = block_end
|
66
|
+
end_line = @lines.count - 1
|
67
|
+
end
|
68
|
+
index = start_line
|
69
|
+
match = false
|
70
|
+
while index < end_line && !match
|
71
|
+
line = @lines[index]
|
72
|
+
if after.nil? || line.match?(after)
|
73
|
+
unless append
|
74
|
+
match = true
|
75
|
+
# We adjust the injection point if we really wanted to insert before.
|
76
|
+
insert_line(content, index - (before ? 1 : 0))
|
77
|
+
end
|
78
|
+
end
|
79
|
+
index += 1
|
80
|
+
end
|
81
|
+
|
82
|
+
return if match
|
83
|
+
|
84
|
+
# Match should always be false here.
|
85
|
+
if append && !match
|
86
|
+
insert_line(content, index - 1)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def insert_line(content, insert_at_index)
|
91
|
+
content += "\n" unless content.match?(/\n$/)
|
92
|
+
final = []
|
93
|
+
@lines.each_with_index do |line, index|
|
94
|
+
indent = line.match(/^\s*/).to_s
|
95
|
+
final << line
|
96
|
+
if index == insert_at_index
|
97
|
+
final << indent + content
|
98
|
+
end
|
99
|
+
end
|
100
|
+
@lines = final
|
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)
|
106
|
+
insert_line(block_content[0], block_end)
|
107
|
+
insert_line(block_content[1], block_end + 1)
|
108
|
+
end
|
109
|
+
|
110
|
+
def write
|
111
|
+
File.write(@filepath, @lines.join)
|
112
|
+
end
|
113
|
+
|
114
|
+
def find_block_start(starting_string)
|
115
|
+
matcher = Regexp.escape(starting_string)
|
116
|
+
starting_line = 0
|
117
|
+
|
118
|
+
@lines.each_with_index do |line, index|
|
119
|
+
if line.match?(matcher)
|
120
|
+
starting_line = index
|
121
|
+
break
|
122
|
+
end
|
123
|
+
end
|
124
|
+
starting_line
|
125
|
+
end
|
126
|
+
|
127
|
+
def find_block_end(starting_from:)
|
128
|
+
depth = 0
|
129
|
+
current_line = starting_from
|
130
|
+
@lines[starting_from..@lines.count].each_with_index do |line, index|
|
131
|
+
current_line = starting_from + index
|
132
|
+
depth += 1 if line.match?(/\s*<%.+ do .*%>/)
|
133
|
+
depth += 1 if line.match?(/\s*<% if .*%>/)
|
134
|
+
depth += 1 if line.match?(/\s*<% unless .*%>/)
|
135
|
+
depth -= 1 if line.match?(/\s*<%.* end .*%>/)
|
136
|
+
break current_line if depth == 0
|
137
|
+
end
|
138
|
+
current_line
|
139
|
+
end
|
140
|
+
end
|
data/lib/scaffolding/script.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "indefinite_article"
|
2
2
|
require "yaml"
|
3
|
+
require "scaffolding/class_names_transformer"
|
3
4
|
|
4
5
|
class Scaffolding::Transformer
|
5
6
|
attr_accessor :child, :parent, :parents, :class_names_transformer, :cli_options, :additional_steps, :namespace, :suppress_could_not_find
|
@@ -111,11 +112,11 @@ class Scaffolding::Transformer
|
|
111
112
|
# Originally all the potential source files were in the repository alongside the application.
|
112
113
|
# Now the files could be provided by an included Ruby gem, so we allow those Ruby gems to register their base
|
113
114
|
# path and then we check them in order to see which template we should use.
|
114
|
-
BulletTrain::SuperScaffolding.template_paths.
|
115
|
+
BulletTrain::SuperScaffolding.template_paths.map do |base_path|
|
115
116
|
base_path = Pathname.new(base_path)
|
116
117
|
resolved_path = base_path.join(file).to_s
|
117
|
-
File.
|
118
|
-
end.compact.first
|
118
|
+
File.exist?(resolved_path) ? resolved_path : nil
|
119
|
+
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")}")
|
119
120
|
end
|
120
121
|
|
121
122
|
def get_transformed_file_content(file)
|
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.8
|
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-02-
|
11
|
+
date: 2022-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 6.0.0
|
27
27
|
description: Bullet Train Super Scaffolding
|
28
28
|
email:
|
29
29
|
- andrew.culver@gmail.com
|
@@ -45,6 +45,7 @@ files:
|
|
45
45
|
- lib/bullet_train/super_scaffolding/scaffolders/oauth_provider_scaffolder.rb
|
46
46
|
- lib/bullet_train/super_scaffolding/version.rb
|
47
47
|
- lib/scaffolding.rb
|
48
|
+
- lib/scaffolding/block_manipulator.rb
|
48
49
|
- lib/scaffolding/class_names_transformer.rb
|
49
50
|
- lib/scaffolding/oauth_providers.rb
|
50
51
|
- lib/scaffolding/routes_file_manipulator.rb
|