lizarb 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) 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/net/{models/app_model.rb → records/app_record.rb} +2 -1
  27. data/app/net/{models/post_model_test.rb → records/app_record_test.rb} +2 -2
  28. data/app/net/records/post_record.rb +4 -0
  29. data/app/net/{models/app_model_test.rb → records/post_record_test.rb} +2 -2
  30. data/app/net/records/user_record.rb +4 -0
  31. data/app/net/{models/user_model_test.rb → records/user_record_test.rb} +2 -2
  32. data/app/web/requests/api_request.rb +8 -7
  33. data/app/web/requests/assets_request.rb +12 -13
  34. data/app/web/requests/root_request.rb +6 -7
  35. data/app/web/requests/root_request_test.rb +1 -1
  36. data/app/web_box.rb +8 -0
  37. data/app_new/Procfile +1 -1
  38. data/exe/lrb +3 -0
  39. data/lib/app.rb +18 -14
  40. data/lib/dev_system/dev/controllers/bench/not_found_bench.rb +29 -0
  41. data/lib/dev_system/dev/controllers/bench/not_found_bench_test.rb +14 -0
  42. data/lib/dev_system/dev/controllers/command/bench_command.rb +11 -1
  43. data/lib/dev_system/dev/controllers/command/generate_command.rb +14 -2
  44. data/lib/dev_system/dev/controllers/command/not_found_command.rb +29 -0
  45. data/lib/dev_system/dev/controllers/command/{dev_command_test.rb → not_found_command_test.rb} +2 -2
  46. data/lib/dev_system/dev/controllers/command/{dev_command.rb → terminal_command.rb} +1 -1
  47. data/lib/dev_system/dev/controllers/command/terminal_command_test.rb +14 -0
  48. data/lib/dev_system/dev/controllers/command/test_command.rb +6 -2
  49. data/lib/dev_system/dev/controllers/generator_dsl_main_part.rb +1 -1
  50. data/lib/dev_system/dev/controllers/generators/app_generator.rb +30 -5
  51. data/lib/dev_system/dev/controllers/generators/generator_generator/generator.rb.erb +18 -0
  52. data/lib/dev_system/dev/controllers/generators/generator_generator/generator_test.rb.erb +12 -0
  53. data/lib/dev_system/dev/controllers/generators/generator_generator/template.rb.erb +9 -0
  54. data/lib/dev_system/dev/controllers/generators/generator_generator/template_test.rb.erb +12 -0
  55. data/lib/dev_system/dev/controllers/generators/generator_generator.rb +30 -0
  56. data/lib/dev_system/dev/controllers/generators/generator_generator_test.rb +12 -0
  57. data/lib/dev_system/dev/controllers/generators/not_found_generator.rb +29 -0
  58. data/lib/dev_system/dev/controllers/generators/not_found_generator_test.rb +14 -0
  59. data/lib/dev_system/dev/controllers/shell/bin_shell.rb +22 -0
  60. data/lib/dev_system/dev/controllers/shell/bin_shell_test.rb +87 -0
  61. data/lib/dev_system/dev/controllers/shell/dir_shell.rb +27 -0
  62. data/lib/dev_system/dev/controllers/shell/dir_shell_test.rb +73 -0
  63. data/lib/dev_system/dev/controllers/shell/file_shell.rb +56 -26
  64. data/lib/dev_system/dev/controllers/shell/file_shell_test.rb +143 -7
  65. data/lib/dev_system/dev/controllers/shell/text_shell.rb +23 -0
  66. data/lib/dev_system/dev/controllers/shell/text_shell_test.rb +84 -0
  67. data/lib/dev_system/dev/controllers/shell.rb +26 -14
  68. data/lib/dev_system/dev/controllers/shell_test.rb +42 -9
  69. data/lib/dev_system/dev/panels/command_panel.rb +21 -1
  70. data/lib/dev_system/dev/panels/log_panel.rb +1 -1
  71. data/lib/lerb.rb +106 -0
  72. data/lib/liza/base/controller.rb +2 -0
  73. data/lib/liza/base/panel.rb +6 -5
  74. data/lib/liza/base_parts/controller_renderer_part.rb +140 -0
  75. data/lib/liza/base_parts/controller_renderer_part_test.rb +16 -0
  76. data/lib/liza/meta/part_extension.rb +6 -1
  77. data/lib/liza/ruby_test.rb +9 -0
  78. data/lib/liza/ruby_tests/module_test.rb +21 -0
  79. data/lib/liza/ruby_tests/string_test.rb +59 -0
  80. data/lib/liza/test/test.rb +3 -1
  81. data/lib/liza/test/test_test.rb +108 -15
  82. data/lib/liza/test_parts/test_assertions_advanced_part.rb +127 -0
  83. data/lib/liza/test_parts/test_assertions_part.rb +7 -6
  84. data/lib/liza/test_parts/test_dsl_part.rb +37 -89
  85. data/lib/liza/test_parts/test_log_part.rb +124 -0
  86. data/lib/liza/test_parts/test_tree_part.rb +139 -0
  87. data/lib/liza/unit.rb +2 -0
  88. data/lib/liza/unit_parts/unit_procedure_part.rb +17 -0
  89. data/lib/liza/unit_parts/unit_procedure_part_test.rb +65 -0
  90. data/lib/liza.rb +5 -0
  91. data/lib/lizarb/ruby/module.rb +17 -0
  92. data/lib/lizarb/ruby/string.rb +10 -2
  93. data/lib/lizarb/version.rb +1 -1
  94. data/lib/lizarb.rb +24 -2
  95. data/lib/net_system/net/controllers/record.rb +31 -0
  96. data/lib/net_system/net/controllers/{model_test.rb → record_test.rb} +2 -2
  97. data/lib/web_system/dev/rack_command.rb +26 -0
  98. data/lib/web_system/dev/request_command.rb +143 -0
  99. data/lib/web_system/dev/web_command.rb +3 -34
  100. data/lib/web_system/web/controllers/rack.rb +8 -0
  101. data/lib/web_system/web/controllers/rack_test.rb +18 -0
  102. data/lib/web_system/web/controllers/request/client_error_request.rb +0 -1
  103. data/lib/web_system/web/controllers/request/not_found_request.rb +0 -1
  104. data/lib/web_system/web/controllers/request/server_error_request.rb +0 -1
  105. data/lib/web_system/web/panels/rack_panel.rb +44 -0
  106. data/lib/web_system/web/panels/rack_panel_test.rb +14 -0
  107. data/lib/web_system/web/panels/request_panel.rb +51 -32
  108. data/lib/web_system/web/panels/request_panel_test.rb +28 -9
  109. data/lib/web_system/web/web_box.rb +12 -0
  110. data/lizarb.gemspec +2 -2
  111. metadata +68 -25
  112. data/app/dev/commands/example_command.rb +0 -57
  113. data/app/dev/commands/example_command_test.rb +0 -43
  114. data/app/dev/commands/macro_child_command.rb +0 -32
  115. data/app/dev/commands/macro_child_command_test.rb +0 -7
  116. data/app/dev/commands/macro_parent_command.rb +0 -70
  117. data/app/dev/commands/macro_parent_command_test.rb +0 -7
  118. data/app/dev/commands/my_command.rb +0 -7
  119. data/app/dev/commands/my_command_test.rb +0 -7
  120. data/app/dev/generators/model_generator.rb +0 -46
  121. data/app/net/models/post_model.rb +0 -4
  122. data/app/net/models/user_model.rb +0 -4
  123. data/lib/liza/test_parts/test_context_part.rb +0 -81
  124. data/lib/net_system/net/controllers/model.rb +0 -31
