lizarb 1.0.1 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.tool-versions +1 -0
  4. data/Gemfile +1 -0
  5. data/Gemfile.lock +7 -4
  6. data/README.md +23 -64
  7. data/README_SYSTEMS.md +80 -0
  8. data/Rakefile +3 -1
  9. data/app/dev/benches/loops_bench.rb +35 -0
  10. data/app/dev/commands/calculator_command.rb +69 -0
  11. data/app/dev/commands/calculator_command_test.rb +58 -0
  12. data/app/dev/commands/circle_command.rb +70 -0
  13. data/app/dev/commands/circle_command_test.rb +76 -0
  14. data/app/dev/commands/narrative_method_command.rb +60 -0
  15. data/app/dev/commands/narrative_method_command_test.rb +36 -0
  16. data/app/dev/commands/quadratic_command.rb +66 -0
  17. data/app/dev/commands/quadratic_command_test.rb +47 -0
  18. data/app/dev/generators/bench_generator/bench.rb.erb +24 -0
  19. data/app/dev/generators/bench_generator/bench_test.rb.erb +12 -0
  20. data/app/dev/generators/bench_generator.rb +2 -51
  21. data/app/dev/generators/command_generator/command.rb.erb +26 -0
  22. data/app/dev/generators/command_generator/command_test.rb.erb +12 -0
  23. data/app/dev/generators/command_generator.rb +2 -35
  24. data/app/dev/generators/record_generator.rb +46 -0
  25. data/app/dev/generators/{model_generator_test.rb → record_generator_test.rb} +2 -2
  26. data/app/dev_box.rb +24 -4
  27. data/app/happy_box.rb +1 -1
  28. data/app/net/databases/sqlite_db_test.rb +5 -5
  29. data/app/net/{models/app_model.rb → records/app_record.rb} +2 -1
  30. data/app/net/records/app_record_test.rb +8 -0
  31. data/app/net/records/post_record.rb +4 -0
  32. data/app/net/records/post_record_test.rb +8 -0
  33. data/app/net/records/user_record.rb +4 -0
  34. data/app/net/records/user_record_test.rb +8 -0
  35. data/app/net_box.rb +7 -7
  36. data/app/web/requests/api_request.rb +8 -7
  37. data/app/web/requests/assets_request.rb +12 -13
  38. data/app/web/requests/root_request.rb +6 -7
  39. data/app/web/requests/root_request_test.rb +1 -1
  40. data/app/web_box.rb +9 -1
  41. data/exe/lrb +3 -0
  42. data/lib/app.rb +19 -15
  43. data/lib/dev_system/dev/controllers/bench/not_found_bench.rb +27 -0
  44. data/lib/dev_system/dev/controllers/{command/dev_command_test.rb → bench/not_found_bench_test.rb} +3 -5
  45. data/lib/dev_system/dev/controllers/bench.rb +5 -7
  46. data/lib/dev_system/dev/controllers/bench_dsl_main_part.rb +37 -39
  47. data/lib/dev_system/dev/controllers/bench_test.rb +8 -10
  48. data/lib/dev_system/dev/controllers/command/bench_command.rb +20 -12
  49. data/lib/dev_system/dev/controllers/command/bench_command_test.rb +8 -10
  50. data/lib/dev_system/dev/controllers/command/echo_command.rb +5 -7
  51. data/lib/dev_system/dev/controllers/command/echo_command_test.rb +8 -10
  52. data/lib/dev_system/dev/controllers/command/generate_command.rb +22 -12
  53. data/lib/dev_system/dev/controllers/command/generate_command_test.rb +8 -10
  54. data/lib/dev_system/dev/controllers/command/not_found_command.rb +27 -0
  55. data/lib/dev_system/dev/controllers/command/not_found_command_test.rb +12 -0
  56. data/lib/dev_system/dev/controllers/command/terminal_command.rb +22 -0
  57. data/lib/dev_system/dev/controllers/command/terminal_command_test.rb +12 -0
  58. data/lib/dev_system/dev/controllers/command/test_command.rb +64 -49
  59. data/lib/dev_system/dev/controllers/command/test_command_test.rb +8 -10
  60. data/lib/dev_system/dev/controllers/command/version_command.rb +4 -6
  61. data/lib/dev_system/dev/controllers/command/version_command_test.rb +8 -10
  62. data/lib/dev_system/dev/controllers/command.rb +11 -13
  63. data/lib/dev_system/dev/controllers/command_test.rb +8 -10
  64. data/lib/dev_system/dev/controllers/generator.rb +5 -7
  65. data/lib/dev_system/dev/controllers/generator_dsl_main_part.rb +35 -37
  66. data/lib/dev_system/dev/controllers/generator_test.rb +8 -10
  67. data/lib/dev_system/dev/controllers/generators/app_generator.rb +122 -47
  68. data/lib/dev_system/dev/controllers/generators/app_generator_test.rb +8 -10
  69. data/lib/dev_system/dev/controllers/generators/generator_generator/generator.rb.erb +18 -0
  70. data/lib/dev_system/dev/controllers/generators/generator_generator/generator_test.rb.erb +12 -0
  71. data/lib/dev_system/dev/controllers/generators/generator_generator/template.rb.erb +9 -0
  72. data/lib/dev_system/dev/controllers/generators/generator_generator/template_test.rb.erb +12 -0
  73. data/lib/dev_system/dev/controllers/generators/generator_generator.rb +30 -0
  74. data/lib/dev_system/dev/controllers/generators/generator_generator_test.rb +12 -0
  75. data/lib/dev_system/dev/controllers/generators/not_found_generator.rb +27 -0
  76. data/lib/dev_system/dev/controllers/generators/not_found_generator_test.rb +12 -0
  77. data/lib/dev_system/dev/controllers/shell/bin_shell.rb +22 -0
  78. data/lib/dev_system/dev/controllers/shell/bin_shell_test.rb +87 -0
  79. data/lib/dev_system/dev/controllers/shell/dir_shell.rb +27 -0
  80. data/lib/dev_system/dev/controllers/shell/dir_shell_test.rb +73 -0
  81. data/lib/dev_system/dev/controllers/shell/file_shell.rb +56 -26
  82. data/lib/dev_system/dev/controllers/shell/file_shell_test.rb +143 -7
  83. data/lib/dev_system/dev/controllers/shell/text_shell.rb +23 -0
  84. data/lib/dev_system/dev/controllers/shell/text_shell_test.rb +84 -0
  85. data/lib/dev_system/dev/controllers/shell.rb +26 -14
  86. data/lib/dev_system/dev/controllers/shell_test.rb +42 -9
  87. data/lib/dev_system/dev/controllers/terminal/irb_terminal.rb +11 -13
  88. data/lib/dev_system/dev/controllers/terminal/irb_terminal_test.rb +8 -10
  89. data/lib/dev_system/dev/controllers/terminal/pry_terminal.rb +6 -8
  90. data/lib/dev_system/dev/controllers/terminal/pry_terminal_test.rb +8 -10
  91. data/lib/dev_system/dev/controllers/terminal.rb +11 -13
  92. data/lib/dev_system/dev/controllers/terminal_test.rb +8 -10
  93. data/lib/dev_system/dev/dev_box.rb +33 -16
  94. data/lib/dev_system/dev/dev_box_test.rb +12 -14
  95. data/lib/dev_system/dev/panels/bench_panel.rb +3 -0
  96. data/lib/dev_system/dev/panels/bench_panel_test.rb +12 -0
  97. data/lib/dev_system/dev/panels/command_panel.rb +24 -6
  98. data/lib/dev_system/dev/panels/command_panel_test.rb +15 -17
  99. data/lib/dev_system/dev/panels/generator_panel.rb +3 -0
  100. data/lib/dev_system/dev/panels/generator_panel_test.rb +12 -0
  101. data/lib/dev_system/dev/panels/log_panel.rb +9 -6
  102. data/lib/dev_system/dev/panels/log_panel_test.rb +11 -13
  103. data/lib/dev_system/dev/panels/shell_panel.rb +3 -0
  104. data/lib/dev_system/dev/panels/shell_panel_test.rb +12 -0
  105. data/lib/dev_system/dev/panels/terminal_panel.rb +3 -0
  106. data/lib/dev_system/dev/panels/terminal_panel_test.rb +12 -0
  107. data/lib/happy_system/happy/controllers/axo.rb +4 -5
  108. data/lib/happy_system/happy/happy_box.rb +6 -9
  109. data/lib/happy_system/happy/happy_box_test.rb +11 -13
  110. data/lib/happy_system/happy/panels/axo_panel.rb +1 -3
  111. data/lib/lerb.rb +106 -0
  112. data/lib/liza/base/box.rb +71 -26
  113. data/lib/liza/base/box_test.rb +7 -9
  114. data/lib/liza/base/controller.rb +19 -19
  115. data/lib/liza/base/controller_test.rb +7 -9
  116. data/lib/liza/base/panel.rb +40 -24
  117. data/lib/liza/base/panel_test.rb +10 -12
  118. data/lib/liza/base_parts/controller_renderer_part.rb +140 -0
  119. data/lib/liza/base_parts/controller_renderer_part_test.rb +16 -0
  120. data/lib/liza/meta/part.rb +12 -14
  121. data/lib/liza/meta/part_extension.rb +14 -11
  122. data/lib/liza/meta/part_test.rb +4 -6
  123. data/lib/liza/meta/system.rb +12 -14
  124. data/lib/liza/meta/system_test.rb +8 -10
  125. data/lib/liza/ruby_test.rb +7 -0
  126. data/lib/liza/ruby_tests/module_test.rb +21 -0
  127. data/lib/liza/ruby_tests/string_test.rb +59 -0
  128. data/lib/liza/test/test.rb +7 -8
  129. data/lib/liza/test/test_test.rb +168 -76
  130. data/lib/liza/test_parts/test_assertions_advanced_part.rb +125 -0
  131. data/lib/liza/test_parts/test_assertions_part.rb +81 -82
  132. data/lib/liza/test_parts/test_dsl_part.rb +44 -98
  133. data/lib/liza/test_parts/test_log_part.rb +122 -0
  134. data/lib/liza/test_parts/test_subject_part.rb +16 -18
  135. data/lib/liza/test_parts/test_tree_part.rb +137 -0
  136. data/lib/liza/unit.rb +108 -102
  137. data/lib/liza/unit_parts/unit_procedure_part.rb +17 -0
  138. data/lib/liza/unit_parts/unit_procedure_part_test.rb +65 -0
  139. data/lib/liza/unit_test.rb +69 -71
  140. data/lib/liza.rb +5 -0
  141. data/lib/lizarb/ruby/module.rb +17 -0
  142. data/lib/lizarb/ruby/string.rb +10 -2
  143. data/lib/lizarb/version.rb +1 -1
  144. data/lib/lizarb.rb +24 -2
  145. data/lib/net_system/dev/net_command.rb +10 -12
  146. data/lib/net_system/net/controllers/client/redis_client.rb +19 -21
  147. data/lib/net_system/net/controllers/client/redis_client_test.rb +20 -22
  148. data/lib/net_system/net/controllers/client/sqlite_client.rb +19 -21
  149. data/lib/net_system/net/controllers/client/sqlite_client_test.rb +20 -22
  150. data/lib/net_system/net/controllers/client.rb +1 -3
  151. data/lib/net_system/net/controllers/client_test.rb +8 -10
  152. data/lib/net_system/net/controllers/database/redis_db.rb +6 -8
  153. data/lib/net_system/net/controllers/database/redis_db_test.rb +15 -17
  154. data/lib/net_system/net/controllers/database/sqlite_db.rb +6 -8
  155. data/lib/net_system/net/controllers/database/sqlite_db_test.rb +15 -17
  156. data/lib/net_system/net/controllers/database.rb +21 -23
  157. data/lib/net_system/net/controllers/database_test.rb +8 -10
  158. data/lib/net_system/net/controllers/record.rb +29 -0
  159. data/lib/net_system/net/controllers/record_test.rb +12 -0
  160. data/lib/net_system/net/net_box.rb +11 -16
  161. data/lib/net_system/net/net_box_test.rb +12 -14
  162. data/lib/net_system/net/panels/client_panel.rb +1 -3
  163. data/lib/net_system/net/panels/client_panel_test.rb +11 -13
  164. data/lib/net_system/net/panels/database_panel.rb +6 -8
  165. data/lib/net_system/net/panels/database_panel_test.rb +11 -13
  166. data/lib/web_system/dev/rack_command.rb +35 -0
  167. data/lib/web_system/dev/request_command.rb +143 -0
  168. data/lib/web_system/dev/web_command.rb +6 -39
  169. data/lib/web_system/web/controllers/rack.rb +6 -0
  170. data/lib/web_system/web/controllers/rack_test.rb +16 -0
  171. data/lib/web_system/web/controllers/request/client_error_request.rb +9 -12
  172. data/lib/web_system/web/controllers/request/not_found_request.rb +9 -12
  173. data/lib/web_system/web/controllers/request/server_error_request.rb +10 -13
  174. data/lib/web_system/web/controllers/request.rb +1 -3
  175. data/lib/web_system/web/controllers/request_test.rb +11 -13
  176. data/lib/web_system/web/panels/rack_panel.rb +42 -0
  177. data/lib/web_system/web/panels/rack_panel_test.rb +12 -0
  178. data/lib/web_system/web/panels/request_panel.rb +54 -37
  179. data/lib/web_system/web/panels/request_panel_test.rb +28 -9
  180. data/lib/web_system/web/web_box.rb +16 -8
  181. data/lib/web_system/web/web_box_test.rb +11 -13
  182. data/lizarb.gemspec +2 -2
  183. metadata +76 -28
  184. data/app/dev/commands/example_command.rb +0 -57
  185. data/app/dev/commands/example_command_test.rb +0 -43
  186. data/app/dev/commands/macro_child_command.rb +0 -32
  187. data/app/dev/commands/macro_child_command_test.rb +0 -7
  188. data/app/dev/commands/macro_parent_command.rb +0 -70
  189. data/app/dev/commands/macro_parent_command_test.rb +0 -7
  190. data/app/dev/commands/my_command.rb +0 -7
  191. data/app/dev/commands/my_command_test.rb +0 -7
  192. data/app/dev/generators/model_generator.rb +0 -46
  193. data/app/net/models/app_model_test.rb +0 -8
  194. data/app/net/models/post_model.rb +0 -4
  195. data/app/net/models/post_model_test.rb +0 -8
  196. data/app/net/models/user_model.rb +0 -4
  197. data/app/net/models/user_model_test.rb +0 -8
  198. data/app_new/.gitignore +0 -4
  199. data/app_new/Gemfile +0 -31
  200. data/app_new/Procfile +0 -3
  201. data/lib/dev_system/dev/controllers/command/dev_command.rb +0 -24
  202. data/lib/liza/test_parts/test_context_part.rb +0 -81
  203. data/lib/net_system/net/controllers/model.rb +0 -31
  204. data/lib/net_system/net/controllers/model_test.rb +0 -14
