lizarb 1.0.2 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +12 -13
  3. data/Rakefile +38 -0
  4. data/app/dev_box.rb +26 -4
  5. data/app/happy_box.rb +2 -2
  6. data/app/net/databases/sqlite_db_test.rb +5 -5
  7. data/app/net/records/app_record_test.rb +1 -1
  8. data/app/net/records/post_record_test.rb +1 -1
  9. data/app/net/records/user_record_test.rb +1 -1
  10. data/app/net_box.rb +9 -9
  11. data/app/web_box.rb +4 -4
  12. data/app.rb +6 -7
  13. data/{exe/Gemfile → app_global.gemfile.rb} +2 -0
  14. data/app_global.gemfile.rb.lock +19 -0
  15. data/app_global.rb +4 -0
  16. data/{app → app_new}/dev/benches/loops_bench.rb +3 -2
  17. data/{app/dev/generators/bench_generator_test.rb → app_new/dev/benches/loops_bench_test.rb} +2 -2
  18. data/app_new/dev/benches/objects_bench.rb +83 -0
  19. data/{app/dev/generators/record_generator_test.rb → app_new/dev/benches/objects_bench_test.rb} +2 -2
  20. data/app_new/dev/benches/sorted_bench.rb +54 -0
  21. data/app_new/dev/benches/sorted_bench_test.rb +12 -0
  22. data/app_new/dev/benches/variables_bench.rb +55 -0
  23. data/{app/dev/generators/command_generator_test.rb → app_new/dev/benches/variables_bench_test.rb} +2 -2
  24. data/{app → app_new}/dev/commands/calculator_command.rb +1 -1
  25. data/{app → app_new}/dev/commands/circle_command.rb +1 -1
  26. data/{app → app_new}/dev/commands/narrative_method_command.rb +5 -7
  27. data/{app → app_new}/dev/commands/quadratic_command.rb +1 -1
  28. data/app_new/dev_box.rb +14 -0
  29. data/app_new.rb +15 -0
  30. data/exe/lizarb +9 -1
  31. data/lib/app.rb +27 -95
  32. data/lib/dev_system/dev/controllers/bench/not_found_bench.rb +23 -18
  33. data/lib/dev_system/dev/controllers/bench/not_found_bench_test.rb +9 -11
  34. data/lib/dev_system/dev/controllers/bench.rb +1 -9
  35. data/lib/dev_system/dev/controllers/bench_test.rb +8 -10
  36. data/lib/dev_system/dev/controllers/command/bench_command.rb +19 -22
  37. data/lib/dev_system/dev/controllers/command/bench_command_test.rb +8 -10
  38. data/lib/dev_system/dev/controllers/command/generate_command.rb +5 -31
  39. data/lib/dev_system/dev/controllers/command/generate_command_test.rb +8 -10
  40. data/lib/dev_system/dev/controllers/command/new_command.rb +9 -0
  41. data/lib/dev_system/dev/controllers/command/new_command_test.rb +7 -0
  42. data/lib/dev_system/dev/controllers/command/not_found_command.rb +37 -18
  43. data/lib/dev_system/dev/controllers/command/not_found_command_test.rb +8 -10
  44. data/lib/dev_system/dev/controllers/command/terminal_command.rb +12 -14
  45. data/lib/dev_system/dev/controllers/command/terminal_command_test.rb +8 -10
  46. data/lib/dev_system/dev/controllers/command/test_command.rb +64 -53
  47. data/lib/dev_system/dev/controllers/command/test_command_test.rb +8 -10
  48. data/lib/dev_system/dev/controllers/command.rb +9 -15
  49. data/lib/dev_system/dev/controllers/command_test.rb +8 -10
  50. data/lib/dev_system/dev/controllers/generator.rb +5 -7
  51. data/lib/dev_system/dev/controllers/generator_dsl_main_part.rb +33 -37
  52. data/lib/dev_system/dev/controllers/generator_test.rb +8 -10
  53. data/{app/dev/generators/bench_generator/bench.rb.erb → lib/dev_system/dev/controllers/generators/bench_generator/controller.rb.erb} +1 -2
  54. data/{app/dev/generators/bench_generator/bench_test.rb.erb → lib/dev_system/dev/controllers/generators/bench_generator/controller_test.rb.erb} +2 -2
  55. data/lib/dev_system/dev/controllers/generators/bench_generator.rb +12 -0
  56. data/lib/dev_system/dev/controllers/generators/bench_generator_test.rb +12 -0
  57. data/lib/dev_system/dev/controllers/generators/command_generator/controller.rb.erb +41 -0
  58. data/{app/dev/generators/command_generator/command_test.rb.erb → lib/dev_system/dev/controllers/generators/command_generator/controller_test.rb.erb} +2 -2
  59. data/lib/dev_system/dev/controllers/generators/command_generator.rb +19 -0
  60. data/lib/dev_system/dev/controllers/generators/command_generator_test.rb +12 -0
  61. data/lib/dev_system/dev/controllers/generators/controller_generator.rb +97 -0
  62. data/lib/dev_system/dev/controllers/generators/controller_generator_test.rb +12 -0
  63. data/lib/dev_system/dev/controllers/generators/generator_generator/template.rb.erb +1 -1
  64. data/lib/dev_system/dev/controllers/generators/new_generator.rb +117 -0
  65. data/lib/dev_system/dev/controllers/generators/new_generator_test.rb +12 -0
  66. data/lib/dev_system/dev/controllers/generators/not_found_generator.rb +27 -17
  67. data/lib/dev_system/dev/controllers/generators/not_found_generator_test.rb +8 -10
  68. data/{app/dev → lib/dev_system/dev/controllers}/generators/record_generator.rb +1 -1
  69. data/lib/dev_system/dev/controllers/generators/record_generator_test.rb +12 -0
  70. data/{app/dev → lib/dev_system/dev/controllers}/generators/request_generator.rb +2 -2
  71. data/lib/dev_system/dev/controllers/generators/request_generator_test.rb +12 -0
  72. data/lib/dev_system/dev/controllers/log.rb +3 -0
  73. data/{app/dev/generators/request_generator_test.rb → lib/dev_system/dev/controllers/log_test.rb} +2 -2
  74. data/lib/dev_system/dev/controllers/shell.rb +22 -0
  75. data/lib/dev_system/dev/controllers/shell_test.rb +25 -0
  76. data/lib/dev_system/dev/controllers/terminal/irb_terminal.rb +15 -11
  77. data/lib/dev_system/dev/controllers/terminal/irb_terminal_test.rb +8 -10
  78. data/lib/dev_system/dev/controllers/terminal/pry_terminal.rb +6 -8
  79. data/lib/dev_system/dev/controllers/terminal/pry_terminal_test.rb +8 -10
  80. data/lib/dev_system/dev/controllers/terminal.rb +11 -13
  81. data/lib/dev_system/dev/controllers/terminal_test.rb +8 -10
  82. data/lib/dev_system/dev/dev_box.rb +27 -16
  83. data/lib/dev_system/dev/dev_box_test.rb +12 -14
  84. data/lib/dev_system/dev/panels/bench_panel.rb +3 -0
  85. data/lib/dev_system/dev/panels/bench_panel_test.rb +12 -0
  86. data/lib/dev_system/dev/panels/command_panel.rb +59 -18
  87. data/lib/dev_system/dev/panels/command_panel_test.rb +43 -20
  88. data/lib/dev_system/dev/panels/generator_panel.rb +73 -0
  89. data/lib/dev_system/dev/panels/generator_panel_test.rb +46 -0
  90. data/lib/dev_system/dev/panels/log_panel.rb +9 -6
  91. data/lib/dev_system/dev/panels/log_panel_test.rb +11 -13
  92. data/lib/dev_system/dev/panels/shell_panel.rb +3 -0
  93. data/lib/dev_system/dev/panels/shell_panel_test.rb +12 -0
  94. data/lib/dev_system/dev/panels/terminal_panel.rb +3 -0
  95. data/lib/dev_system/dev/panels/terminal_panel_test.rb +12 -0
  96. data/lib/happy_system/happy/controllers/axo.rb +4 -5
  97. data/lib/happy_system/happy/happy_box.rb +5 -9
  98. data/lib/happy_system/happy/happy_box_test.rb +11 -13
  99. data/lib/happy_system/happy/panels/axo_panel.rb +1 -3
  100. data/lib/lerb.rb +95 -49
  101. data/lib/liza/base/box.rb +76 -26
  102. data/lib/liza/base/box_test.rb +7 -9
  103. data/lib/liza/base/controller.rb +19 -21
  104. data/lib/liza/base/controller_test.rb +7 -9
  105. data/lib/liza/base/panel.rb +40 -27
  106. data/lib/liza/base/panel_test.rb +36 -12
  107. data/lib/liza/base_parts/controller_renderer_part.rb +1 -1
  108. data/lib/liza/meta/part.rb +12 -14
  109. data/lib/liza/meta/part_extension.rb +14 -16
  110. data/lib/liza/meta/part_test.rb +4 -6
  111. data/lib/liza/meta/system.rb +12 -14
  112. data/lib/liza/meta/system_test.rb +8 -10
  113. data/lib/liza/ruby_test.rb +4 -6
  114. data/lib/liza/ruby_tests/module_test.rb +3 -3
  115. data/lib/liza/test/test.rb +7 -10
  116. data/lib/liza/test/test_test.rb +160 -157
  117. data/lib/liza/test_parts/test_assertions_advanced_part.rb +102 -104
  118. data/lib/liza/test_parts/test_assertions_part.rb +81 -83
  119. data/lib/liza/test_parts/test_dsl_part.rb +47 -49
  120. data/lib/liza/test_parts/test_log_part.rb +88 -90
  121. data/lib/liza/test_parts/test_subject_part.rb +16 -18
  122. data/lib/liza/test_parts/test_tree_part.rb +73 -120
  123. data/lib/liza/unit.rb +105 -107
  124. data/lib/liza/unit_parts/unit_procedure_part_test.rb +9 -9
  125. data/lib/liza/unit_parts/unit_settings_part.rb +76 -0
  126. data/lib/liza/unit_parts/unit_settings_part_test.rb +3 -0
  127. data/lib/liza/unit_test.rb +80 -71
  128. data/lib/liza.rb +10 -1
  129. data/lib/lizarb/ruby/module.rb +1 -1
  130. data/lib/lizarb/version.rb +1 -1
  131. data/lib/lizarb.rb +247 -23
  132. data/lib/net_system/dev/net_command.rb +15 -17
  133. data/lib/net_system/net/controllers/client/redis_client.rb +19 -21
  134. data/lib/net_system/net/controllers/client/redis_client_test.rb +20 -22
  135. data/lib/net_system/net/controllers/client/sqlite_client.rb +19 -21
  136. data/lib/net_system/net/controllers/client/sqlite_client_test.rb +20 -22
  137. data/lib/net_system/net/controllers/client.rb +1 -3
  138. data/lib/net_system/net/controllers/client_test.rb +8 -10
  139. data/lib/net_system/net/controllers/database/redis_db.rb +6 -8
  140. data/lib/net_system/net/controllers/database/redis_db_test.rb +15 -17
  141. data/lib/net_system/net/controllers/database/sqlite_db.rb +6 -8
  142. data/lib/net_system/net/controllers/database/sqlite_db_test.rb +15 -17
  143. data/lib/net_system/net/controllers/database.rb +21 -23
  144. data/lib/net_system/net/controllers/database_test.rb +8 -10
  145. data/lib/net_system/net/controllers/record.rb +21 -23
  146. data/lib/net_system/net/controllers/record_test.rb +8 -10
  147. data/lib/net_system/net/net_box.rb +9 -16
  148. data/lib/net_system/net/net_box_test.rb +12 -14
  149. data/lib/net_system/net/panels/client_panel.rb +1 -3
  150. data/lib/net_system/net/panels/client_panel_test.rb +11 -13
  151. data/lib/net_system/net/panels/database_panel.rb +6 -8
  152. data/lib/net_system/net/panels/database_panel_test.rb +11 -13
  153. data/lib/web_system/dev/rack_command.rb +20 -18
  154. data/lib/web_system/dev/request_command.rb +8 -22
  155. data/lib/web_system/dev/web_command.rb +6 -8
  156. data/lib/web_system/web/controllers/rack.rb +4 -6
  157. data/lib/web_system/web/controllers/rack_test.rb +11 -13
  158. data/lib/web_system/web/controllers/request/client_error_request.rb +9 -11
  159. data/lib/web_system/web/controllers/request/not_found_request.rb +9 -11
  160. data/lib/web_system/web/controllers/request/server_error_request.rb +10 -12
  161. data/lib/web_system/web/controllers/request.rb +1 -3
  162. data/lib/web_system/web/controllers/request_test.rb +11 -13
  163. data/lib/web_system/web/panels/rack_panel.rb +37 -39
  164. data/lib/web_system/web/panels/rack_panel_test.rb +8 -10
  165. data/lib/web_system/web/panels/request_panel.rb +53 -57
  166. data/lib/web_system/web/panels/request_panel_test.rb +1 -1
  167. data/lib/web_system/web/web_box.rb +12 -18
  168. data/lib/web_system/web/web_box_test.rb +11 -13
  169. data/lizarb.gemspec +1 -1
  170. metadata +54 -44
  171. data/.ruby-version +0 -1
  172. data/app/dev/benches/app_bench.rb +0 -5
  173. data/app/dev/benches/app_bench_test.rb +0 -7
  174. data/app/dev/benches/loops_bench_test.rb +0 -11
  175. data/app/dev/commands/app_command.rb +0 -5
  176. data/app/dev/commands/app_command_test.rb +0 -7
  177. data/app/dev/commands/new_command.rb +0 -9
  178. data/app/dev/commands/new_command_test.rb +0 -7
  179. data/app/dev/generators/bench_generator.rb +0 -18
  180. data/app/dev/generators/command_generator/command.rb.erb +0 -26
  181. data/app/dev/generators/command_generator.rb +0 -18
  182. data/app_new/.gitignore +0 -4
  183. data/app_new/Gemfile +0 -31
  184. data/app_new/Procfile +0 -3
  185. data/exe/Gemfile.lock +0 -13
  186. data/lib/dev_system/dev/controllers/bench_dsl_main_part.rb +0 -60
  187. data/lib/dev_system/dev/controllers/command/echo_command.rb +0 -11
  188. data/lib/dev_system/dev/controllers/command/echo_command_test.rb +0 -14
  189. data/lib/dev_system/dev/controllers/command/version_command.rb +0 -9
  190. data/lib/dev_system/dev/controllers/command/version_command_test.rb +0 -14
  191. data/lib/dev_system/dev/controllers/generators/app_generator.rb +0 -96
  192. data/lib/dev_system/dev/controllers/generators/app_generator_test.rb +0 -14
  193. /data/{app → app_new}/dev/commands/calculator_command_test.rb +0 -0
  194. /data/{app → app_new}/dev/commands/circle_command_test.rb +0 -0
  195. /data/{app → app_new}/dev/commands/narrative_method_command_test.rb +0 -0
  196. /data/{app → app_new}/dev/commands/quadratic_command_test.rb +0 -0