@@ -1,29 +1,59 @@
1
- class DevSystem
2
- class FileShell < Shell
3
- require "fileutils"
4
-
5
- def self.create_folder folder, write_log = true
6
- log "Creating folder #{folder}" if write_log
7
- FileUtils.mkdir_p folder
8
- end
9
-
10
- def self.write folder, filename, content
11
- create_folder folder, false
12
- fname = "#{folder}/#{filename}"
13
- log "Writing #{fname} with #{content.size} bytes"
14
- File.write fname, content
15
- end
16
-
17
- def self.touch folder, filename
18
- create_folder folder, false
19
- fname = "#{folder}/#{filename}"
20
- log "Touching #{fname}"
21
- FileUtils.touch fname
22
- end
23
-
24
- def self.gitkeep folder
25
- touch folder, ".gitkeep"
26
- end
1
+ class DevSystem::FileShell < DevSystem::Shell
27
2
 
3
+ def self._raise_if_blank path
4
+ raise ArgumentError, "Path is required" if path.nil? || path.to_s.empty?
28
5
  end
6
+
7
+ def self._raise_if_not_exists path
8
+ raise ArgumentError, "File does not exist at '#{path}'" unless exist? path
9
+ end
10
+
11
+ #
12
+
13
+ def self.exist? path
14
+ log :normal, "Checking if file exists at '#{path}'"
15
+ _raise_if_blank path
16
+
17
+ File.exist? path
18
+ end
19
+
20
+ def self.size path
21
+ log :normal, "Getting size of file at '#{path}'"
22
+ _raise_if_not_exists path
23
+
24
+ File.size path
25
+ end
26
+
27
+ #
28
+
29
+ def self.directory? path
30
+ log :normal, "Checking if '#{path}' is a directory"
31
+ _raise_if_blank path
32
+
33
+ File.directory? path
34
+ end
35
+
36
+ def self.file? path
37
+ log :normal, "Checking if '#{path}' is a file"
38
+ _raise_if_blank path
39
+
40
+ File.file? path
41
+ end
42
+
43
+ #
44
+
45
+ def self.touch path
46
+ log :normal, "Touching '#{path}'"
47
+ _raise_if_blank path
48
+
49
+ dir = File.dirname(path)
50
+ DevSystem::DirShell.create dir
51
+
52
+ FileUtils.touch path
53
+ end
54
+
55
+ def self.gitkeep path
56
+ touch "#{path}/.gitkeep"
57
+ end
58
+
29
59
  end