@@ -1,12 +1,10 @@
1
- class DevSystem
2
- class PryTerminal < Terminal
1
+ class DevSystem::PryTerminal < DevSystem::Terminal
3
2
 
4
- def self.call args
5
- log :higher, "Called #{self}.#{__method__} with args #{args}"
6
-
7
- require "pry"
8
- Pry.start
9
- end
3
+ def self.call args
4
+ log :higher, "Called #{self}.#{__method__} with args #{args}"
10
5
 
6
+ require "pry"
7
+ Pry.start
11
8
  end
9
+
12
10
  end
@@ -1,14 +1,12 @@
1
- class DevSystem
2
- class PryTerminalTest < TerminalTest
1
+ class DevSystem::PryTerminalTest < DevSystem::TerminalTest
3
2
 
4
- test :subject_class do
5
- assert subject_class == DevSystem::PryTerminal
6
- end
7
-
8
- test :settings do
9
- assert subject_class.log_level == :normal
10
- assert subject_class.log_color == :green
11
- end
3
+ test :subject_class do
4
+ assert subject_class == DevSystem::PryTerminal
5
+ end
12
6
 
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :green
13
10
  end
11
+
14
12
  end
@@ -1,19 +1,17 @@
1
- class DevSystem
2
- class Terminal < Liza::Controller
1
+ class DevSystem::Terminal < Liza::Controller
3
2
 