@@ -1,30 +1,71 @@
1
- class DevSystem
2
- class CommandPanel < Liza::Panel
1
+ class DevSystem::CommandPanel < Liza::Panel
2
+ class Error < StandardError; end
3
+ class ParseError < Error; end
3
4
 
4
- def call args
5
- # 1. LOG
5
+ def call args
6
+ log "args = #{args.inspect}" if get :log_details
6
7
 
7
- log "call #{args}"
8
+ return call_not_found args if args.none?
8
9
 
9
- # 2. FIND command
10
+ struct = parse args[0]
11
+ struct.command = short struct.command
12
+ command = find struct.command
10
13
 
11
- return call_not_found args if args.none?
14
+ case
15
+ when struct.class_method
16
+ _call_log "#{command}.#{struct.class_method}(#{args[1..-1]})"
17
+ command.public_send struct.class_method, args[1..-1]
18
+ when struct.instance_method
19
+ _call_log "#{command}.new.#{struct.instance_method}(#{args[1..-1]})"
20
+ command.new.public_send struct.instance_method, args[1..-1]
21
+ when struct.method
22
+ if command.respond_to?(struct.method)
23
+ _call_log "#{command}.#{struct.method}(#{args[1..-1]})"
24
+ command.public_send struct.method, args[1..-1]
25
+ else
26
+ _call_log "#{command}.new.#{struct.method}(#{args[1..-1]})"
27
+ command.new.public_send struct.method, args[1..-1]
28
+ end
29
+ else
30
+ _call_log "#{command}.call(#{args[1..-1]})"
31
+ command.call args[1..-1]
32
+ end
33
+ rescue ParseError
34
+ call_not_found args
35
+ end
12
36
 
