jetski 0.2.4 → 0.2.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 52524e0b705d5bb94407dda01e0af30c309213798ff46047ac5f2aa4224ebe44
4
- data.tar.gz: 8ddf98dc0ec78eda05b6bdf17dbdd42f68fbd1045e5fb3dcb0a4c7c901f1eaac
3
+ metadata.gz: 831978e080c29ad5bfdf13d68c4eb578c008eb84e99316f3dd8209988399b582
4
+ data.tar.gz: 698027e9c51838c642f02871f77a09edcdabcb997e2e0688bc9a7abc9a8197aa
5
5
  SHA512:
6
- metadata.gz: c4c1f737cc101e4b5aee3ffd4b9560fe9e1a80f4e5ac351cf167e6bae37ffe76283689df8086bfa88f929aeed8a671849546c41f174c4fc3f963e7dca28a4b29
7
- data.tar.gz: 32665c9eef582c11d7d3c7958976b71009234780fdc37ee97502caf4d6d2e4f426103b1e24ff14212367621252e34bf655b2c7abe90146bc65954ba7f95bb1a4
6
+ metadata.gz: 83f11f888980010118f35a9717d666a3e85739ff425b0a3b76620d093a2a28a773b73edd04136de07462d678304362af5120365f751aa220b66e2d941a7ada89
7
+ data.tar.gz: 963765aee88f67fd4516853332cee01ef3e78558e99db439a31261078eb43f31b3ac8e5f61b6e65bfa50c393c296781fa6b2effdb035a9a6e019814af4755f78
@@ -17,7 +17,7 @@ module Jetski
17
17
  page_with_layout = layout_content.gsub("YIELD_CONTENT", page_content)
18
18
  action_css_file = File.join(assets_folder, "#{controller_name}.css")
19
19
  css_content = if File.exist? action_css_file
20
- "<link rel='stylesheet' href='/assets/#{controller_name}.css'>"
20
+ "<link rel='stylesheet' href='/#{controller_name}.css'>"
21
21
  else
22
22
  ''
23
23
  end
data/lib/jetski/router.rb CHANGED
@@ -16,38 +16,69 @@ 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
- constantized_controller = "#{controller_name.capitalize}Controller"
20
- path_to_defined_controller = File.join(Jetski.app_root, "app/controllers/#{controller_name}_controller.rb")
21
- require_relative path_to_defined_controller
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
- if found_error == false # Continue unless error found
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
+ constantized_controller = "#{controller_name.capitalize}Controller"
28
+ path_to_defined_controller = File.join(Jetski.app_root, "app/controllers/#{controller_name}_controller.rb")
29
+ require_relative path_to_defined_controller
30
+ begin
31
+ controller_class = Object.const_get(constantized_controller)
32
+ rescue NameError
33
+ errors << "#{constantized_controller} is not defined. Please create a file app/controllers/#{controller_name}.rb"
34
+ end
35
+ end
36
+
37
+ if errors.empty? # Continue unless error found
31
38
  controller = controller_class.new(res)
32
39
  controller.action_name = action_name
33
40
  controller.controller_name = controller_name
34
41
  controller.send(action_name)
35
- controller.render
42
+ # Render matching HTML template for GET requests only
43
+ controller.render if route_action.upcase == "GET"
44
+ end
45
+
46
+ if errors.any?
47
+ res.body = errors.join(", ")
36
48
  end
37
49
  end
38
50
  end
39
51
  end
40
52
 
41
53
  def host_assets
42
- # Render css via url
54
+ # Render stylesheets css via url
55
+ host_css && host_images
56
+ end
57
+
58
+ def host_css
43
59
  css_files = Dir[File.join(Jetski.app_root,'app/assets/stylesheets/*.css')]
44
60
  css_files.each do |file_path|
45
61
  filename = file_path.split("/").last
46
- asset_url = "/assets/#{filename}"
62
+ asset_url = "/#{filename}"
47
63
  server.mount_proc asset_url do |req, res|
48
64
  res.body = File.read(File.join(Jetski.app_root,"app/assets/stylesheets/#{filename}"))
49
65
  end
50
66
  end
51
67
  end
68
+
69
+ def host_images
70
+ # TODO: Expand this to support more types of images.
71
+
72
+ image_files = Dir[
73
+ File.join(Jetski.app_root, 'app/assets/images/*.jpg')
74
+ ]
75
+ image_files.each do |file_path|
76
+ filename = file_path.split("/").last
77
+ asset_url = "/#{filename}"
78
+ server.mount_proc asset_url do |req, res|
79
+ res.body = File.read(File.join(Jetski.app_root,"app/assets/images/#{filename}"))
80
+ end
81
+ end
82
+ end
52
83
  end
53
84
  end
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
6
  <title> Jetski app </title>
7
- <link rel="stylesheet" href="/assets/application.css">
7
+ <link rel="stylesheet" href="/application.css">
8
8
  DYNAMIC_CSS
9
9
  </head>
10
10
  <body>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jetski
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Indigo Tech Tutorials