4
- # def self.call args
5
- # new.call args
6
- # end
3
+ # def self.call args
4
+ # new.call args
5
+ # end
7
6
 
8
- # def initialize args
9
- # @args = args
10
- # end
7
+ # def initialize args
8
+ # @args = args
9
+ # end
11
10
 
12
- # attr_reader :args
11
+ # attr_reader :args
13
12
 
14
- # def call args
15
- #
16
- # end
13
+ # def call args
14
+ #
15
+ # end
17
16
 
18
- end
19
17
  end
@@ -1,14 +1,12 @@
1
- class DevSystem
2
- class TerminalTest < Liza::ControllerTest
1
+ class DevSystem::TerminalTest < Liza::ControllerTest
3
2
 
4
- test :subject_class do
5
- assert subject_class == DevSystem::Terminal
6
- end
7
-
8
- test :settings do
9
- assert subject_class.log_level == :normal
10
- assert subject_class.log_color == :green
11
- end
3
+ test :subject_class do
4
+ assert subject_class == DevSystem::Terminal
5
+ end
12
6
 
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :green
13
10
  end
11
+
14
12
  end
@@ -1,22 +1,39 @@
1
- class DevSystem
2
- class DevBox < Liza::Box
3
- has_panel :command, :commands
4
- has_controller :command, :commands
5
- has_controller :shell, :commands
6
- has_controller :bench, :commands
7
- has_controller :terminal, :commands
1
+ class DevSystem::DevBox < Liza::Box
8
2
 