@@ -1,14 +1,150 @@
1
- class DevSystem
2
- class FileShellTest < ShellTest
1
+ class DevSystem::FileShellTest < DevSystem::ShellTest
3
2
 
4
- test :subject_class do
5
- assert subject_class == DevSystem::FileShell
3
+ # before do
4
+ # puts tmp.to_s.magenta
5
+ # end
6
+
7
+ def tmp_dir
8
+ @tmp_dir ||= begin
9
+ name = self.class.name.split("::").map(&:snakefy).join "_"
10
+ time = Time.now.strftime "%Y%m%d_%H%M%S"
11
+ random = SecureRandom.hex 4
12
+ ret = Pathname.new(Dir.pwd).join "tmp/test_#{App.mode}_#{name}_#{time}_#{random}"
13
+ FileUtils.mkdir_p ret
14
+ log "Created tmp_dir: #{ret}"
15
+ ret
16
+ end
17
+ end
18
+
19
+ after do
20
+ # NOTE: @tmp_dir does not create a new directory for each test
21
+ if @tmp_dir
22
+ FileUtils.rm_rf @tmp_dir
23
+ log "Removed tmp_dir: #{@tmp_dir}"
24
+ end
25
+ end
26
+
27
+ #
28
+
29
+ test :subject_class do
30
+ assert subject_class == DevSystem::FileShell
31
+ end
32
+
33
+ test :settings do
34
+ assert subject_class.log_level == :normal
35
+ assert subject_class.log_color == :green
36
+ end
37
+
38
+ #
39
+
40
+ test :subject_class, :exist?, :true do
41
+ assert subject_class.exist? __FILE__
42
+ end
43
+
44
+ test :subject_class, :exist?, :false do
45
+ refute subject_class.exist? "does_not_exist_#{rand 999}"
46
+ end
47
+
48
+ test :subject_class, :exist?, :raise do
49
+ assert_raises ArgumentError do
50
+ subject_class.exist? nil
51
+ end
52
+
53
+ assert_raises ArgumentError do
54
+ subject_class.exist? ""
55
+ end
56
+ end
57
+
58
+ #
59
+
60
+ test :subject_class, :size, true do
61
+ assert subject_class.size(__FILE__).positive?
62
+ end
63
+
64
+ test :subject_class, :size, :raise do
65
+ assert_raises ArgumentError do
66
+ subject_class.size nil
67
+ end
68
+
69
+ assert_raises ArgumentError do
70
+ subject_class.size ""
71
+ end
72
+
73
+ assert_raises ArgumentError do
74
+ subject_class.size "does_not_exist_#{rand 999}"
75
+ end
76
+ end
77
+
78
+ #
79
+
80
+ test :subject_class, :directory?, true do
81
+ assert subject_class.directory? Dir.pwd
82
+ end
83
+
84
+ test :subject_class, :directory?, false do
85
+ refute subject_class.directory? __FILE__
86
+ refute subject_class.directory? "does_not_exist"
87
+ end
88
+
89
+ test :subject_class, :directory?, :raise do
90
+ assert_raises ArgumentError do
91
+ subject_class.directory? nil
92
+ end
93
+
94
+ assert_raises ArgumentError do
95
+ subject_class.directory? ""
96
+ end
97
+ end
98
+
99
+ test :subject_class, :file?, true do
100
+ assert subject_class.file? __FILE__
101
+ end
102
+
103
+ test :subject_class, :file?, false do
104
+ refute subject_class.file? Dir.pwd
105
+ refute subject_class.file? "does_not_exist_#{rand 999}"
106
+ end
107
+
108
+ test :subject_class, :file?, :raise do
109
+ assert_raises ArgumentError do
110
+ subject_class.file? nil
6
111
  end
