jetski 0.3.0 → 0.3.2
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/bin/jetski +9 -0
- data/lib/jetski/base_controller.rb +5 -4
- data/lib/jetski/router/parser.rb +94 -0
- data/lib/jetski/router.rb +7 -86
- data/lib/jetski/version.rb +1 -1
- data/lib/jetski.rb +2 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 746e669c9cd0109b9c5d11bc04b8eeda814b529f211ea5cf8aafd1531aa651e3
|
|
4
|
+
data.tar.gz: d178172efe91cc4f611d0cf1c5225871d70ea8718af834d21648f7eb51de2324
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7c8b29c0de093d02b4a3c72401210e54c97bd09615ef3894d216f7b2ede33878ee3b30ecd329cfbde8427951709ca983f04a8e152b0c2fe4d91370edae65a8d9
|
|
7
|
+
data.tar.gz: fd259f11692b58f01c5cdf82e462ea573ded074fa71924764d7932bbe42494c1e76861ca87030531f9279f1394daf321abfbe882656b92379b617e2f274810a3
|
data/bin/jetski
CHANGED
|
@@ -23,6 +23,15 @@ class JetskiCLI < Thor
|
|
|
23
23
|
say "Jetski v#{Jetski::VERSION}"
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
+
desc "routes", "shows the routes in your app."
|
|
27
|
+
def routes
|
|
28
|
+
compiled_routes = Jetski::Router::Parser.compile_routes
|
|
29
|
+
say "🌊 Jetski Routes 🏄♂️"
|
|
30
|
+
compiled_routes.each do |route_obj|
|
|
31
|
+
say "#{route_obj[:method]} #{route_obj[:url]} #{route_obj[:controller_name]}##{route_obj[:action_name]}"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
26
35
|
def self.source_root
|
|
27
36
|
File.join(File.dirname(__FILE__), '..', 'templates')
|
|
28
37
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# This is the base controller of the library
|
|
2
2
|
module Jetski
|
|
3
3
|
class BaseController
|
|
4
|
-
attr_accessor :action_name, :controller_name
|
|
4
|
+
attr_accessor :action_name, :controller_name, :controller_path
|
|
5
5
|
attr_reader :res
|
|
6
6
|
attr_reader :performed_render
|
|
7
7
|
|
|
@@ -50,11 +50,12 @@ module Jetski
|
|
|
50
50
|
views_folder = File.join(Jetski.app_root, 'app/views')
|
|
51
51
|
assets_folder = File.join(Jetski.app_root, 'app/assets/stylesheets')
|
|
52
52
|
layout_content = File.read(File.join(views_folder, "layouts/application.html"))
|
|
53
|
-
|
|
53
|
+
path_to_controller = controller_path[1..-1]
|
|
54
|
+
page_content = File.read(File.join(views_folder, path_to_controller, "#{action_name}.html"))
|
|
54
55
|
page_with_layout = layout_content.gsub("YIELD_CONTENT", page_content)
|
|
55
|
-
action_css_file = File.join(assets_folder, "#{
|
|
56
|
+
action_css_file = File.join(assets_folder, "#{path_to_controller}.css")
|
|
56
57
|
css_content = if File.exist? action_css_file
|
|
57
|
-
"<link rel='stylesheet' href='/#{
|
|
58
|
+
"<link rel='stylesheet' href='/#{path_to_controller}.css'>"
|
|
58
59
|
else
|
|
59
60
|
''
|
|
60
61
|
end
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
module Jetski
|
|
2
|
+
class Router
|
|
3
|
+
module Parser
|
|
4
|
+
extend self
|
|
5
|
+
def compile_routes
|
|
6
|
+
auto_found_routes = []
|
|
7
|
+
controller_file_paths = Dir.glob([File.join(Jetski.app_root, 'app', 'controllers', '**', '*_controller.rb')])
|
|
8
|
+
controller_file_paths.each do |file_path|
|
|
9
|
+
controller_file_name = file_path.split('app/controllers')[1]
|
|
10
|
+
controller_path = controller_file_name.gsub(/_controller.rb/, '')
|
|
11
|
+
controller_name = controller_path.split("/").last
|
|
12
|
+
controller_classname = controller_path.split("/").reject(&:empty?).map(&:capitalize).join("::") + "Controller"
|
|
13
|
+
controller_file_readlines = File.readlines(file_path)
|
|
14
|
+
controller_file_readlines.each.with_index do |line, idx|
|
|
15
|
+
strp_line = line.strip
|
|
16
|
+
if strp_line.start_with?('def')
|
|
17
|
+
action_name = strp_line.split("def").last.strip
|
|
18
|
+
base_opts = {
|
|
19
|
+
controller_classname: controller_classname,
|
|
20
|
+
controller_file_name: controller_file_name,
|
|
21
|
+
controller_name: controller_name,
|
|
22
|
+
controller_path: controller_path,
|
|
23
|
+
}
|
|
24
|
+
case action_name
|
|
25
|
+
when "new"
|
|
26
|
+
auto_found_routes << base_opts.merge({
|
|
27
|
+
url: controller_path + "/new",
|
|
28
|
+
method: "GET",
|
|
29
|
+
action_name: action_name,
|
|
30
|
+
})
|
|
31
|
+
when "create"
|
|
32
|
+
auto_found_routes << base_opts.merge({
|
|
33
|
+
url: controller_path,
|
|
34
|
+
method: "POST",
|
|
35
|
+
action_name: action_name,
|
|
36
|
+
})
|
|
37
|
+
when "show"
|
|
38
|
+
auto_found_routes << base_opts.merge({
|
|
39
|
+
url: controller_path + "/:id",
|
|
40
|
+
method: "GET",
|
|
41
|
+
action_name: action_name,
|
|
42
|
+
})
|
|
43
|
+
when "edit"
|
|
44
|
+
auto_found_routes << base_opts.merge({
|
|
45
|
+
url: controller_path + "/:id/edit",
|
|
46
|
+
method: "GET",
|
|
47
|
+
action_name: action_name,
|
|
48
|
+
})
|
|
49
|
+
when "update"
|
|
50
|
+
auto_found_routes << base_opts.merge({
|
|
51
|
+
url: controller_path + "/:id",
|
|
52
|
+
method: "PUT",
|
|
53
|
+
action_name: action_name,
|
|
54
|
+
})
|
|
55
|
+
when "destroy"
|
|
56
|
+
auto_found_routes << base_opts.merge({
|
|
57
|
+
url: controller_path + "/:id",
|
|
58
|
+
method: "DELETE",
|
|
59
|
+
action_name: action_name,
|
|
60
|
+
})
|
|
61
|
+
else
|
|
62
|
+
method_route_options = controller_file_readlines[(idx - 2)..(idx - 1)].map(&:strip)
|
|
63
|
+
custom_request_method = method_route_options.find { |line| line.start_with? "request_method" }
|
|
64
|
+
custom_request_method = if custom_request_method
|
|
65
|
+
custom_request_method.split(" ")[1].gsub('"', '').upcase
|
|
66
|
+
else
|
|
67
|
+
"GET"
|
|
68
|
+
end
|
|
69
|
+
custom_path_option = method_route_options.find { |line| line.start_with? "path" }
|
|
70
|
+
check_root = controller_file_readlines[idx - 1].strip
|
|
71
|
+
url_to_use = if check_root.include?("root")
|
|
72
|
+
"/"
|
|
73
|
+
else
|
|
74
|
+
if custom_path_option
|
|
75
|
+
custom_path_option.split(" ")[1].gsub('"', '')
|
|
76
|
+
else
|
|
77
|
+
url_friendly_action_name = action_name.split("_").join("-")
|
|
78
|
+
controller_path + "/#{url_friendly_action_name}"
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
auto_found_routes << base_opts.merge({
|
|
82
|
+
url: url_to_use,
|
|
83
|
+
method: custom_request_method,
|
|
84
|
+
action_name: action_name,
|
|
85
|
+
})
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
auto_found_routes
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
data/lib/jetski/router.rb
CHANGED
|
@@ -1,105 +1,25 @@
|
|
|
1
1
|
module Jetski
|
|
2
2
|
class Router
|
|
3
|
+
include Parser
|
|
3
4
|
attr_reader :server
|
|
4
5
|
def initialize(server)
|
|
5
6
|
@server = server
|
|
6
7
|
end
|
|
7
8
|
|
|
8
9
|
def call
|
|
9
|
-
|
|
10
|
+
host_routes && host_assets
|
|
10
11
|
end
|
|
11
12
|
|
|
12
|
-
def
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
controller_file_paths.each do |file_path|
|
|
16
|
-
controller_file_name = file_path.split('app/controllers')[1]
|
|
17
|
-
controller_as_url = controller_file_name.gsub(/_controller.rb/, '')
|
|
18
|
-
controller_name = controller_as_url.split("/").last
|
|
19
|
-
controller_classname = controller_as_url.split("/").reject(&:empty?).map(&:capitalize).join("::") + "Controller"
|
|
20
|
-
controller_file_readlines = File.readlines(file_path)
|
|
21
|
-
controller_file_readlines.each.with_index do |line, idx|
|
|
22
|
-
strp_line = line.strip
|
|
23
|
-
if strp_line.start_with?('def')
|
|
24
|
-
action_name = strp_line.split("def").last.strip
|
|
25
|
-
base_opts = {
|
|
26
|
-
controller_classname: controller_classname,
|
|
27
|
-
controller_file_name: controller_file_name,
|
|
28
|
-
controller_name: controller_name
|
|
29
|
-
}
|
|
30
|
-
case action_name
|
|
31
|
-
when "new"
|
|
32
|
-
auto_found_routes << base_opts.merge({
|
|
33
|
-
url: controller_as_url + "/new",
|
|
34
|
-
method: "GET",
|
|
35
|
-
action_name: action_name,
|
|
36
|
-
})
|
|
37
|
-
when "create"
|
|
38
|
-
auto_found_routes << base_opts.merge({
|
|
39
|
-
url: controller_as_url,
|
|
40
|
-
method: "POST",
|
|
41
|
-
action_name: action_name,
|
|
42
|
-
})
|
|
43
|
-
when "show"
|
|
44
|
-
auto_found_routes << base_opts.merge({
|
|
45
|
-
url: controller_as_url + "/:id",
|
|
46
|
-
method: "GET",
|
|
47
|
-
action_name: action_name,
|
|
48
|
-
})
|
|
49
|
-
when "edit"
|
|
50
|
-
auto_found_routes << base_opts.merge({
|
|
51
|
-
url: controller_as_url + "/:id/edit",
|
|
52
|
-
method: "GET",
|
|
53
|
-
action_name: action_name,
|
|
54
|
-
})
|
|
55
|
-
when "update"
|
|
56
|
-
auto_found_routes << base_opts.merge({
|
|
57
|
-
url: controller_as_url + "/:id",
|
|
58
|
-
method: "PUT",
|
|
59
|
-
action_name: action_name,
|
|
60
|
-
})
|
|
61
|
-
when "destroy"
|
|
62
|
-
auto_found_routes << base_opts.merge({
|
|
63
|
-
url: controller_as_url + "/:id",
|
|
64
|
-
method: "DELETE",
|
|
65
|
-
action_name: action_name,
|
|
66
|
-
})
|
|
67
|
-
else
|
|
68
|
-
method_route_options = controller_file_readlines[(idx - 2)..(idx - 1)].map(&:strip)
|
|
69
|
-
custom_request_method = method_route_options.find { |line| line.start_with? "request_method" }
|
|
70
|
-
custom_request_method = if custom_request_method
|
|
71
|
-
custom_request_method.split(" ")[1].gsub('"', '').upcase
|
|
72
|
-
else
|
|
73
|
-
"GET"
|
|
74
|
-
end
|
|
75
|
-
custom_path_option = method_route_options.find { |line| line.start_with? "path" }
|
|
76
|
-
check_root = controller_file_readlines[idx - 1].strip
|
|
77
|
-
url_to_use = if check_root.include?("root")
|
|
78
|
-
"/"
|
|
79
|
-
else
|
|
80
|
-
if custom_path_option
|
|
81
|
-
custom_path_option.split(" ")[1].gsub('"', '')
|
|
82
|
-
else
|
|
83
|
-
controller_as_url + "/#{action_name}"
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
auto_found_routes << base_opts.merge({
|
|
87
|
-
url: url_to_use,
|
|
88
|
-
method: custom_request_method,
|
|
89
|
-
action_name: action_name,
|
|
90
|
-
})
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
auto_found_routes.each do |af_route|
|
|
13
|
+
def host_routes
|
|
14
|
+
routes = compile_routes
|
|
15
|
+
routes.each do |af_route|
|
|
97
16
|
served_url = af_route[:url]
|
|
98
17
|
request_method = af_route[:method]
|
|
99
18
|
controller_classname = af_route[:controller_classname]
|
|
100
19
|
controller_name = af_route[:controller_name]
|
|
101
20
|
action_name = af_route[:action_name]
|
|
102
21
|
controller_file_name = af_route[:controller_file_name]
|
|
22
|
+
controller_path = af_route[:controller_path]
|
|
103
23
|
|
|
104
24
|
server.mount_proc served_url do |req, res|
|
|
105
25
|
errors = []
|
|
@@ -120,6 +40,7 @@ module Jetski
|
|
|
120
40
|
controller = controller_class.new(res)
|
|
121
41
|
controller.action_name = action_name
|
|
122
42
|
controller.controller_name = controller_name
|
|
43
|
+
controller.controller_path = controller_path
|
|
123
44
|
controller.send(action_name)
|
|
124
45
|
if !controller.performed_render && (request_method.upcase == "GET")
|
|
125
46
|
controller.render
|
data/lib/jetski/version.rb
CHANGED
data/lib/jetski.rb
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
require_relative './jetski/version'
|
|
2
2
|
require_relative './jetski/base_controller'
|
|
3
3
|
require_relative './jetski/server'
|
|
4
|
+
require_relative './jetski/router/parser'
|
|
4
5
|
require_relative './jetski/router'
|
|
5
6
|
require "webrick"
|
|
6
7
|
require "json"
|
|
8
|
+
require "json"
|
|
7
9
|
|
|
8
10
|
module Jetski
|
|
9
11
|
# Debug stage add constants here for debugging.
|
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.3.
|
|
4
|
+
version: 0.3.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Indigo Tech Tutorials
|
|
@@ -49,6 +49,7 @@ files:
|
|
|
49
49
|
- lib/jetski.rb
|
|
50
50
|
- lib/jetski/base_controller.rb
|
|
51
51
|
- lib/jetski/router.rb
|
|
52
|
+
- lib/jetski/router/parser.rb
|
|
52
53
|
- lib/jetski/server.rb
|
|
53
54
|
- lib/jetski/version.rb
|
|
54
55
|
- templates/base/Gemfile
|