Class: DevSystem::SubsystemGenerator
Instance Attribute Summary
#menv
#menv
Instance Method Summary
collapse
#add_unit, #add_view, #app_shell, #arg_views, #arg_views_adjacent?, #arg_views_eof?, #arg_views_nested?, #arg_views_none?, #before, before_instance_call, #before_instance_calls, before_instance_calls, #copy_examples, #copy_file, #copy_files, #create_file, #create_file_contents, #delete_file, #generate, #inform, #mapper, #pick_many_units, #puts_line, #read_file, #remove_units, #save, #set_default_views, set_default_views, #update_file, #valid_views
#action_name, #after, #args, #before, #before_default, #before_input, #call, call, #command, #default_args, default_args, #default_booleans, default_booleans, default_strings, #default_strings, get_generator_signatures, #inform, #input_args, input_args, input_booleans, #input_booleans, input_strings, #input_strings, #save, #set_default_arg, set_default_arg, #set_default_boolean, set_default_boolean, #set_default_string, set_default_string, #set_input_arg, set_input_arg, set_input_boolean, #set_input_boolean, set_input_string, #set_input_string
Methods inherited from Generator
get_generator_signatures
#`, `, attr_accessor, attr_reader, attr_writer, #attrs, box, #box, call, color, division, division!, division?, inherited, menv_accessor, menv_reader, menv_writer, on_connected, panel, #panel, plural, require, requirements, sh, #sh, singular, subsystem, subsystem!, subsystem?, subsystem_token, token
Methods inherited from Liza::Unit
_erbs_for, #add, add, cl, #cl, class_methods_defined, const_added, const_missing, constants_defined, define_error, descendants_select, division, erbs_available, erbs_defined, erbs_for, errors, #fetch, fetch, get, #get, instance_methods_defined, log, #log, log?, #log?, #log_array, log_array, log_hash, #log_hash, #log_level, log_level, #log_level?, log_level?, log_levels, #log_levels, #log_render_convert, #log_render_format, #log_render_in, #log_render_out, method_added, methods_defined, namespace, part, raise_error, #raise_error, reload!, #reload!, #render, #render!, #render_stack, renderable_formats_for, renderable_names, section, sections, #set, set, #settings, settings, singleton_method_added, sleep, #sleep, stick, #stick, sticks, #sticks, subclasses_select, subunits, system, #system, system?, test_class, time_diff, #time_diff
Instance Method Details
#_add_panel_to_box(path, contents, verb) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/dev_system/generators/subsystem_generator.rb', line 49
def _add_panel_to_box path, contents, verb
a = contents.split("\n")
a = a.map { _1.strip }
a = a.select { _1.start_with? " #{verb} :" }
old_lines = contents.split("\n")
generic_panel_line = " #{verb} :"
new_lines = [
" #{verb} :#{subsystem_name} do",
" # #{subsystem_name.camelcase}Panel.instance gives you read-access to this instance",
" end",
"",
]
lines = LineShell. old_lines, "class ".."end"
if a.count == 0
lines += new_lines
else
panel_lines = LineShell. lines, generic_panel_line
panel_lines += new_lines
panel_lines = panel_lines.sort
lines = LineShell.replace_wall_of lines, generic_panel_line, panel_lines
end
lines = LineShell.replace_between old_lines, "class ".."end", lines
lines.join("\n")
end
|
#_create_controller_panel_unit(unit, class_names, path) ⇒ Object
134
135
136
137
138
139
140
141
|
# File 'lib/dev_system/generators/subsystem_generator.rb', line 134
def _create_controller_panel_unit(unit, class_names, path)
log "Adding unit..."
log "unit: #{unit.inspect}"
log "class_names: #{class_names}"
log "path: #{path.inspect}"
add_unit unit, class_names, path
end
|
#add_panel_to_box ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/dev_system/generators/subsystem_generator.rb', line 35
def add_panel_to_box
path = App.systems_directory / "#{system_name}_system/#{system_name}_box.rb"
contents = read_file path
contents = _add_panel_to_box path, contents, "preconfigure"
update_file path, contents
path = App.directory / "#{system_name}_box.rb"
contents = read_file path
return if contents.empty?
contents = _add_panel_to_box path, contents, "configure"
update_file path, contents
end
|
#add_sub_to_system ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/dev_system/generators/subsystem_generator.rb', line 23
def add_sub_to_system
contents = read_file system_path
old_lines = contents.split("\n")
lines = LineShell. old_lines, "class ".."end"
lines << " panel :#{subsystem_name}"
lines = LineShell.replace_between old_lines, "class ".."end", lines
contents = lines.join("\n")
update_file system_path, contents
end
|
#arg_name ⇒ Object
153
|
# File 'lib/dev_system/generators/subsystem_generator.rb', line 153
def arg_name() = @arg_name ||= (name = command.simple_arg(1) until name.to_s.strip.length.positive?; name)
|
#arg_place ⇒ Object
167
|
# File 'lib/dev_system/generators/subsystem_generator.rb', line 167
def arg_place() = @arg_place ||= command.simple_string(:place)
|
#arg_place_path ⇒ Object
169
|
# File 'lib/dev_system/generators/subsystem_generator.rb', line 169
def arg_place_path() = @arg_place_path ||= ControllerShell.path_for(arg_place, arg_name)
|
#arg_place_system ⇒ Object
165
|
# File 'lib/dev_system/generators/subsystem_generator.rb', line 165
def arg_place_system() = App.systems[arg_place.to_sym]
|
#available_places ⇒ Object
#call_default ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/dev_system/generators/subsystem_generator.rb', line 6
def call_default
name = arg_name
if App.systems.values.map(&:subs).flatten.map(&:to_s).include? name
log stick :red, :white, :b, "controller and panel #{name} already exist"
return
end
add_sub_to_system
add_panel_to_box
create_controller_panel
create_command
create_generator
end
|
#create_command ⇒ Object
143
144
145
|
# File 'lib/dev_system/generators/subsystem_generator.rb', line 143
def create_command
generate "command", subsystem_name, "place=#{system_name}/#{subsystem_name}", "-prefix"
end
|
#create_controller_panel ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/dev_system/generators/subsystem_generator.rb', line 82
def create_controller_panel
class_name = "#{system_name.to_s.camelize}System::#{subsystem_name.to_s.camelize}"
controller = UnitHelper.new
controller_test = UnitHelper.new
panel = UnitHelper.new
panel_test = UnitHelper.new
controller.section name: :subsystem, render_key: :section_controller, format: :rb
controller_test.section name: :subject, render_key: :section_controller_test
panel.section name: :subsystem, render_key: :section_panel, format: :rb
panel_test.section name: :subject, render_key: :section_panel_test
controller_class_names = ["#{class_name}", "Liza::Controller"]
controller_test_class_names = ["#{class_name}Test", "Liza::ControllerTest"]
panel_class_names = ["#{class_name}Panel", "Liza::Panel"]
panel_test_class_names = ["#{class_name}PanelTest", "Liza::PanelTest"]
controller_path = subsystem_path / "#{subsystem_name}.rb"
controller_test_path = subsystem_path / "#{subsystem_name}_test.rb"
panel_path = subsystem_path / "#{subsystem_name}_panel.rb"
panel_test_path = subsystem_path / "#{subsystem_name}_panel_test.rb"
_create_controller_panel_unit(
controller,
controller_class_names,
controller_path
)
_create_controller_panel_unit(
controller_test,
controller_test_class_names,
controller_test_path
)
_create_controller_panel_unit(
panel,
panel_class_names,
panel_path
)
_create_controller_panel_unit(
panel_test,
panel_test_class_names,
panel_test_path
)
end
|
#create_generator ⇒ Object
147
148
149
|
# File 'lib/dev_system/generators/subsystem_generator.rb', line 147
def create_generator
generate "generator:controller", subsystem_name, "place=#{system_name}/#{subsystem_name}", "-prefix"
end
|
#subsystem_name ⇒ Object
159
|
# File 'lib/dev_system/generators/subsystem_generator.rb', line 159
def subsystem_name() = arg_name
|
#subsystem_path ⇒ Object
161
|
# File 'lib/dev_system/generators/subsystem_generator.rb', line 161
def subsystem_path() = @subsystem_path ||= (App.root / arg_place_path)
|
#system_name ⇒ Object
155
|
# File 'lib/dev_system/generators/subsystem_generator.rb', line 155
def system_name() = arg_place
|
#system_path ⇒ Object
157
|
# File 'lib/dev_system/generators/subsystem_generator.rb', line 157
def system_path() = @system_path ||= (App.systems_directory / "#{system_name}_system.rb")
|