7
112
 
8
- test :settings do
9
- assert subject_class.log_level == :normal
10
- assert subject_class.log_color == :green
113
+ assert_raises ArgumentError do
114
+ subject_class.file? ""
11
115
  end
116
+ end
117
+
118
+ #
119
+
120
+ test :subject_class, :touch, true do
121
+ path = tmp_dir.join "touch_#{Time.now.to_i}"
122
+ refute subject_class.exist? path
12
123
 
124
+ assert subject_class.touch path
125
+ assert subject_class.exist? path
13
126
  end
127
+
128
+ test :subject_class, :touch, :raise do
129
+ assert_raises ArgumentError do
130
+ subject_class.touch nil
131
+ end
132
+
133
+ assert_raises ArgumentError do
134
+ subject_class.touch ""
135
+ end
136
+ end
137
+
138
+ #
139
+
140
+ test :subject_class, :gitkeep do
141
+ path = tmp_dir.join "gitkeep_#{Time.now.to_i}"
142
+ refute subject_class.exist? path
143
+
144
+ assert subject_class.gitkeep path
145
+ assert subject_class.exist? path
146
+ end
147
+
148
+ #
149
+
14
150
  end
@@ -0,0 +1,23 @@
1
+ class DevSystem::TextShell < DevSystem::FileShell
2
+
3
+ set :create_dir, true
4
+
5
+ def self.read path
6
+ log "Reading #{path}"
7
+ _raise_if_blank path
8
+ _raise_if_not_exists path
9
+
10
+ File.read path
11
+ end
12
+
13
+ def self.write path, content, create_dir: nil
14
+ log "Writing #{content.to_s.size} characters (#{content.encoding}) to #{path}"
15
+ _raise_if_blank path
16
+
17
+ create_dir = get :create_dir if create_dir.nil?
18
+ DevSystem::DirShell.create File.dirname path if create_dir
19
+
20
+ File.write path, content
21
+ end
22
+
23
+ end
@@ -0,0 +1,84 @@
1
+ class DevSystem::TextShellTest < DevSystem::FileShellTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == DevSystem::TextShell
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
+ #
13
+
14
+ test :subject_class, :read, true do
15
+ assert subject_class.read(__FILE__).size.positive?
16
+ end
17
+
18
+ test :subject_class, :read, :raise do
19
+ assert_raises ArgumentError do
20
+ subject_class.read nil
21
+ end
22
+
23
+ assert_raises ArgumentError do
24
+ subject_class.read ""
25
+ end
26
+
27
+ assert_raises ArgumentError do
28
+ subject_class.read "does_not_exist_#{rand 999}"
29
+ end
30
+ end
31
+
32
+ #
33
+
34
+ test :subject_class, :write, :raise do
35
+ assert_raises ArgumentError do
36
+ subject_class.write nil, "content"
37
+ end
38
+
39
+ assert_raises ArgumentError do
40
+ subject_class.write "", "content"
41
+ end
42
+ end
43
+
44
+ test :subject_class, :write, true do
45
+ path = tmp_dir.join "write_#{Time.now.to_i}"
46
+
47
+ refute subject_class.exist? path
48
+ assert subject_class.write path, "content"
49
+
50
+ assert subject_class.exist? path
51
+ assert subject_class.read(path) == "content"
52
+ end
53
+
54
+ test :subject_class, :write, :encoding do
55
+ path = tmp_dir.join "write_#{Time.now.to_i}"
56
+ s1 = "content"
57
+
58
+ refute subject_class.exist? path
59
+ assert subject_class.write path, s1
60
+
61
+ s2 = subject_class.read path
62
+ assert_equality s1, s2
63
+ assert_equality s1.encoding, s2.encoding
64
+
65
+ assert_equality s1.encoding, Encoding::UTF_8
66
+ assert_equality s2.encoding, Encoding::UTF_8
67
+ end
68
+
69
+ test :subject_class, :write, :create_dir do
70
+ path = tmp_dir.join "write_dir_#{Time.now.to_i}/a/b/c"
71
+
72
+ refute subject_class.exist? path
73
+
74
+ assert_raises Errno::ENOENT do
75
+ assert subject_class.write path, "content", create_dir: false
76
+ end
77
+
78
+ assert subject_class.write path, "content", create_dir: true
79
+
80
+ assert subject_class.exist? path
81
+ assert subject_class.read(path) == "content"
82
+ end
83
+
84
+ end
@@ -1,19 +1,31 @@
1
- class DevSystem
2
- class Shell < Liza::Controller
3
- def windows?
4
- RUBY_PLATFORM =~ /win32/
5
- end
1
+ class DevSystem::Shell < Liza::Controller
6
2
 
