jetski 0.3.8 → 0.4.0
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 +1 -2
- data/bin/jetski_cli_helpers/generate.rb +22 -13
- data/bin/templates/base/app/assets/javascript/application.js +1 -0
- data/bin/templates/base/app/controllers/pages_controller.rb +1 -1
- data/bin/templates/base/app/views/layouts/application.html.erb +0 -2
- data/lib/jetski/base_controller.rb +56 -13
- data/lib/jetski/router/parser.rb +73 -74
- data/lib/jetski/router.rb +15 -1
- data/lib/jetski/version.rb +1 -1
- data/lib/jetski.rb +6 -6
- metadata +2 -3
- data/bin/templates/controllers/example_controller +0 -3
- data/bin/templates/views/example.html.erb +0 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ffe71a8de5f4201c446a70331fae92f982af3887b388426e5b64f1b6c3d897c8
|
|
4
|
+
data.tar.gz: 73a1faada7420962abfdbab298f7f81157431b995452ca5fc2adefd903d074ec
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 35e4cfce787089dfe046575b38969927013e09a91b855dee64af15394872eed1660a087ecdd801fb4c0ede590b491da3759b5d68f1ff2c92a49363426f5a8f38
|
|
7
|
+
data.tar.gz: '049857042cd6299e591dab667ef9f3943637649905fe77e09174eabdc3a1131abb9849e93e35f07adb32d9c09dda067ffc19c8d671ddade29715d74ff0c9acfa'
|
data/bin/jetski
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
|
-
require 'optparse'
|
|
4
3
|
require 'jetski'
|
|
4
|
+
require 'optparse'
|
|
5
5
|
require 'thor'
|
|
6
6
|
require_relative './jetski_cli_helpers/generate.rb'
|
|
7
7
|
require_relative './jetski_cli_helpers/destroy.rb'
|
|
@@ -37,7 +37,6 @@ class JetskiCLI < Thor
|
|
|
37
37
|
|
|
38
38
|
desc "server", "starts the jetski app"
|
|
39
39
|
def server
|
|
40
|
-
ENV['JETSKI_PROJECT_PATH'] = __dir__
|
|
41
40
|
Jetski::Server.new.call
|
|
42
41
|
end
|
|
43
42
|
|
|
@@ -5,27 +5,36 @@ module JetskiCLIHelpers
|
|
|
5
5
|
desc "controller NAME ACTION_NAMES", "Create a controller with matching actions"
|
|
6
6
|
def controller(name, *actions)
|
|
7
7
|
controller_file_path = "app/controllers/#{name}_controller.rb"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if actions.size < (idx + 1)
|
|
13
|
-
action_content += "\nACTION_NAME"
|
|
8
|
+
create_file controller_file_path
|
|
9
|
+
append_to_file controller_file_path, <<~CONTROLLER
|
|
10
|
+
class #{name.capitalize}Controller < Jetski::BaseController
|
|
11
|
+
|
|
14
12
|
end
|
|
15
|
-
|
|
13
|
+
CONTROLLER
|
|
14
|
+
|
|
15
|
+
actions.each.with_index do |action_name, idx|
|
|
16
|
+
action_content = <<~ACTION_CONTENT
|
|
17
|
+
def #{action_name}
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
ACTION_CONTENT
|
|
21
|
+
insert_into_file(controller_file_path, indent_code(action_content, 1), before: "\nend")
|
|
16
22
|
path_to_view = "app/views/#{name}/#{action_name}.html.erb"
|
|
17
23
|
|
|
18
24
|
empty_directory("app/views/#{name}")
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
create_file(path_to_view)
|
|
26
|
+
append_to_file path_to_view, <<~EXAMPLEFILE
|
|
27
|
+
<h1> #{name}##{action_name} </h1>
|
|
28
|
+
<p> edit the content of this page at app/views/#{path_to_view}/#{action_name}.html.erb </p>
|
|
29
|
+
EXAMPLEFILE
|
|
30
|
+
|
|
23
31
|
say "🌊 View your new page at http://localhost:8000/#{name}/#{action_name}"
|
|
24
32
|
end
|
|
25
33
|
end
|
|
26
34
|
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
private
|
|
36
|
+
def indent_code(code, level = 1)
|
|
37
|
+
code.strip.split("\n").map { |l| (1..level).map { |lvl| " " }.join + l }.join("\n")
|
|
29
38
|
end
|
|
30
39
|
end
|
|
31
40
|
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
console.log("🌊 Hello Jetski JS!")
|
|
@@ -4,9 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title> APP_NAME </title>
|
|
7
|
-
<link rel="stylesheet" href="/application.css">
|
|
8
7
|
<link rel="icon" type="image/x-icon" href="/jetski-logo.png">
|
|
9
|
-
DYNAMIC_CSS
|
|
10
8
|
</head>
|
|
11
9
|
<body>
|
|
12
10
|
<%= yield %>
|
|
@@ -4,6 +4,7 @@ module Jetski
|
|
|
4
4
|
attr_accessor :action_name, :controller_name, :controller_path, :params
|
|
5
5
|
attr_reader :res
|
|
6
6
|
attr_reader :performed_render
|
|
7
|
+
attr_writer :root, :path, :request_method
|
|
7
8
|
|
|
8
9
|
class << self
|
|
9
10
|
def request_method(method)
|
|
@@ -50,25 +51,67 @@ module Jetski
|
|
|
50
51
|
res.set_redirect(WEBrick::HTTPStatus::Found, url)
|
|
51
52
|
end
|
|
52
53
|
|
|
54
|
+
def is_root?
|
|
55
|
+
@root == true
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def custom_path
|
|
59
|
+
@path
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def custom_request_method
|
|
63
|
+
@request_method
|
|
64
|
+
end
|
|
65
|
+
|
|
53
66
|
private
|
|
54
67
|
def render_template_file
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
68
|
+
view_render = page_with_layout.gsub("\n</head>", "#{content_for_head}\n</head>")
|
|
69
|
+
res.content_type = "text/html"
|
|
70
|
+
res.body = view_render
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def page_with_layout
|
|
74
|
+
process_erb(File.read(File.join(views_folder, "layouts/application.html.erb"))) do
|
|
60
75
|
process_erb(File.read(File.join(views_folder, path_to_controller, "#{action_name}.html.erb")))
|
|
61
76
|
end
|
|
77
|
+
end
|
|
62
78
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
79
|
+
def content_for_head
|
|
80
|
+
_content_for_head = ''
|
|
81
|
+
|
|
82
|
+
application_css_file = File.join(assets_folder, "stylesheets", "application.css")
|
|
83
|
+
if File.exist? application_css_file
|
|
84
|
+
_content_for_head += "<link rel='stylesheet' href='/application.css'>\n"
|
|
68
85
|
end
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
86
|
+
|
|
87
|
+
controller_css_file = File.join(assets_folder, "stylesheets", "#{path_to_controller}.css")
|
|
88
|
+
if File.exist? controller_css_file
|
|
89
|
+
_content_for_head += "<link rel='stylesheet' href='/#{path_to_controller}.css'>\n"
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
application_js_file = File.join(assets_folder, "javascript", "application.js")
|
|
93
|
+
if File.exist? application_js_file
|
|
94
|
+
_content_for_head += "<script src='application.js' defer></script>\n"
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
controller_js_file = File.join(assets_folder, "javascript", "#{path_to_controller}.js")
|
|
98
|
+
if File.exist? controller_js_file
|
|
99
|
+
_content_for_head += "<script src='/#{path_to_controller}.js' defer></script>\n"
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
_content_for_head
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def views_folder
|
|
106
|
+
File.join(Jetski.app_root, 'app/views')
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def assets_folder
|
|
110
|
+
File.join(Jetski.app_root, 'app/assets')
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def path_to_controller
|
|
114
|
+
controller_path[1..-1]
|
|
72
115
|
end
|
|
73
116
|
|
|
74
117
|
def process_erb(content)
|
data/lib/jetski/router/parser.rb
CHANGED
|
@@ -5,85 +5,84 @@ module Jetski
|
|
|
5
5
|
def compile_routes
|
|
6
6
|
auto_found_routes = []
|
|
7
7
|
controller_file_paths = Dir.glob([File.join(Jetski.app_root, 'app', 'controllers', '**', '*_controller.rb')])
|
|
8
|
-
controller_file_paths.each do |file_path|
|
|
8
|
+
controller_file_paths.each do |file_path|
|
|
9
|
+
require_relative file_path
|
|
9
10
|
controller_file_name = file_path.split('app/controllers')[1]
|
|
10
11
|
controller_path = controller_file_name.gsub(/_controller.rb/, '')
|
|
11
12
|
controller_name = controller_path.split("/").last
|
|
12
|
-
controller_classname = controller_path
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
13
|
+
controller_classname = controller_path
|
|
14
|
+
.split("/")
|
|
15
|
+
.reject(&:empty?)
|
|
16
|
+
.map(&:capitalize)
|
|
17
|
+
.map { |c| c.split("_").map(&:capitalize).join }
|
|
18
|
+
.join("::") + "Controller"
|
|
19
|
+
controller_class = Module.const_get(controller_classname)
|
|
20
|
+
action_names = controller_class.instance_methods(false)
|
|
21
|
+
base_opts = {
|
|
22
|
+
controller_classname: controller_classname,
|
|
23
|
+
controller_file_name: controller_file_name,
|
|
24
|
+
controller_name: controller_name,
|
|
25
|
+
controller_path: controller_path,
|
|
26
|
+
}
|
|
27
|
+
action_names.each do |action_name|
|
|
28
|
+
action_name = action_name.to_s
|
|
29
|
+
case action_name
|
|
30
|
+
when "new"
|
|
31
|
+
auto_found_routes << base_opts.merge({
|
|
32
|
+
url: controller_path + "/new",
|
|
33
|
+
method: "GET",
|
|
34
|
+
action_name: action_name,
|
|
35
|
+
})
|
|
36
|
+
when "create"
|
|
37
|
+
auto_found_routes << base_opts.merge({
|
|
38
|
+
url: controller_path,
|
|
39
|
+
method: "POST",
|
|
40
|
+
action_name: action_name,
|
|
41
|
+
})
|
|
42
|
+
when "show"
|
|
43
|
+
auto_found_routes << base_opts.merge({
|
|
44
|
+
url: controller_path + "/:id",
|
|
45
|
+
method: "GET",
|
|
46
|
+
action_name: action_name,
|
|
47
|
+
})
|
|
48
|
+
when "edit"
|
|
49
|
+
auto_found_routes << base_opts.merge({
|
|
50
|
+
url: controller_path + "/:id/edit",
|
|
51
|
+
method: "GET",
|
|
52
|
+
action_name: action_name,
|
|
53
|
+
})
|
|
54
|
+
when "update"
|
|
55
|
+
auto_found_routes << base_opts.merge({
|
|
56
|
+
url: controller_path + "/:id",
|
|
57
|
+
method: "PUT",
|
|
58
|
+
action_name: action_name,
|
|
59
|
+
})
|
|
60
|
+
when "destroy"
|
|
61
|
+
auto_found_routes << base_opts.merge({
|
|
62
|
+
url: controller_path + "/:id",
|
|
63
|
+
method: "DELETE",
|
|
64
|
+
action_name: action_name,
|
|
65
|
+
})
|
|
66
|
+
else
|
|
67
|
+
tmp_controller_instance = controller_class.new("")
|
|
68
|
+
tmp_controller_instance.send(action_name)
|
|
69
|
+
is_root = tmp_controller_instance.is_root?
|
|
70
|
+
custom_path = tmp_controller_instance.custom_path
|
|
71
|
+
url_to_use = if is_root
|
|
72
|
+
"/"
|
|
73
|
+
elsif custom_path
|
|
74
|
+
custom_path
|
|
61
75
|
else
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
})
|
|
76
|
+
url_friendly_action_name = action_name.split("_").join("-")
|
|
77
|
+
controller_path + "/#{url_friendly_action_name}"
|
|
86
78
|
end
|
|
79
|
+
custom_request_method = tmp_controller_instance.custom_request_method
|
|
80
|
+
|
|
81
|
+
auto_found_routes << base_opts.merge({
|
|
82
|
+
url: url_to_use,
|
|
83
|
+
method: custom_request_method || "GET",
|
|
84
|
+
action_name: action_name,
|
|
85
|
+
})
|
|
87
86
|
end
|
|
88
87
|
end
|
|
89
88
|
end
|
data/lib/jetski/router.rb
CHANGED
|
@@ -57,7 +57,7 @@ module Jetski
|
|
|
57
57
|
|
|
58
58
|
def host_assets
|
|
59
59
|
# Render stylesheets css via url
|
|
60
|
-
host_css && host_images
|
|
60
|
+
host_css && host_images && host_javascript
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
def host_css
|
|
@@ -66,6 +66,7 @@ module Jetski
|
|
|
66
66
|
filename = file_path.split("app/assets/stylesheets/").last
|
|
67
67
|
asset_url = "/#{filename}"
|
|
68
68
|
server.mount_proc asset_url do |req, res|
|
|
69
|
+
res.content_type = "text/css"
|
|
69
70
|
res.body = File.read(File.join(Jetski.app_root,"app/assets/stylesheets/#{filename}"))
|
|
70
71
|
end
|
|
71
72
|
end
|
|
@@ -81,9 +82,22 @@ module Jetski
|
|
|
81
82
|
filename = file_path.split("/").last
|
|
82
83
|
asset_url = "/#{filename}"
|
|
83
84
|
server.mount_proc asset_url do |req, res|
|
|
85
|
+
res.content_type = "image/*"
|
|
84
86
|
res.body = File.read(File.join(Jetski.app_root,"app/assets/images/#{filename}"))
|
|
85
87
|
end
|
|
86
88
|
end
|
|
87
89
|
end
|
|
90
|
+
|
|
91
|
+
def host_javascript
|
|
92
|
+
js_files = Dir[File.join(Jetski.app_root,'app/assets/javascript/**/*.js')]
|
|
93
|
+
js_files.each do |file_path|
|
|
94
|
+
filename = file_path.split("app/assets/javascript/").last
|
|
95
|
+
asset_url = "/#{filename}"
|
|
96
|
+
server.mount_proc asset_url do |req, res|
|
|
97
|
+
res.content_type = "text/javascript"
|
|
98
|
+
res.body = File.read(File.join(Jetski.app_root,"app/assets/javascript/#{filename}"))
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
88
102
|
end
|
|
89
103
|
end
|
data/lib/jetski/version.rb
CHANGED
data/lib/jetski.rb
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
require_relative './jetski/version'
|
|
2
|
-
require_relative './jetski/base_controller'
|
|
3
|
-
require_relative './jetski/server'
|
|
4
|
-
require_relative './jetski/router/parser'
|
|
5
|
-
require_relative './jetski/router'
|
|
6
1
|
require "webrick"
|
|
7
2
|
require "json"
|
|
8
3
|
require "json"
|
|
9
4
|
require "ostruct"
|
|
10
5
|
require "erb"
|
|
11
6
|
|
|
7
|
+
require_relative './jetski/version'
|
|
8
|
+
require_relative './jetski/base_controller'
|
|
9
|
+
require_relative './jetski/server'
|
|
10
|
+
require_relative './jetski/router/parser'
|
|
11
|
+
require_relative './jetski/router'
|
|
12
|
+
|
|
12
13
|
module Jetski
|
|
13
|
-
# Debug stage add constants here for debugging.
|
|
14
14
|
extend self
|
|
15
15
|
def app_root
|
|
16
16
|
Dir.pwd
|
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.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Indigo Tech Tutorials
|
|
@@ -78,13 +78,12 @@ files:
|
|
|
78
78
|
- bin/jetski_cli_helpers/generate.rb
|
|
79
79
|
- bin/templates/base/Gemfile
|
|
80
80
|
- bin/templates/base/app/assets/images/jetski-logo.png
|
|
81
|
+
- bin/templates/base/app/assets/javascript/application.js
|
|
81
82
|
- bin/templates/base/app/assets/stylesheets/application.css
|
|
82
83
|
- bin/templates/base/app/assets/stylesheets/pages.css
|
|
83
84
|
- bin/templates/base/app/controllers/pages_controller.rb
|
|
84
85
|
- bin/templates/base/app/views/layouts/application.html.erb
|
|
85
86
|
- bin/templates/base/app/views/pages/home.html.erb
|
|
86
|
-
- bin/templates/controllers/example_controller
|
|
87
|
-
- bin/templates/views/example.html.erb
|
|
88
87
|
- lib/jetski.rb
|
|
89
88
|
- lib/jetski/base_controller.rb
|
|
90
89
|
- lib/jetski/router.rb
|