9
- has_panel :log, :logs
3
+ # Set up your bench panel per the DSL in http://guides.lizarb.org/panels/bench.html
4
+ panel :bench do
5
+ # set :log_level, ENV["dev.bench.log_level"]
6
+ end
7
+
8
+ # Set up your command panel per the DSL in http://guides.lizarb.org/panels/command.html
9
+ panel :command do
10
+ # set :log_level, ENV["dev.command.log_level"]
11
+ end
12
+
13
+ # Set up your generator panel per the DSL in http://guides.lizarb.org/panels/generator.html
14
+ panel :generator do
15
+ # set :log_level, ENV["dev.generator.log_level"]
16
+ end
10
17
 
11
- # Set up your command panel per the DSL in http://guides.lizarb.org/panels/command.html
12
- commands do
13
- # set :log_level, ENV["dev.command.log_level"]
14
- end
18
+ # Set up your command panel per the DSL in http://guides.lizarb.org/panels/log.html
19
+ panel :log do
20
+ # set :log_level, ENV["dev.log.log_level"]
21
+ end
15
22
 
16
- # Set up your command panel per the DSL in http://guides.lizarb.org/panels/log.html
17
- logs do
18
- # set :log_level, ENV["dev.log.log_level"]
19
- end
23
+ # Set up your shell panel per the DSL in http://guides.lizarb.org/panels/shell.html
24
+ panel :shell do
25
+ # set :log_level, ENV["dev.shell.log_level"]
26
+ end
20
27
 
