Class: AssetsRequest
Class Method Summary
collapse
Instance Method Summary
collapse
color, inherited, on_connected
Methods inherited from Liza::Unit
const_missing, division, part, system, #system, test_class
Class Method Details
.call(env) ⇒ Object
3
4
5
|
# File 'app/web/requests/assets_request.rb', line 3
def self.call env
new.call env
end
|
Instance Method Details
#call(env) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'app/web/requests/assets_request.rb', line 7
def call env
action = env["LIZA_ACTION"].to_sym
format = env["LIZA_FORMAT"].to_sym
status = 200
= {
"Framework" => "Liza #{Lizarb::VERSION}"
}
body = ""
body = render_action_admin_format_js if action == :admin && format == :js
body = render_action_admin_format_css if action == :admin && format == :css
body = render_action_app_format_js if action == :app && format == :js
body = render_action_app_format_css if action == :app && format == :css
[status, , [body]]
end
|
#random_color ⇒ Object
61
62
63
64
65
66
67
68
|
# File 'app/web/requests/assets_request.rb', line 61
def random_color
s = ""
3.times do |i|
s += Array(3..9).sample.to_s(16)
s += "0"
end
s
end
|
#random_string ⇒ Object
57
58
59
|
# File 'app/web/requests/assets_request.rb', line 57
def random_string
Array("A".."z").sample(16).join
end
|
33
34
35
|
# File 'app/web/requests/assets_request.rb', line 33
def render_action_admin_format_css
"body { background: gray }"
end
|
29
30
31
|
# File 'app/web/requests/assets_request.rb', line 29
def render_action_admin_format_js
"alert('it works')"
end
|
48
49
50
51
52
53
54
55
|
# File 'app/web/requests/assets_request.rb', line 48
def render_action_app_format_css
<<-CODE
body {
background: ##{random_color};
font-family: Roboto;
}
CODE
end
|
37
38
39
40
41
42
43
44
45
46
|
# File 'app/web/requests/assets_request.rb', line 37
def render_action_app_format_js
<<-CODE
window.onload = () => {
var h1 = document.createElement("h1");
h1.setAttribute("style", "color: white");
h1.innerHTML="JS file has been loaded. Random String: #{random_string}";
document.body.append(h1);
}
CODE
end
|