7
- def unix?
8
- linux? || mac?
9
- end
3
+ # Check if the current platform is Windows
4
+ def self.windows?
5
+ @windows || Gem.win_platform?
6
+ end
7
+
8
+ # Check if the current platform is Unix or Unix-like
9
+ def self.unix?
10
+ @unix || !windows?
11
+ end
10
12
 
11
- def linux?
12
- RUBY_PLATFORM =~ /linux/
13
- end
13
+ # Check if the current platform is Linux
14
+ def self.linux?
15
+ @linux || (unix? && RbConfig::CONFIG['host_os'].include?("linux"))
16
+ end
14
17
 
15
- def mac?
16
- RUBY_PLATFORM =~ /darwin/
17
- end
18
+ # Check if the current platform is Mac OS
19
+ def self.mac?
20
+ @mac || (unix? && RbConfig::CONFIG['host_os'].include?("darwin"))
18
21
  end
22
+
23
+ # Return the current operating system as a symbol
24
+ def self.os
25
+ return :windows if windows?
26
+ return :linux if linux?
27
+ return :mac if mac?
28
+ :unix
29
+ end
30
+
19
31
  end
@@ -1,13 +1,46 @@
1
- class DevSystem
2
- class ShellTest < Liza::ControllerTest
1
+ class DevSystem::ShellTest < Liza::ControllerTest
3
2
 