28
+ # Set up your terminal panel per the DSL in http://guides.lizarb.org/panels/terminal.html
29
+ panel :terminal do
30
+ # set :log_level, ENV["dev.terminal.log_level"]
21
31
  end
32
+
33
+ has_controller :bench, :bench
34
+ has_controller :command, :command
35
+ has_controller :generator, :generator
36
+ # has_controller :log, :log
37
+ has_controller :shell, :shell
38
+ has_controller :terminal, :terminal
22
39
  end
@@ -1,19 +1,17 @@
1
- class DevSystem
2
- class DevBoxTest < Liza::BoxTest
1
+ class DevSystem::DevBoxTest < Liza::BoxTest
3
2
 
4
- test :subject_class do
5
- assert subject_class == DevSystem::DevBox
6
- end
7
-
8
- test :settings do
9
- assert subject_class.log_level == :normal
10
- assert subject_class.log_color == :green
11
- end
3
+ test :subject_class do
4
+ assert subject_class == DevSystem::DevBox
5
+ end
12
6
 
13
- test :panels do
14
- assert subject_class.commands.is_a? CommandPanel
15
- assert subject_class.logs.is_a? LogPanel
16
- end
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :green
10
+ end
17
11
 
12
+ test :panels do
13
+ assert subject_class[:command].is_a? DevSystem::CommandPanel
14
+ assert subject_class[:log].is_a? DevSystem::LogPanel
18
15
  end
16
+
19
17
  end
@@ -0,0 +1,3 @@
1
+ class DevSystem::BenchPanel < Liza::Panel
2
+
3
+ end
@@ -0,0 +1,12 @@
1
+ class DevSystem::BenchPanelTest < Liza::PanelTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == DevSystem::BenchPanel
5
+ end
6
+
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :green
10
+ end
11
+
12
+ end
@@ -1,10 +1,28 @@
1
- class DevSystem
2
- class CommandPanel < Liza::Panel
1
+ class DevSystem::CommandPanel < Liza::Panel
3
2
 
4
- def call args
5
- command_klass = Liza.const "#{args[0]}_command"
6
- command_klass.call args[1..-1]
7
- end
3
+ def call args
4
+ # 1. LOG
8
5
 
6
+ log "call #{args}"
7
+
8
+ # 2. FIND command
9
+
10
+ return call_not_found args if args.none?
11
+
12
+ command = args[0]
13
+
14
+ log({command:})
15
+
16
+ command_klass = Liza.const "#{command}_command"
17
+
18
+ # 3. CALL
19
+
20
+ command_klass.call args[1..-1]
21
+ rescue Liza::ConstNotFound
22
+ call_not_found args
23
+ end
24
+
25
+ def call_not_found args
26
+ Liza::NotFoundCommand.call args
9
27
  end
