Class: AssetsRequest

Inherits:
AppRequest show all
Defined in:
app/web/requests/assets_request.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Liza::Controller

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
  headers = {
    "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, headers, [body]]
end

#random_colorObject



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_stringObject



57
58
59
# File 'app/web/requests/assets_request.rb', line 57

def random_string
  Array("A".."z").sample(16).join
end

#render_action_admin_format_cssObject



33
34
35
# File 'app/web/requests/assets_request.rb', line 33

def render_action_admin_format_css
  "body { background: gray }"
end

#render_action_admin_format_jsObject

helper methods



29
30
31
# File 'app/web/requests/assets_request.rb', line 29

def render_action_admin_format_js
  "alert('it works')"
end

#render_action_app_format_cssObject



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

#render_action_app_format_jsObject



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