13
- command = args[0]
37
+ def _call_log string
38
+ log "#{string}" if get :log_details
39
+ end
14
40
 
15
- log({command:})
41
+ #
16
42
 
17
- command_klass = Liza.const "#{command}_command"
43
+ PARSE_REGEX = /(?<command>[A-Za-z_]+)(?::(?<class_method>[a-z_]+))?(?:#(?<instance_method>[a-z_]+))?(?:\.(?<method>[a-z_]+))?/
18
44
 
19
- # 3. CALL
45
+ # OpenStruct command class_method instance_method method
46
+ def parse string
47
+ md = string.to_s.match PARSE_REGEX
48
+ raise ParseError if md.nil?
49
+ hash = md.named_captures
50
+ log "{#{hash.map { ":#{_1}=>#{_2.to_s.inspect}" }.join(", ") }}" if get :log_details
51
+ OpenStruct.new hash
52
+ end
20
53
 
21
- command_klass.call args[1..-1]
22
- rescue Liza::ConstNotFound
23
- call_not_found args
24
- end
54
+ #
25
55
 
26
- def call_not_found args
27
- Liza::NotFoundCommand.call args
28
- end
56
+ def find string
57
+ k = Liza.const "#{string}_command"
58
+ rescue Liza::ConstNotFound
59
+ k = Liza::NotFoundCommand
60
+ ensure
61
+ log k.to_s if get :log_details
62
+ k
29
63
  end
64
+
65
+ #
66
+
67
+ def call_not_found args
68
+ Liza[:NotFoundCommand].call args
69
+ end
70
+
30
71
  end
@@ -1,23 +1,46 @@
1
- class DevSystem
2
- class CommandPanelTest < Liza::PanelTest
3
-
4
- test :subject_class do
5
- assert subject_class == DevSystem::CommandPanel
6
- end
7
-
8
- test :settings do
9
- assert subject_class.log_level == :normal
10
- assert subject_class.log_color == :green
11
- end
12
-
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
20
- end
1
+ class DevSystem::CommandPanelTest < Liza::PanelTest
21
2
 
3
+ test :subject_class do
4
+ assert_equality subject_class, DevSystem::CommandPanel
22
5
  end
6
+
7
+ test :settings do
8
+ assert_equality subject_class.log_level, :normal
9
+ assert_equality subject_class.log_color, :green
10
+ end
11
+
12
+ test :parse do
13
+ struct = subject.parse "generate"
14
+ assert_equality struct.command, "generate"
15
+ assert_equality struct.class_method, nil
16
+ assert_equality struct.instance_method, nil
17
+ assert_equality struct.method, nil
18
+
19
+ struct = subject.parse "generate:install"
20
+ assert_equality struct.command, "generate"
21
+ assert_equality struct.class_method, "install"
22
+ assert_equality struct.instance_method, nil
23
+ assert_equality struct.method, nil
24
+
25
+ struct = subject.parse "generate#install"
26
+ assert_equality struct.command, "generate"
27
+ assert_equality struct.class_method, nil
28
+ assert_equality struct.instance_method, "install"
29
+ assert_equality struct.method, nil
30
+
31
+ struct = subject.parse "generate.install"
32
+ assert_equality struct.command, "generate"
33
+ assert_equality struct.class_method, nil
34
+ assert_equality struct.instance_method, nil
35
+ assert_equality struct.method, "install"
36
+ end
37
+
38
+ test :find do
39
+ klass = subject.find "generate"
40
+ assert_equality DevSystem::GenerateCommand, klass
41
+
42
+ klass = subject.find "g"
43
+ assert_equality DevSystem::NotFoundCommand, klass
44
+ end
45
+
23
46
  end
@@ -0,0 +1,73 @@
1
+ class DevSystem::GeneratorPanel < Liza::Panel
2
+ class Error < StandardError; end
3
+ class ParseError < Error; end
4
+
5
+ #
6
+
7
+ def call args
8
+ log "args = #{args}"
9
+
10
+ return call_not_found args if args.none?
11
+
12
+ struct = parse args[0]
13
+ struct.generator = short struct.generator
14
+ generator = find struct.generator
15
+
16
+ case
17
+ when struct.class_method
18
+ _call_log "#{generator}.#{struct.class_method}(#{args[1..-1]})"
19
+ generator.public_send struct.class_method, args[1..-1]
20
+ when struct.instance_method
21
+ _call_log "#{generator}.new.#{struct.instance_method}(#{args[1..-1]})"
22
+ generator.new.public_send struct.instance_method, args[1..-1]
23
+ when struct.method
24
+ if generator.respond_to?(struct.method)
25
+ _call_log "#{generator}.#{struct.method}(#{args[1..-1]})"
26
+ generator.public_send struct.method, args[1..-1]
27
+ else
28
+ _call_log "#{generator}.new.#{struct.method}(#{args[1..-1]})"
29
+ generator.new.public_send struct.method, args[1..-1]
30
+ end
31
+ else
32
+ _call_log "#{generator}.call(#{args[1..-1]})"
33
+ generator.call args[1..-1]
34
+ end
35
+ rescue ParseError
36
+ call_not_found args
37
+ end
38
+
39
+ def _call_log string
40
+ log "#{string}" if get :log_details
41
+ end
42
+
43
+ #
44
+
45
+ PARSE_REGEX = /(?<generator>[a-z_]+)(?::(?<class_method>[a-z_]+))?(?:#(?<instance_method>[a-z_]+))?(?:\.(?<method>[a-z_]+))?/
46
+
47
+ # OpenStruct generator class_method instance_method method
48
+ def parse string
49
+ md = string.to_s.match PARSE_REGEX
50
+ raise ParseError if md.nil?
51
+ hash = md.named_captures
52
+ log "{#{hash.map { ":#{_1} => #{_2.to_s.inspect}" }.join(", ") }}" if get :log_details
53
+ OpenStruct.new hash
54
+ end
55
+
56
+ #
57
+
58
+ def find string
59
+ k = Liza.const "#{string}_generator"
60
+ rescue Liza::ConstNotFound
61
+ k = Liza::NotFoundGenerator
62
+ ensure
63
+ log k.to_s if get :log_details
64
+ k
65
+ end
66
+
67
+ #
68
+
69
+ def call_not_found args
70
+ Liza[:NotFoundGenerator].call args
71
+ end
72
+
73
+ end
@@ -0,0 +1,46 @@
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
+ test :parse do
13
+ struct = subject.parse "system"
14
+ assert_equality struct.generator, "system"
15
+ assert_equality struct.class_method, nil
16
+ assert_equality struct.instance_method, nil
17
+ assert_equality struct.method, nil
18
+
19
+ struct = subject.parse "system:install"
20
+ assert_equality struct.generator, "system"
21
+ assert_equality struct.class_method, "install"
22
+ assert_equality struct.instance_method, nil
23
+ assert_equality struct.method, nil
24
+
25
+ struct = subject.parse "system#install"
26
+ assert_equality struct.generator, "system"
27
+ assert_equality struct.class_method, nil
28
+ assert_equality struct.instance_method, "install"
29
+ assert_equality struct.method, nil
30
+
31
+ struct = subject.parse "system.install"
32
+ assert_equality struct.generator, "system"
33
+ assert_equality struct.class_method, nil
34
+ assert_equality struct.instance_method, nil
35
+ assert_equality struct.method, "install"
36
+ end
37
+
38
+ test :find do
39
+ klass = subject.find "command"
40
+ assert_equality DevSystem::CommandGenerator, klass
41
+
42
+ klass = subject.find "c"
43
+ assert_equality DevSystem::NotFoundGenerator, klass
44
+ end
45
+
46
+ 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 "lizarb #{Lizarb.thread_id.to_s.rjust_zeroes 3} #{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,8 @@
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
+ # Configure your axo panel per the DSL in http://guides.lizarb.org/panels/axo.html
4
+ configure :axo do
5
+ # set :log_level, ENV["happy.axo.log_level"]
11
6
  end
7
+
12
8
  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 CHANGED
@@ -3,95 +3,141 @@
3
3
  # https://docs.ruby-lang.org/en/3.2/ERB.html
4
4
  require "erb"
5
5
 
6
+ $LERB_VERBOSE = ENV["LERB_VERBOSE"]
7
+
6
8
  class LERB < ERB
7
9
  class Error < StandardError; end
8
10
  class BuildError < Error; end
9
11
  class ExecutionError < Error; end
10
12
 
11
- # loaders
13
+ # output
12
14
 
13
- def self.load path_radical
14
- load_from_folder(path_radical) + load_from_file("#{path_radical}.rb")
15
+ def self.puts string=nil
16
+ super if $LERB_VERBOSE
15
17
  end
16
18
 
17
- def self.load_from_file path
18
- ret = []
19
-
20
- fname = path
21
- return ret unless File.exist? path
19
+ # loaders
22
20
 
23
- lines = File.readlines fname
21
+ DEFAULT_KEY = "inline.txt.erb"
24
22
 
25
- lineno = lines.index "__END__\n"
26
- return ret if lineno.nil?
23
+ def self.load path_radical
24
+ erbs = []
27
25
 
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>"]
26
+ "#{path_radical}.rb".tap do |filename|
27
+ _load erbs, filename
28
+ end
31
29
 
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
30
+ Dir.glob("#{path_radical}.*.erb").each do |filename|
31
+ _load erbs, filename
38
32
  end
39
33
 
40
- ret
41
- end
34
+ Dir.glob("#{path_radical}/*.*.erb").each do |filename|
35
+ _load erbs, filename
36
+ end
42
37
 
43
- def self.load_from_folder path
44
- ret = []
38
+ #
45
39
 
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
40
+ puts "#{erbs.size} erbs".on_red
41
+ erbs.each do |h|
42
+ puts "key: #{h.key}".on_green
52
43
  end
53
44
 
54
- ret
45
+ erbs
55
46
  end
56
47
 
57
- # format
48
+ def self._load erbs, filename
49
+ is_erb = filename.end_with? ".erb"
50
+ is_ignoring_ruby = !is_erb
51
+ is_accepting_views = false
52
+
53
+ puts
54
+ puts "LERB filename: #{filename}".on_red
55
+
56
+ puts "LERB is_erb: #{is_erb}".on_red
57
+ puts "LERB is_ignoring_ruby: #{is_ignoring_ruby}".on_red
58
+ puts "LERB is_accepting_views: #{is_accepting_views}".on_red
59
+
60
+ current_lineno = 0
61
+ current_content = ""
62
+ current_key = is_erb ? filename.split("/").last : DEFAULT_KEY
63
+
64
+ if current_key
65
+ puts "LERB declare: #{current_key} | because not erb".green
66
+ end
58
67
 
59
- TAG_FORMATS = %w|xml html|
68
+ File.readlines(filename).each.with_index do |line, lineno|
69
+ is_line_end = line == "__END__\n"
70
+
71
+ # stop ignoring ruby lines if line is __END__
72
+ # move to next line if ignoring ruby lines
73
+
74
+ if is_ignoring_ruby
75
+ puts "LERB ignore: #{lineno}: #{line[0..-2]}".light_black
76
+ if is_line_end
77
+ is_ignoring_ruby = false
78
+ is_accepting_views = true
79
+ current_lineno = lineno + 1
80
+ puts "LERB declare: #{current_key} | current".green if current_key
81
+ end
82
+ next
83
+ end
84
+
85
+ if is_accepting_views && line[0..6] == "# view "
86
+ _load_into erbs, filename, current_lineno, current_key, current_content
87
+ current_key = line[7..-1].strip
88
+ current_lineno = lineno + 1
89
+ current_content = ""
90
+ puts "LERB declare: #{current_key} | #{lineno}: #{line[0..-2]}".green
91
+ else
92
+ current_content += line
93
+ puts "LERB keeping: #{lineno}: #{line[0..-2]}".bold.white
94
+ end
95
+
96
+ if is_line_end
97
+ puts "LERB warning: #{lineno}: #{line[0..-2]} found! No longer accepting views".light_yellow
98
+ is_accepting_views = false
99
+ end
100
+ end
60
101
 
61
- def tags?
62
- TAG_FORMATS.include? format
102
+ _load_into erbs, filename, current_lineno, current_key, current_content
103
+
104
+ erbs
63
105
  end
64
106
 
65
- # source
107
+ def self._load_into erbs, filename, lineno, key, content
108
+ return unless key
109
+ return unless key.end_with? "erb"
110
+ return if content.strip.empty?
66
111
 
67
- SOURCES = %i|file folder|
112
+ content += "\n" if content[-1] != "\n"
68
113
 
69
- def file?
70
- @source == :file
114
+ erbs.push new filename, lineno, key, content
71
115
  end
72
116
 
73
- def folder?
74
- @source == :folder
117
+ # format
118
+
119
+ TAG_FORMATS = %w|xml html|
120
+
121
+ def tags?
122
+ TAG_FORMATS.include? format
75
123
  end
76
124
 
77
125
  # constructor
78
126
 
79
127
  TRIM_MODE = "<>-"
80
128
 
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
129
+ attr_reader :key, :name, :format
85
130
 
131
+ def initialize filename, lineno, key, content
86
132
  segments = key.split("/").last.split(".")
87
133
  name, format = segments[0..1]
88
134
 
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
135
+ if format.gsub(/[^a-z0-9]/, "") != format
136
+ raise BuildError, "key '#{key}' has an invalid format '#{format}'"
137
+ end
92
138
 
93
139
  super content, trim_mode: TRIM_MODE
94
- @source, @key, @name, @format, self.filename, self.lineno = source, key, name, format, filename, lineno
140
+ self.filename, self.lineno, @key, @name, @format = filename, lineno, key, name, format
95
141
  end
96
142
 
97
143
  # result