10
28
  end
@@ -1,23 +1,21 @@
1
- class DevSystem
2
- class CommandPanelTest < Liza::PanelTest
1
+ class DevSystem::CommandPanelTest < Liza::PanelTest
3
2
 
4
- test :subject_class do
5
- assert subject_class == DevSystem::CommandPanel
6
- end
3
+ test :subject_class do
4
+ assert subject_class == DevSystem::CommandPanel
5
+ end
7
6
 
8
- test :settings do
9
- assert subject_class.log_level == :normal
10
- assert subject_class.log_color == :green
11
- end
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :green
10
+ end
12
11
 
13
- test :call do
14
- begin
15
- subject.call ["echo", 1, 2, 3]
16
- assert false
17
- rescue RuntimeError => e
18
- assert e.message == "[1, 2, 3]"
19
- end
12
+ test :call do
13
+ begin
14
+ subject.call ["echo", 1, 2, 3]
15
+ assert false
16
+ rescue RuntimeError => e
17
+ assert e.message == "[1, 2, 3]"
20
18
  end
21
-
22
19
  end
20
+
23
21
  end
@@ -0,0 +1,3 @@
1
+ class DevSystem::GeneratorPanel < Liza::Panel
2
+
3
+ end
@@ -0,0 +1,12 @@
1
+ class DevSystem::GeneratorPanelTest < Liza::PanelTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == DevSystem::GeneratorPanel
5
+ end
6
+
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :green
10
+ end
11
+
12
+ end
@@ -1,10 +1,13 @@
1
- class DevSystem
2
- class LogPanel < Liza::Panel
1
+ class DevSystem::LogPanel < Liza::Panel
3
2
 
4
- # https://rubyapi.org/3.1/o/logger
5
- def call string
6
- puts string
3
+ # https://rubyapi.org/3.1/o/logger
4
+ def call string
5
+ unless App.mode == :code
6
+ pid = Process.pid
7
+ tid = Lizarb.thread_id.to_s.rjust_zeroes 3
8
+ string = "#{pid} #{tid} #{string}"
7
9
  end
8
-
10
+ puts string
9
11
  end
12
+
10
13
  end
@@ -1,18 +1,16 @@
1
- class DevSystem
2
- class LogPanelTest < Liza::PanelTest
1
+ class DevSystem::LogPanelTest < Liza::PanelTest
3
2
 
4
- test :subject_class do
5
- assert subject_class == DevSystem::LogPanel
6
- end
3
+ test :subject_class do
4
+ assert subject_class == DevSystem::LogPanel
5
+ end
7
6
 
8
- test :settings do
9
- assert subject_class.log_level == :normal
10
- assert subject_class.log_color == :green
11
- end
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :green
10
+ end
12
11
 
13
- # test :call do
14
- # todo "write this"
15
- # end
12
+ # test :call do
13
+ # todo "write this"
14
+ # end
16
15
 
17
- end
18
16
  end
@@ -0,0 +1,3 @@
1
+ class DevSystem::ShellPanel < Liza::Panel
2
+
3
+ end
@@ -0,0 +1,12 @@
1
+ class DevSystem::ShellPanelTest < Liza::PanelTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == DevSystem::ShellPanel
5
+ end
6
+
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :green
10
+ end
11
+
12
+ end
@@ -0,0 +1,3 @@
1
+ class DevSystem::TerminalPanel < Liza::Panel
2
+
3
+ end
@@ -0,0 +1,12 @@
1
+ class DevSystem::TerminalPanelTest < Liza::PanelTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == DevSystem::TerminalPanel
5
+ end
6
+
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :green
10
+ end
11
+
12
+ end
@@ -1,8 +1,7 @@
1
- class HappySystem
2
- class Axo < Liza::Controller
1
+ class HappySystem::Axo < Liza::Controller
3
2
 
4
- def self.call args
5
- #
6
- end
3
+ def self.call args
4
+ #
7
5
  end
6
+
8
7
  end
@@ -1,12 +1,9 @@
1
- class HappySystem
2
- class HappyBox < Liza::Box
3
- has_panel :axo
4
- has_controller :axo
5
-
6
- # Set up your axo panel per the DSL in http://guides.lizarb.org/panels/axo.html
7
- axo do
8
- # set :log_level, ENV["happy.axo.log_level"]
9
- end
1
+ class HappySystem::HappyBox < Liza::Box
10
2
 
