lizarb 0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/CHANGELOG.md +13 -2
- data/Gemfile +22 -2
- data/Gemfile.lock +52 -0
- data/README.md +88 -12
- data/app/dev/benches/app_bench.rb +5 -0
- data/app/dev/benches/app_bench_test.rb +7 -0
- data/app/dev/benches/loops_bench.rb +148 -0
- data/app/dev/benches/loops_bench_test.rb +11 -0
- data/app/dev/commands/app_command.rb +5 -0
- data/app/dev/commands/app_command_test.rb +7 -0
- data/app/dev/commands/example_command.rb +57 -0
- data/app/dev/commands/example_command_test.rb +43 -0
- data/app/dev/commands/macro_child_command.rb +32 -0
- data/app/dev/commands/macro_child_command_test.rb +7 -0
- data/app/dev/commands/macro_parent_command.rb +70 -0
- data/app/dev/commands/macro_parent_command_test.rb +7 -0
- data/app/dev/commands/my_command.rb +7 -0
- data/app/dev/commands/my_command_test.rb +7 -0
- data/app/dev/commands/new_command.rb +9 -0
- data/app/dev/commands/new_command_test.rb +7 -0
- data/app/dev/generators/bench_generator.rb +67 -0
- data/app/dev/generators/bench_generator_test.rb +12 -0
- data/app/dev/generators/command_generator.rb +51 -0
- data/app/dev/generators/command_generator_test.rb +12 -0
- data/app/dev/generators/model_generator.rb +46 -0
- data/app/dev/generators/model_generator_test.rb +12 -0
- data/app/dev/generators/request_generator.rb +63 -0
- data/app/dev/generators/request_generator_test.rb +12 -0
- data/app/dev_box.rb +13 -0
- data/app/happy/axos/axo.rb +50 -0
- data/app/happy_box.rb +8 -0
- data/app/net/databases/redis_db.rb +5 -0
- data/app/net/databases/redis_db_test.rb +12 -0
- data/app/net/databases/sqlite_db.rb +11 -0
- data/app/net/databases/sqlite_db_test.rb +12 -0
- data/app/net/models/app_model.rb +20 -0
- data/app/net/models/app_model_test.rb +8 -0
- data/app/net/models/post_model.rb +4 -0
- data/app/net/models/post_model_test.rb +8 -0
- data/app/net/models/user_model.rb +4 -0
- data/app/net/models/user_model_test.rb +8 -0
- data/app/net_box.rb +21 -0
- data/app/web/requests/api_request.rb +61 -0
- data/app/web/requests/api_request_test.rb +31 -0
- data/app/web/requests/app_request.rb +5 -0
- data/app/web/requests/app_request_test.rb +7 -0
- data/app/web/requests/assets_request.rb +71 -0
- data/app/web/requests/assets_request_test.rb +33 -0
- data/app/web/requests/root_request.rb +55 -0
- data/app/web/requests/root_request_test.rb +31 -0
- data/app/web_box.rb +8 -0
- data/app.code.env +11 -0
- data/app.env +11 -0
- data/app.rb +17 -0
- data/app_new/.gitignore +4 -0
- data/app_new/Gemfile +31 -0
- data/app_new/Procfile +3 -0
- data/exe/Gemfile +3 -0
- data/exe/Gemfile.lock +13 -0
- data/exe/liza +3 -0
- data/exe/lizarb +11 -0
- data/lib/app.rb +200 -0
- data/lib/dev_system/dev/controllers/bench.rb +11 -0
- data/lib/dev_system/dev/controllers/bench_dsl_main_part.rb +60 -0
- data/lib/dev_system/dev/controllers/bench_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command/bench_command.rb +24 -0
- data/lib/dev_system/dev/controllers/command/bench_command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command/dev_command.rb +24 -0
- data/lib/dev_system/dev/controllers/command/dev_command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command/echo_command.rb +11 -0
- data/lib/dev_system/dev/controllers/command/echo_command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command/generate_command.rb +23 -0
- data/lib/dev_system/dev/controllers/command/generate_command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command/test_command.rb +70 -0
- data/lib/dev_system/dev/controllers/command/test_command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command/version_command.rb +9 -0
- data/lib/dev_system/dev/controllers/command/version_command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command.rb +19 -0
- data/lib/dev_system/dev/controllers/command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/generator.rb +11 -0
- data/lib/dev_system/dev/controllers/generator_dsl_main_part.rb +54 -0
- data/lib/dev_system/dev/controllers/generator_test.rb +14 -0
- data/lib/dev_system/dev/controllers/generators/app_generator.rb +71 -0
- data/lib/dev_system/dev/controllers/generators/app_generator_test.rb +14 -0
- data/lib/dev_system/dev/controllers/shell/file_shell.rb +29 -0
- data/lib/dev_system/dev/controllers/shell/file_shell_test.rb +14 -0
- data/lib/dev_system/dev/controllers/shell.rb +19 -0
- data/lib/dev_system/dev/controllers/shell_test.rb +13 -0
- data/lib/dev_system/dev/controllers/terminal/irb_terminal.rb +19 -0
- data/lib/dev_system/dev/controllers/terminal/irb_terminal_test.rb +14 -0
- data/lib/dev_system/dev/controllers/terminal/pry_terminal.rb +12 -0
- data/lib/dev_system/dev/controllers/terminal/pry_terminal_test.rb +14 -0
- data/lib/dev_system/dev/controllers/terminal.rb +19 -0
- data/lib/dev_system/dev/controllers/terminal_test.rb +14 -0
- data/lib/dev_system/dev/dev_box.rb +22 -0
- data/lib/dev_system/dev/dev_box_test.rb +19 -0
- data/lib/dev_system/dev/panels/command_panel.rb +10 -0
- data/lib/dev_system/dev/panels/command_panel_test.rb +23 -0
- data/lib/dev_system/dev/panels/log_panel.rb +10 -0
- data/lib/dev_system/dev/panels/log_panel_test.rb +18 -0
- data/lib/dev_system.rb +8 -0
- data/lib/happy_system/dev/happy_command.rb +11 -0
- data/lib/happy_system/happy/controllers/axo.rb +8 -0
- data/lib/happy_system/happy/happy_box.rb +12 -0
- data/lib/happy_system/happy/happy_box_test.rb +18 -0
- data/lib/happy_system/happy/panels/axo_panel.rb +5 -0
- data/lib/{viral.rb → happy_system.rb} +7 -3
- data/lib/liza/base/box.rb +40 -0
- data/lib/liza/base/box_test.rb +12 -0
- data/lib/liza/base/controller.rb +27 -0
- data/lib/liza/base/controller_test.rb +12 -0
- data/lib/liza/base/panel.rb +38 -0
- data/lib/liza/base/panel_test.rb +16 -0
- data/lib/liza/meta/part.rb +19 -0
- data/lib/liza/meta/part_extension.rb +13 -0
- data/lib/liza/meta/part_test.rb +8 -0
- data/lib/liza/meta/system.rb +20 -0
- data/lib/liza/meta/system_test.rb +13 -0
- data/lib/liza/test/test.rb +11 -0
- data/lib/liza/test/test_test.rb +108 -0
- data/lib/liza/test_parts/test_assertions_part.rb +110 -0
- data/lib/liza/test_parts/test_context_part.rb +81 -0
- data/lib/liza/test_parts/test_dsl_part.rb +122 -0
- data/lib/liza/test_parts/test_subject_part.rb +24 -0
- data/lib/liza/unit.rb +149 -0
- data/lib/liza/unit_test.rb +79 -0
- data/lib/liza.rb +62 -0
- data/lib/lizarb/ruby/class.rb +17 -0
- data/lib/lizarb/ruby/proc.rb +12 -0
- data/lib/lizarb/ruby/string.rb +25 -0
- data/lib/lizarb/ruby/time.rb +9 -0
- data/lib/{viral → lizarb}/version.rb +2 -2
- data/lib/lizarb.rb +68 -0
- data/lib/net_system/dev/net_command.rb +24 -0
- data/lib/net_system/net/controllers/client/redis_client.rb +28 -0
- data/lib/net_system/net/controllers/client/redis_client_test.rb +29 -0
- data/lib/net_system/net/controllers/client/sqlite_client.rb +28 -0
- data/lib/net_system/net/controllers/client/sqlite_client_test.rb +29 -0
- data/lib/net_system/net/controllers/client.rb +5 -0
- data/lib/net_system/net/controllers/client_test.rb +14 -0
- data/lib/net_system/net/controllers/database/redis_db.rb +11 -0
- data/lib/net_system/net/controllers/database/redis_db_test.rb +23 -0
- data/lib/net_system/net/controllers/database/sqlite_db.rb +11 -0
- data/lib/net_system/net/controllers/database/sqlite_db_test.rb +23 -0
- data/lib/net_system/net/controllers/database.rb +33 -0
- data/lib/net_system/net/controllers/database_test.rb +14 -0
- data/lib/net_system/net/controllers/model.rb +31 -0
- data/lib/net_system/net/controllers/model_test.rb +14 -0
- data/lib/net_system/net/net_box.rb +20 -0
- data/lib/net_system/net/net_box_test.rb +19 -0
- data/lib/net_system/net/panels/client_panel.rb +5 -0
- data/lib/net_system/net/panels/client_panel_test.rb +18 -0
- data/lib/net_system/net/panels/database_panel.rb +12 -0
- data/lib/net_system/net/panels/database_panel_test.rb +18 -0
- data/lib/net_system.rb +3 -0
- data/lib/web_system/dev/web_command.rb +42 -0
- data/lib/web_system/web/controllers/request/client_error_request.rb +18 -0
- data/lib/web_system/web/controllers/request/not_found_request.rb +18 -0
- data/lib/web_system/web/controllers/request/server_error_request.rb +20 -0
- data/lib/web_system/web/controllers/request.rb +5 -0
- data/lib/web_system/web/controllers/request_test.rb +18 -0
- data/lib/web_system/web/panels/request_panel.rb +55 -0
- data/lib/web_system/web/panels/request_panel_test.rb +14 -0
- data/lib/web_system/web/web_box.rb +12 -0
- data/lib/web_system/web/web_box_test.rb +18 -0
- data/lib/web_system.rb +5 -0
- data/lizarb.gemspec +44 -0
- data/sig/{viral.rbs → lizarb.rbs} +1 -1
- data/tmp/.gitkeep +0 -0
- data/web_files/favicon.ico +0 -0
- data/web_files/favicon.svg +948 -0
- metadata +226 -13
- data/viral.gemspec +0 -45
@@ -0,0 +1,67 @@
|
|
1
|
+
class BenchGenerator < Liza::Generator
|
2
|
+
main_dsl
|
3
|
+
|
4
|
+
FOLDER = "app/dev/benches"
|
5
|
+
|
6
|
+
generate :controller do
|
7
|
+
folder FOLDER
|
8
|
+
filename "#{name}_bench.rb"
|
9
|
+
content bench_content
|
10
|
+
end
|
11
|
+
|
12
|
+
generate :controller_test do
|
13
|
+
folder FOLDER
|
14
|
+
filename "#{name}_bench_test.rb"
|
15
|
+
content bench_test_content
|
16
|
+
end
|
17
|
+
|
18
|
+
# helper methods
|
19
|
+
|
20
|
+
def bench_content
|
21
|
+
<<~CODE
|
22
|
+
class #{name.camelize}Bench < AppBench
|
23
|
+
|
24
|
+
main_dsl
|
25
|
+
|
26
|
+
setup do
|
27
|
+
N = 1_000_000
|
28
|
+
end
|
29
|
+
|
30
|
+
mark "alternative 1" do
|
31
|
+
i = 0
|
32
|
+
|
33
|
+
while (i += 1) <= N
|
34
|
+
a = "1".to_sym
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
mark "alternative 2" do
|
39
|
+
i = 0
|
40
|
+
|
41
|
+
while (i += 1) <= N
|
42
|
+
a = :"1"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
CODE
|
48
|
+
end
|
49
|
+
|
50
|
+
def bench_test_content
|
51
|
+
<<~CODE
|
52
|
+
class #{name.camelize}BenchTest < Liza::BenchTest
|
53
|
+
|
54
|
+
test :subject_class do
|
55
|
+
assert subject_class == #{name.camelize}Bench
|
56
|
+
end
|
57
|
+
|
58
|
+
test :settings do
|
59
|
+
assert subject_class.log_level == :normal
|
60
|
+
assert subject_class.log_color == :green
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
CODE
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class CommandGenerator < Liza::Generator
|
2
|
+
main_dsl
|
3
|
+
|
4
|
+
FOLDER = "app/dev/commands"
|
5
|
+
|
6
|
+
generate :controller do
|
7
|
+
folder FOLDER
|
8
|
+
filename "#{name}_command.rb"
|
9
|
+
content command_content
|
10
|
+
end
|
11
|
+
|
12
|
+
generate :controller_test do
|
13
|
+
folder FOLDER
|
14
|
+
filename "#{name}_command_test.rb"
|
15
|
+
content command_test_content
|
16
|
+
end
|
17
|
+
|
18
|
+
# helper methods
|
19
|
+
|
20
|
+
def command_content
|
21
|
+
<<~CODE
|
22
|
+
class #{name.camelize}Command < Liza::Command
|
23
|
+
|
24
|
+
def self.call args
|
25
|
+
log :higher, "Called \#{self}.\#{__method__} with args \#{args}"
|
26
|
+
|
27
|
+
#
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
CODE
|
32
|
+
end
|
33
|
+
|
34
|
+
def command_test_content
|
35
|
+
<<~CODE
|
36
|
+
class #{name.camelize}CommandTest < Liza::CommandTest
|
37
|
+
|
38
|
+
test :subject_class do
|
39
|
+
assert subject_class == #{name.camelize}Command
|
40
|
+
end
|
41
|
+
|
42
|
+
test :settings do
|
43
|
+
assert subject_class.log_level == :normal
|
44
|
+
assert subject_class.log_color == :green
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
CODE
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class ModelGenerator < Liza::Generator
|
2
|
+
main_dsl
|
3
|
+
|
4
|
+
FOLDER = "app/net/models"
|
5
|
+
|
6
|
+
generate :controller do
|
7
|
+
folder FOLDER
|
8
|
+
filename "#{name}_model.rb"
|
9
|
+
content model_content name
|
10
|
+
end
|
11
|
+
|
12
|
+
generate :controller_test do
|
13
|
+
folder FOLDER
|
14
|
+
filename "#{name}_model_test.rb"
|
15
|
+
content model_test_content name
|
16
|
+
end
|
17
|
+
|
18
|
+
# helper methods
|
19
|
+
|
20
|
+
def model_content name
|
21
|
+
<<~CODE
|
22
|
+
class #{name.camelize}Model < AppModel
|
23
|
+
set :table, :#{name}s
|
24
|
+
|
25
|
+
end
|
26
|
+
CODE
|
27
|
+
end
|
28
|
+
|
29
|
+
def model_test_content name
|
30
|
+
<<~CODE
|
31
|
+
class #{name.camelize}ModelTest < Liza::ModelTest
|
32
|
+
|
33
|
+
test :subject_class do
|
34
|
+
assert subject_class == #{name.camelize}Model
|
35
|
+
end
|
36
|
+
|
37
|
+
test :settings do
|
38
|
+
assert subject_class.log_level == :normal
|
39
|
+
assert subject_class.log_color == :red
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
CODE
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
class RequestGenerator < Liza::Generator
|
2
|
+
main_dsl
|
3
|
+
|
4
|
+
FOLDER = "app/web/requests"
|
5
|
+
|
6
|
+
generate :controller do
|
7
|
+
folder "app/web/requests"
|
8
|
+
filename "#{name}_request.rb"
|
9
|
+
content request_content name
|
10
|
+
end
|
11
|
+
|
12
|
+
generate :controller_test do
|
13
|
+
folder "app/web/requests"
|
14
|
+
filename "#{name}_request_test.rb"
|
15
|
+
content request_test_content name
|
16
|
+
end
|
17
|
+
|
18
|
+
# helper methods
|
19
|
+
|
20
|
+
def request_content name
|
21
|
+
<<~CODE
|
22
|
+
class #{name.camelize}Request < Liza::Request
|
23
|
+
|
24
|
+
def self.call env
|
25
|
+
path = env["REQUEST_PATH"]
|
26
|
+
log :higher, "Called \#{self}.\#{__method__} with path \#{path}"
|
27
|
+
|
28
|
+
#
|
29
|
+
|
30
|
+
status = 200
|
31
|
+
headers = {
|
32
|
+
"Framework" => "Liza \#{Lizarb::VERSION}"
|
33
|
+
}
|
34
|
+
body = "It works!"
|
35
|
+
|
36
|
+
#
|
37
|
+
|
38
|
+
log status
|
39
|
+
[status, headers, [body]]
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
CODE
|
44
|
+
end
|
45
|
+
|
46
|
+
def request_test_content name
|
47
|
+
<<~CODE
|
48
|
+
class #{name.camelize}RequestTest < Liza::RequestTest
|
49
|
+
|
50
|
+
test :subject_class do
|
51
|
+
assert subject_class == #{name.camelize}Request
|
52
|
+
end
|
53
|
+
|
54
|
+
test :settings do
|
55
|
+
assert subject_class.log_level == :normal
|
56
|
+
assert subject_class.log_color == :blue
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
CODE
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
data/app/dev_box.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
class DevBox < Liza::DevBox
|
2
|
+
|
3
|
+
commands do
|
4
|
+
# Set up your command panel per the DSL in http://guides.lizarb.com/panels/command.html
|
5
|
+
|
6
|
+
end
|
7
|
+
|
8
|
+
logs do
|
9
|
+
# Set up your log panel per the DSL in http://guides.lizarb.com/panels/log.html
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
class Axo < Liza::Axo
|
2
|
+
|
3
|
+
# Set up your request controllers per the DSL in http://guides.lizarb.org/controllers/axo.html
|
4
|
+
|
5
|
+
def self.call args
|
6
|
+
cycles = args[0] || "3"
|
7
|
+
sleep_time = args[1] || "3"
|
8
|
+
|
9
|
+
cycles = cycles.to_i
|
10
|
+
sleep_time = sleep_time.to_f / 10
|
11
|
+
|
12
|
+
array = <<-HEREDOC.split("\n")
|
13
|
+
>(.___.)<
|
14
|
+
>(.__.)<
|
15
|
+
>(.___.)< code
|
16
|
+
>(.__.)< code to
|
17
|
+
>(.___.)< code to the
|
18
|
+
>(.__.)< code to the right
|
19
|
+
>(.___.)< code to the right
|
20
|
+
>(.__.)<
|
21
|
+
code >(.___.)<
|
22
|
+
code to >(.__.)<
|
23
|
+
code to the >(.___.)<
|
24
|
+
code to the left >(.__.)<
|
25
|
+
code to the left >(.___.)<
|
26
|
+
>(.__.)<
|
27
|
+
HEREDOC
|
28
|
+
|
29
|
+
cycles.times do |i|
|
30
|
+
array.each_with_index do |s, j|
|
31
|
+
system "clear"
|
32
|
+
|
33
|
+
puts "Axo v0"
|
34
|
+
puts "frame: #{j}/#{array.size}"
|
35
|
+
puts "cycle: #{i}/#{cycles} (#{sleep_time}spf)"
|
36
|
+
puts
|
37
|
+
puts
|
38
|
+
puts " " * 3 + s.bold.light_white
|
39
|
+
puts
|
40
|
+
|
41
|
+
sleep sleep_time
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
puts "That was actually quite a nice workout session!".black.on_white
|
46
|
+
puts " We should do this again some time. ".black.on_white
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/app/happy_box.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
class RedisDbTest < Liza::RedisDbTest
|
2
|
+
|
3
|
+
test :subject_class do
|
4
|
+
assert subject_class == RedisDb
|
5
|
+
assert RedisDb.current.class == RedisDb
|
6
|
+
assert Liza::RedisDb.current.class == RedisDb
|
7
|
+
assert RedisDb.current == Liza::RedisDb.current
|
8
|
+
assert RedisDb.current.client == Liza::RedisDb.current.client
|
9
|
+
assert RedisDb.current.client.conn == Liza::RedisDb.current.client.conn
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class SqliteDb < Liza::SqliteDb
|
2
|
+
|
3
|
+
# Set up your database controllers per the DSL in http://guides.lizarb.org/controllers/database.html
|
4
|
+
|
5
|
+
def table_names
|
6
|
+
result = call "SELECT name FROM sqlite_schema;"
|
7
|
+
result.delete_at 0
|
8
|
+
result.flatten
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class SqliteDbTest < Liza::SqliteDbTest
|
2
|
+
|
3
|
+
test :subject_class do
|
4
|
+
assert subject_class == SqliteDb
|
5
|
+
assert SqliteDb.current.class == SqliteDb
|
6
|
+
assert Liza::SqliteDb.current.class == SqliteDb
|
7
|
+
assert SqliteDb.current == Liza::SqliteDb.current
|
8
|
+
assert SqliteDb.current.client == Liza::SqliteDb.current.client
|
9
|
+
assert SqliteDb.current.client.conn == Liza::SqliteDb.current.client.conn
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class AppModel < Liza::Model
|
2
|
+
db :sqlite
|
3
|
+
|
4
|
+
def self.create_tables!
|
5
|
+
db.call <<-SQLITE
|
6
|
+
CREATE TABLE #{get :table} (
|
7
|
+
id integer,
|
8
|
+
name text,
|
9
|
+
text text
|
10
|
+
);
|
11
|
+
SQLITE
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.drop_tables!
|
15
|
+
db.call <<-SQLITE
|
16
|
+
DROP TABLE #{get :table};
|
17
|
+
SQLITE
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/app/net_box.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
class NetBox < Liza::NetBox
|
2
|
+
|
3
|
+
clients do
|
4
|
+
# Set up your client panel per the DSL in http://guides.lizarb.org/panels/client.html
|
5
|
+
|
6
|
+
set :redis_url, "redis://localhost:6379/15"
|
7
|
+
set :sqlite, "tmp/app.#{Time.now.to_i}.sqlite" if App.mode == :code
|
8
|
+
set :sqlite, "app.#{App.mode}.sqlite"
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
databases do
|
13
|
+
# Set up your database panel per the DSL in http://guides.lizarb.org/panels/database.html
|
14
|
+
|
15
|
+
define :redis, RedisDb.current
|
16
|
+
define :sql, SqliteDb.current
|
17
|
+
define :sqlite, SqliteDb.current
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
class ApiRequest < AppRequest
|
2
|
+
|
3
|
+
def self.call env
|
4
|
+
path = env["REQUEST_PATH"]
|
5
|
+
|
6
|
+
#
|
7
|
+
|
8
|
+
status = 200
|
9
|
+
headers = {
|
10
|
+
"Framework" => "Liza #{Lizarb::VERSION}"
|
11
|
+
}
|
12
|
+
body = ""
|
13
|
+
|
14
|
+
#
|
15
|
+
|
16
|
+
segments = Array path.split("/")[1..-1]
|
17
|
+
|
18
|
+
case segments
|
19
|
+
in "api", "auth", "sign_up"
|
20
|
+
body = render_route_api_auth_sign_up
|
21
|
+
in "api", "auth", "sign_in"
|
22
|
+
body = render_route_api_auth_sign_in
|
23
|
+
in "api", "auth", "account"
|
24
|
+
body = render_route_api_auth_account
|
25
|
+
in "api", "auth", "sign_out"
|
26
|
+
body = render_route_api_auth_sign_out
|
27
|
+
in "api", "users"
|
28
|
+
body = render_route_api_users
|
29
|
+
else
|
30
|
+
status = 404
|
31
|
+
body = render_route_not_found env["LIZA_PATH"]
|
32
|
+
end
|
33
|
+
|
34
|
+
log status
|
35
|
+
[status, headers, [body]]
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.render_route_api_auth_sign_up
|
39
|
+
"route: render_route_api_auth_sign_up"
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.render_route_api_auth_sign_in
|
43
|
+
"route: render_route_api_auth_sign_in"
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.render_route_api_auth_account
|
47
|
+
"route: render_route_api_auth_account"
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.render_route_api_auth_sign_out
|
51
|
+
"route: render_route_api_auth_sign_out"
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.render_route_api_users
|
55
|
+
"route: render_route_api_users"
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.render_route_not_found path
|
59
|
+
"route: render_route_not_found #{path}"
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class ApiRequestTest < AppRequestTest
|
2
|
+
|
3
|
+
test :subject_class do
|
4
|
+
assert subject_class == ApiRequest
|
5
|
+
end
|
6
|
+
|
7
|
+
test :actions, :root do
|
8
|
+
env = {
|
9
|
+
"REQUEST_PATH" => "/",
|
10
|
+
}
|
11
|
+
|
12
|
+
status, headers, body = subject_class.call env
|
13
|
+
|
14
|
+
assert status == 404
|
15
|
+
assert headers["Framework"].to_s.start_with? "Liza"
|
16
|
+
assert body.first.include? "render_route_not_found"
|
17
|
+
end
|
18
|
+
|
19
|
+
test :actions, :sign_up do
|
20
|
+
env = {
|
21
|
+
"REQUEST_PATH" => "/api/auth/sign_up",
|
22
|
+
}
|
23
|
+
|
24
|
+
status, headers, body = subject_class.call env
|
25
|
+
|
26
|
+
assert status == 200
|
27
|
+
assert headers["Framework"].to_s.start_with? "Liza"
|
28
|
+
assert body.first.include? "render_route_api_auth_sign_up"
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
class AssetsRequest < AppRequest
|
2
|
+
|
3
|
+
def self.call env
|
4
|
+
new.call env
|
5
|
+
end
|
6
|
+
|
7
|
+
def call env
|
8
|
+
action = env["LIZA_ACTION"].to_sym
|
9
|
+
format = env["LIZA_FORMAT"].to_sym
|
10
|
+
|
11
|
+
#
|
12
|
+
|
13
|
+
@status = 200
|
14
|
+
@headers = {
|
15
|
+
"Framework" => "Liza #{Lizarb::VERSION}"
|
16
|
+
}
|
17
|
+
@body = ""
|
18
|
+
|
19
|
+
render_action_admin_format_js if action == :admin && format == :js
|
20
|
+
render_action_admin_format_css if action == :admin && format == :css
|
21
|
+
render_action_app_format_js if action == :app && format == :js
|
22
|
+
render_action_app_format_css if action == :app && format == :css
|
23
|
+
|
24
|
+
log @status
|
25
|
+
[@status, @headers, [@body]]
|
26
|
+
end
|
27
|
+
|
28
|
+
# helper methods
|
29
|
+
|
30
|
+
def render_action_admin_format_js
|
31
|
+
@body = "alert('it works')"
|
32
|
+
end
|
33
|
+
|
34
|
+
def render_action_admin_format_css
|
35
|
+
@body = "body { background: gray }"
|
36
|
+
end
|
37
|
+
|
38
|
+
def render_action_app_format_js
|
39
|
+
@body = <<-CODE
|
40
|
+
window.onload = () => {
|
41
|
+
var h1 = document.createElement("h1");
|
42
|
+
h1.setAttribute("style", "color: white");
|
43
|
+
h1.innerHTML="JS file has been loaded. Random String: #{random_string}";
|
44
|
+
document.body.append(h1);
|
45
|
+
}
|
46
|
+
CODE
|
47
|
+
end
|
48
|
+
|
49
|
+
def render_action_app_format_css
|
50
|
+
@body = <<-CODE
|
51
|
+
body {
|
52
|
+
background: ##{random_color};
|
53
|
+
font-family: Roboto;
|
54
|
+
}
|
55
|
+
CODE
|
56
|
+
end
|
57
|
+
|
58
|
+
def random_string
|
59
|
+
Array("A".."z").sample(16).join
|
60
|
+
end
|
61
|
+
|
62
|
+
def random_color
|
63
|
+
s = ""
|
64
|
+
3.times do |i|
|
65
|
+
s += Array(3..9).sample.to_s(16)
|
66
|
+
s += "0"
|
67
|
+
end
|
68
|
+
s
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|