4
- test :subject_class do
5
- assert subject_class == DevSystem::Shell
6
- end
3
+ test :subject_class do
4
+ assert subject_class == DevSystem::Shell
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
+ #
13
+
14
+ test :subject_class, :windows? do
15
+ original = subject_class.windows?
16
+ subject_class.instance_variable_set(:@windows, true)
17
+ assert subject_class.windows?
18
+ ensure
19
+ subject_class.instance_variable_set(:@windows, original)
20
+ end
7
21
 
8
- test :settings do
9
- assert subject_class.log_level == :normal
10
- assert subject_class.log_color == :green
11
- end
22
+ test :subject_class, :unix? do
23
+ original = subject_class.unix?
24
+ subject_class.instance_variable_set(:@unix, true)
25
+ assert subject_class.unix?
26
+ ensure
27
+ subject_class.instance_variable_set(:@unix, original)
12
28
  end
29
+
30
+ test :subject_class, :linux? do
31
+ original = subject_class.linux?
32
+ subject_class.instance_variable_set(:@linux, true)
33
+ assert subject_class.linux?
34
+ ensure
35
+ subject_class.instance_variable_set(:@linux, original)
36
+ end
37
+
38
+ test :subject_class, :mac? do
39
+ original = subject_class.mac?
40
+ subject_class.instance_variable_set(:@mac, true)
41
+ assert subject_class.mac?
42
+ ensure
43
+ subject_class.instance_variable_set(:@mac, original)
44
+ end
45
+
13
46
  end
@@ -2,9 +2,29 @@ class DevSystem
2
2
  class CommandPanel < Liza::Panel
3
3
 
4
4
  def call args
5
- command_klass = Liza.const "#{args[0]}_command"
5
+ # 1. LOG
6
+
7
+ log "call #{args}"
8
+
9
+ # 2. FIND command
10
+
11
+ return call_not_found args if args.none?
12
+
13
+ command = args[0]
14
+
15
+ log({command:})
16
+
17
+ command_klass = Liza.const "#{command}_command"
18
+
19
+ # 3. CALL
20
+
6
21
  command_klass.call args[1..-1]
22
+ rescue Liza::ConstNotFound
23
+ call_not_found args
7
24
  end
8
25
 
26
+ def call_not_found args
27
+ Liza::NotFoundCommand.call args
28
+ end
9
29
  end
10
30
  end
@@ -3,7 +3,7 @@ class DevSystem
3
3
 
4
4
  # https://rubyapi.org/3.1/o/logger
5
5
  def call string
6
- puts string
6
+ puts "lizarb #{Lizarb.thread_id.to_s.rjust_zeroes 3} #{string}"
7
7
  end
8
8
 
9
9
  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
@@ -1,5 +1,7 @@
1
1
  module Liza
2
2
  class Controller < Unit
3
+ part :controller_renderer
4
+
3
5
  inherited_explicitly_sets_system
4
6
 
5
7
  def self.on_connected box_klass, panel
@@ -18,20 +18,21 @@ module Liza
18
18
  @name = name
19
19
  end
20
20
 
21
- def log string
21
+ def log log_level = :normal, string
22
+ raise "invalid log_level `#{log_level}`" unless LOG_LEVELS.keys.include? log_level
23
+ return unless log_level? log_level
24
+
22
25
  source = box.to_s
23
26
 
24
27
  x = source.size
25
-
26
28
  source = source.bold.colorize log_color
27
29
 
28
30
  y = source.size
29
-
30
31
  source = "#{source}.#{@name}".ljust(LOG_JUST+y-x)
31
32
 
32
33
  string = "#{source} #{string}"
33
-
34
- super string
34
+
35
+ DevBox.logs.call string
35
36
  end
36
37
 
37
38
  end