3
+ # Set up your axo panel per the DSL in http://guides.lizarb.org/panels/axo.html
4
+ panel :axo do
5
+ # set :log_level, ENV["happy.axo.log_level"]
11
6
  end
7
+
8
+ has_controller :axo
12
9
  end
@@ -1,18 +1,16 @@
1
- class HappySystem
2
- class HappyBoxTest < Liza::BoxTest
1
+ class HappySystem::HappyBoxTest < Liza::BoxTest
3
2
 
4
- test :subject_class do
5
- assert subject_class == HappySystem::HappyBox
6
- end
7
-
8
- test :settings do
9
- assert subject_class.log_level == :normal
10
- assert subject_class.log_color == :magenta
11
- end
3
+ test :subject_class do
4
+ assert subject_class == HappySystem::HappyBox
5
+ end
12
6
 
13
- test :panels do
14
- assert subject_class.axo.is_a? AxoPanel
15
- end
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :magenta
10
+ end
16
11
 
12
+ test :panels do
13
+ assert subject_class[:axo].is_a? HappySystem::AxoPanel
17
14
  end
15
+
18
16
  end
@@ -1,5 +1,3 @@
1
- class HappySystem
2
- class AxoPanel < Liza::Panel
1
+ class HappySystem::AxoPanel < Liza::Panel
3
2
 
4
- end
5
3
  end
