jetski 0.2.5 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/jetski/base_controller.rb +18 -1
- data/lib/jetski/router.rb +30 -12
- data/lib/jetski.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 357bfb82fcc61cf00861ecc1eae23837e62650788714473c98efa2423a982eae
|
|
4
|
+
data.tar.gz: 5548ed79761c0e03d05d2b34173d8c47377a44f6062429e281182a62db885b00
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8fd0699bbbf6e90b28644e3c2511f279644ad928a30e023a12b87eb1360d795f7af9b5bc9d8876614b8f02eab1eacfeaca2da54542e83df84ee093b03ed7818d
|
|
7
|
+
data.tar.gz: 3c455bda8f1ac6074b10a4e6f7801be94dc7065f492bd52e4cde3ac2331d5dfc4abb1828688e2f8fa91f3ad3c429d3f7abd92ddc81b9c4ddcac6db1c824527bd
|
|
@@ -9,7 +9,23 @@ module Jetski
|
|
|
9
9
|
|
|
10
10
|
# Method to render matching view with controller_name/action_name
|
|
11
11
|
|
|
12
|
-
def render
|
|
12
|
+
def render(**args)
|
|
13
|
+
if args[:text]
|
|
14
|
+
res.content_type = "text/plain"
|
|
15
|
+
res.body = "#{args[:text]}\n"
|
|
16
|
+
return
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
if args[:json]
|
|
20
|
+
res.content_type = "application/json"
|
|
21
|
+
res.body = args[:json].to_json
|
|
22
|
+
return
|
|
23
|
+
end
|
|
24
|
+
render_template_file
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
def render_template_file
|
|
13
29
|
views_folder = File.join(Jetski.app_root, 'app/views')
|
|
14
30
|
assets_folder = File.join(Jetski.app_root, 'app/assets/stylesheets')
|
|
15
31
|
layout_content = File.read(File.join(views_folder, "layouts/application.html"))
|
|
@@ -22,6 +38,7 @@ module Jetski
|
|
|
22
38
|
''
|
|
23
39
|
end
|
|
24
40
|
page_with_css = page_with_layout.gsub("DYNAMIC_CSS", css_content)
|
|
41
|
+
res.content_type = "text/html"
|
|
25
42
|
res.body = page_with_css
|
|
26
43
|
end
|
|
27
44
|
end
|
data/lib/jetski/router.rb
CHANGED
|
@@ -16,24 +16,40 @@ module Jetski
|
|
|
16
16
|
File.readlines(routes_file, chomp: true).each do |line|
|
|
17
17
|
route_action, served_url, controller_name, action_name = line.split(" ")
|
|
18
18
|
server.mount_proc served_url do |req, res|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
found_error = false
|
|
23
|
-
begin
|
|
24
|
-
controller_class = Object.const_get(constantized_controller)
|
|
25
|
-
rescue NameError
|
|
26
|
-
found_error = true
|
|
27
|
-
# TODO: Move this into a method that can render a styled error to page.
|
|
28
|
-
res.body = "#{constantized_controller} is not defined. Please create a file app/controllers/#{controller_name}.rb"
|
|
19
|
+
errors = []
|
|
20
|
+
if (route_action.upcase != req.request_method)
|
|
21
|
+
errors << "Wrong request was performed"
|
|
29
22
|
end
|
|
30
|
-
|
|
23
|
+
# TODO: Fix the fact that we are always setting res.body to something here.
|
|
24
|
+
# Theres no way to return. We need to organize into case statement or if/else type
|
|
25
|
+
|
|
26
|
+
if errors.empty?
|
|
27
|
+
controller_name_formatted = controller_name.split("/").map(&:capitalize).join("::")
|
|
28
|
+
constantized_controller = "#{controller_name_formatted}Controller"
|
|
29
|
+
path_to_defined_controller = File.join(Jetski.app_root, "app/controllers/#{controller_name}_controller.rb")
|
|
30
|
+
require_relative path_to_defined_controller
|
|
31
|
+
begin
|
|
32
|
+
controller_class = Object.const_get(constantized_controller)
|
|
33
|
+
rescue NameError
|
|
34
|
+
errors << "#{constantized_controller} is not defined. Please create a file app/controllers/#{controller_name}.rb"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
if errors.empty? # Continue unless error found
|
|
31
39
|
controller = controller_class.new(res)
|
|
32
40
|
controller.action_name = action_name
|
|
33
41
|
controller.controller_name = controller_name
|
|
34
42
|
controller.send(action_name)
|
|
35
|
-
|
|
43
|
+
# Render matching HTML template for GET requests only
|
|
44
|
+
controller.render if route_action.upcase == "GET"
|
|
45
|
+
# TODO: Need to setup redirects for other request types. POST/PUT/DELETE
|
|
36
46
|
end
|
|
47
|
+
|
|
48
|
+
if errors.any?
|
|
49
|
+
res.body = errors.join(", ")
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# TODO: Set response content/type and status when rendering/redirecting or head
|
|
37
53
|
end
|
|
38
54
|
end
|
|
39
55
|
end
|
|
@@ -55,6 +71,8 @@ module Jetski
|
|
|
55
71
|
end
|
|
56
72
|
|
|
57
73
|
def host_images
|
|
74
|
+
# TODO: Expand this to support more types of images.
|
|
75
|
+
|
|
58
76
|
image_files = Dir[
|
|
59
77
|
File.join(Jetski.app_root, 'app/assets/images/*.jpg')
|
|
60
78
|
]
|
data/lib/jetski.rb
CHANGED