data/lib/lerb.rb ADDED
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ # https://docs.ruby-lang.org/en/3.2/ERB.html
4
+ require "erb"
5
+
6
+ class LERB < ERB
7
+ class Error < StandardError; end
8
+ class BuildError < Error; end
9
+ class ExecutionError < Error; end
10
+
11
+ # loaders
12
+
13
+ def self.load path_radical
14
+ load_from_folder(path_radical) + load_from_file("#{path_radical}.rb")
15
+ end
16
+
17
+ def self.load_from_file path
18
+ ret = []
19
+
20
+ fname = path
21
+ return ret unless File.exist? path
22
+
23
+ lines = File.readlines fname
24
+
25
+ lineno = lines.index "__END__\n"
26
+ return ret if lineno.nil?
27
+
28
+ content = lines[lineno+1..-1].join
29
+ array = content.split(/^# (\w*).(\w*).(\w*)$/)
30
+ # => ["", "a", "html", "erb", "\n<html>\n<a></a>\n</html>\n", "b", "html", "erb", "\n<html>\n<b></b>\n</html>"]
31
+
32
+ while (chunk = array.pop 4; chunk.size == 4)
33
+ # => ["b", "html", "erb", "\n<html>\n<b></b>\n</html>"]
34
+ # => ["a", "html", "erb", "\n<html>\n<a></a>\n</html>\n"]
35
+ key = "#{chunk[0]}.#{chunk[1]}.#{chunk[2]}"
36
+ content = chunk[3]
37
+ ret.push new :file, key, content, fname, lineno
38
+ end
39
+
40
+ ret
41
+ end
42
+
43
+ def self.load_from_folder path
44
+ ret = []
45
+
46
+ lineno = 0
47
+ fnames = Dir.glob "#{path}/*.*.erb"
48
+ fnames.map do |fname|
49
+ key = fname.split("/").last
50
+ content = File.read fname
51
+ ret.push new :folder, key, content, fname, lineno
52
+ end
53
+
54
+ ret
55
+ end
56
+
57
+ # format
58
+
59
+ TAG_FORMATS = %w|xml html|
60
+
61
+ def tags?
62
+ TAG_FORMATS.include? format
63
+ end
64
+
65
+ # source
66
+
67
+ SOURCES = %i|file folder|
68
+
69
+ def file?
70
+ @source == :file
71
+ end
72
+
73
+ def folder?
74
+ @source == :folder
75
+ end
76
+
77
+ # constructor
78
+
79
+ TRIM_MODE = "<>-"
80
+
81
+ attr_reader :source, :key, :name, :format
82
+
83
+ def initialize source, key, content, filename, lineno
84
+ raise BuildError, "source :#{source} must be one of #{SOURCES}" unless SOURCES.include? source
85
+
86
+ segments = key.split("/").last.split(".")
87
+ name, format = segments[0..1]
88
+
89
+ # raise BuildError, "key '#{key}' must be formatted as <name>.<format>.erb" unless segments.count == 3
90
+ # raise BuildError, "key '#{key}' must be formatted as <name>.<format>.erb" unless segments[2] == "erb"
91
+ raise BuildError, "key '#{key}' has an invalid format '#{format}'" unless format.gsub(/[^a-z0-9]/, "") == format
92
+
93
+ super content, trim_mode: TRIM_MODE
94
+ @source, @key, @name, @format, self.filename, self.lineno = source, key, name, format, filename, lineno
95
+ end
96
+
97
+ # result
98
+
99
+ def result the_binding, receiver=:unset
100
+ super the_binding
101
+ rescue NameError => e
102
+ raise unless e.receiver == receiver
103
+ message = "ERB template for a #{e.receiver.class} instance could not find method '#{e.name}'"
104
+ raise ExecutionError, message, [e.backtrace[0]]
105
+ end
106
+ end
data/lib/liza/base/box.rb CHANGED
@@ -1,40 +1,85 @@
1
- module Liza
2
- class Box < Unit
3
- inherited_explicitly_sets_system
1
+ class Liza::Box < Liza::Unit
2
+ inherited_explicitly_sets_system
4
3
 
5
- def self.has_panel symbol, panel_name = symbol
6
- system_klass = get :system
7
- panel_class = system_klass.const "#{symbol}_panel"
4
+ # def self.has_panel symbol, panel_name = symbol
5
+ # system_klass = get :system
6
+ # panel_class = system_klass.const "#{symbol}_panel"
8
7
 
9
- _has_panel_define panel_name, "get(:panels)[:#{panel_name}]"
8
+ # _has_panel_define panel_name, "get(:panels)[:#{panel_name}]"
10
9
 
11
- panel = panel_class.new panel_name
12
- add :panels, panel_name, panel
10
+ # panel = panel_class.new panel_name
11
+ # add :panels, panel_name, panel
13
12
 
14
- panel_class.on_connected self
15
- end
13
+ # panel_class.on_connected self
14
+ # end
16
15
 
17
- def self.has_controller symbol, panel_name = symbol
18
- system_klass = get :system
19
- controller_class = system_klass.const symbol
16
+ # def self.has_controller symbol, panel_name = symbol
17
+ # system_klass = get :system
18
+ # controller_class = system_klass.const symbol
20
19
 
21
- panel = public_send panel_name
20
+ # panel = public_send panel_name
22
21
 
23
- controller_class.on_connected self, panel
24
- end
22
+ # controller_class.on_connected self, panel
23
+ # end
24
+
25
+ # def self.method_missing symbol, *args, &block
26
+ # if panels.has_key? symbol
27
+ # panels[symbol]
28
+ # else
29
+ # super
30
+ # end
31
+ # end
32
+
33
+ # def self.respond_to_missing? symbol, include_private = false
34
+ # get(:panels).keys.include?(symbol) || super
35
+ # end
25
36
 
26
- def self._has_panel_define name, resource
27
- class_eval <<-CODE, __FILE__, __LINE__ + 1
37
+ # def self._has_panel_define name, resource
38
+ # class_eval <<-CODE, __FILE__, __LINE__ + 1
28
39
 
29
- def self.#{name} &block
30
- if block_given?
31
- #{resource}.instance_eval &block
32
- else
33
- #{resource}
40
+ # def self.#{name} &block
41
+ # if block_given?
42
+ # #{resource}.instance_eval &block
43
+ # else
44
+ # #{resource}
45
+ # end
46
+ # end
47
+
48
+ # CODE
49
+ # end
50
+
51
+ def self.panels
52
+ get :panels
53
+ end
54
+
55
+ def self.[] symbol
56
+ panels[symbol].started
34
57
  end
35
- end
36
58
 
37
- CODE
59
+ def self.panel symbol, panel_class = nil, &block
60
+ raise ArgumentError, "block required" unless block_given?
61
+
62
+ system_class = get :system
63
+ panel_class ||= system_class.const "#{symbol}_panel"
64
+
65
+ if Hash(get :panels).has_key? symbol
66
+ panel = panels[symbol]
67
+ else
68
+ panel_class.on_connected self
69
+ panel = panel_class.new symbol
70
+ add :panels, symbol, panel
38
71
  end
72
+
73
+ panel.push block
39
74
  end
75
+
76
+ def self.has_controller symbol, panel_name = symbol
77
+ system_klass = get :system
78
+ controller_class = system_klass.const symbol
79
+
80
+ panel = self[panel_name]
81
+
82
+ controller_class.on_connected self, panel
83
+ end
84
+
40
85
  end