yescode 1.1.1 → 22.05.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +132 -0
- data/README.md +1 -1
- data/lib/yes_app.rb +2 -1
- data/lib/yes_controller.rb +19 -10
- data/lib/yes_routes.rb +38 -0
- data/lib/yescode/router.rb +8 -16
- data/lib/yescode/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a496bc38d094a8023eb8a35144bbb28b34a83757aa72bbd0c43e74ce14ec687d
|
4
|
+
data.tar.gz: 84eeeb4d8a2f6e31a7b78af40eaad27709adb278917000f5a372e3acc89a3430
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bf4aced8cef7c324db274362313d0293d958673a4e48f9afdf4a784d9cbd9d10443874223f7faef35e521d6956091711c44e3e4cde9080d6e640041675f2803
|
7
|
+
data.tar.gz: ff2c73bbb7d0e4066aa717c077019ec39afc553d6e8fcad678709574f5befcd2edc51ba3fb54f2ee96d94843eba0470184d23ebabfa3133b09d0dd52c49c6d58
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,138 @@ All notable changes to this project will be documented in this file
|
|
4
4
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
6
6
|
|
7
|
+
# Unreleased
|
8
|
+
|
9
|
+
# [22.05.24]
|
10
|
+
|
11
|
+
Switched to calendar versioning, the new format is YY.MM.DD
|
12
|
+
|
13
|
+
### Fixes
|
14
|
+
|
15
|
+
No fixes :tada:
|
16
|
+
|
17
|
+
### Features
|
18
|
+
|
19
|
+
- Add a json response helper
|
20
|
+
- Add render method to controller which can disable layout at runtime
|
21
|
+
- Add action routing
|
22
|
+
- Add actions routing
|
23
|
+
- Add resources routing
|
24
|
+
|
25
|
+
The new `action` method:
|
26
|
+
|
27
|
+
```rb
|
28
|
+
class Routes < YesRoutes
|
29
|
+
action "/signup", :Signups
|
30
|
+
end
|
31
|
+
|
32
|
+
# elsewhere in the signups controller
|
33
|
+
class Signups < YesController
|
34
|
+
# GET /signup
|
35
|
+
def new
|
36
|
+
end
|
37
|
+
|
38
|
+
# POST /signup
|
39
|
+
def create
|
40
|
+
end
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
`actions` is very similar to `action`
|
45
|
+
|
46
|
+
```rb
|
47
|
+
class Routes < YesRoutes
|
48
|
+
actions "/profile", :Profile
|
49
|
+
end
|
50
|
+
|
51
|
+
# elsewhere in the signups controller
|
52
|
+
class Profile < YesController
|
53
|
+
# GET /profile
|
54
|
+
def show
|
55
|
+
end
|
56
|
+
|
57
|
+
# GET /profile/new
|
58
|
+
def new
|
59
|
+
end
|
60
|
+
|
61
|
+
# POST /profile/new
|
62
|
+
def create
|
63
|
+
end
|
64
|
+
|
65
|
+
# GET /profile/edit
|
66
|
+
def edit
|
67
|
+
end
|
68
|
+
|
69
|
+
# POST /profile/edit
|
70
|
+
def update
|
71
|
+
end
|
72
|
+
|
73
|
+
# POST /profile/delete
|
74
|
+
def delete
|
75
|
+
end
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
Finally, resources is a more flexible version of `resource`
|
80
|
+
|
81
|
+
```rb
|
82
|
+
class Routes < YesRoutes
|
83
|
+
resources "/todos/:todo_id", :Todos
|
84
|
+
end
|
85
|
+
|
86
|
+
# elsewhere
|
87
|
+
|
88
|
+
class Todos < YesController
|
89
|
+
# GET /todos
|
90
|
+
def index
|
91
|
+
end
|
92
|
+
|
93
|
+
# GET /todos/:todo_id
|
94
|
+
def show
|
95
|
+
end
|
96
|
+
|
97
|
+
# GET /todos/new
|
98
|
+
def new
|
99
|
+
end
|
100
|
+
|
101
|
+
# POST /todos/new
|
102
|
+
def create
|
103
|
+
end
|
104
|
+
|
105
|
+
# GET /todos/:todo_id/edit
|
106
|
+
def edit
|
107
|
+
end
|
108
|
+
|
109
|
+
# POST /todos/:todo_id/edit
|
110
|
+
def update
|
111
|
+
end
|
112
|
+
|
113
|
+
# POST /todos/:todo_id/delete
|
114
|
+
def delete
|
115
|
+
end
|
116
|
+
end
|
117
|
+
```
|
118
|
+
|
119
|
+
# [1.1.1]
|
120
|
+
|
121
|
+
### Fixes
|
122
|
+
|
123
|
+
- Migrations and rollbacks from the yescode cli are now working as intended
|
124
|
+
|
125
|
+
# [1.1.0]
|
126
|
+
|
127
|
+
### Fixes
|
128
|
+
|
129
|
+
- Make resource routing actually work
|
130
|
+
- Added some tests around snake/pascal/camel case
|
131
|
+
- Fixed a few rough edges around migrations/rollbacks
|
132
|
+
|
133
|
+
### Features
|
134
|
+
|
135
|
+
- Removed refinements
|
136
|
+
- Prep for RBS type checking with steep
|
137
|
+
- Help messages in the yescode cli command
|
138
|
+
|
7
139
|
# [1.0.0]
|
8
140
|
|
9
141
|
- MVC
|
data/README.md
CHANGED
data/lib/yes_app.rb
CHANGED
data/lib/yes_controller.rb
CHANGED
@@ -1,13 +1,6 @@
|
|
1
1
|
class YesController
|
2
2
|
class << self
|
3
|
-
attr_accessor :before_actions
|
4
|
-
attr_writer :layout
|
5
|
-
|
6
|
-
def layout
|
7
|
-
@layout || Object.const_get(:Layout).new
|
8
|
-
rescue NameError => _e
|
9
|
-
nil
|
10
|
-
end
|
3
|
+
attr_accessor :before_actions, :assets
|
11
4
|
|
12
5
|
def before_action(*symbols)
|
13
6
|
@before_actions = symbols
|
@@ -43,6 +36,10 @@ class YesController
|
|
43
36
|
ok body, { "content-type" => "text/xml; charset=utf-8" }
|
44
37
|
end
|
45
38
|
|
39
|
+
def json(body = nil)
|
40
|
+
ok body, { "content-type" => "application/json; charset=utf-8" }
|
41
|
+
end
|
42
|
+
|
46
43
|
def redirect(controller_or_url, method_name = nil, params = {})
|
47
44
|
if method_name
|
48
45
|
response 302, nil, { "Location" => path(controller_or_url, method_name, params) }
|
@@ -64,7 +61,7 @@ class YesController
|
|
64
61
|
end
|
65
62
|
|
66
63
|
def not_found
|
67
|
-
[404, {"content-type" => "text/plain"}, ["not found"]]
|
64
|
+
[404, { "content-type" => "text/plain" }, ["not found"]]
|
68
65
|
end
|
69
66
|
|
70
67
|
def not_found!
|
@@ -72,7 +69,7 @@ class YesController
|
|
72
69
|
end
|
73
70
|
|
74
71
|
def server_error
|
75
|
-
[500, {"content-type" => "text/plain"}, ["internal server error"]]
|
72
|
+
[500, { "content-type" => "text/plain" }, ["internal server error"]]
|
76
73
|
end
|
77
74
|
|
78
75
|
def server_error!
|
@@ -82,4 +79,16 @@ class YesController
|
|
82
79
|
def path(*args)
|
83
80
|
Object.const_get(:App).path(*args)
|
84
81
|
end
|
82
|
+
|
83
|
+
def render(view, layout: true)
|
84
|
+
view.csrf_name = csrf_name
|
85
|
+
view.csrf_value = csrf_value
|
86
|
+
view.assets = self.class.assets&.to_h || {}
|
87
|
+
view.session = session
|
88
|
+
view.ajax = @env.key?("HTTP_YES_AJAX")
|
89
|
+
content = view.render(view.template)
|
90
|
+
content = view.render(view.class.superclass.new.template, content:) if layout
|
91
|
+
|
92
|
+
ok content
|
93
|
+
end
|
85
94
|
end
|
data/lib/yes_routes.rb
CHANGED
@@ -35,6 +35,20 @@ class YesRoutes
|
|
35
35
|
match("POST", path_string, class_name, method_name)
|
36
36
|
end
|
37
37
|
|
38
|
+
def action(path_string, class_name)
|
39
|
+
match("GET", path_string, class_name, :new)
|
40
|
+
match("POST", path_string, class_name, :create)
|
41
|
+
end
|
42
|
+
|
43
|
+
def actions(path_string, class_name)
|
44
|
+
match("GET", path_string, class_name, :show)
|
45
|
+
match("GET", "#{path_string}/new", class_name, :new)
|
46
|
+
match("POST", "#{path_string}/new", class_name, :create)
|
47
|
+
match("GET", "#{path_string}/edit", class_name, :edit)
|
48
|
+
match("POST", "#{path_string}/edit", class_name, :update)
|
49
|
+
match("POST", "#{path_string}/delete", class_name, :delete)
|
50
|
+
end
|
51
|
+
|
38
52
|
def resource(path_string, class_name)
|
39
53
|
[
|
40
54
|
["GET", :index, ""],
|
@@ -49,6 +63,30 @@ class YesRoutes
|
|
49
63
|
end
|
50
64
|
end
|
51
65
|
|
66
|
+
def resources(path_string, class_name)
|
67
|
+
raise StandardError, "Needs at least two url segments" if path_string.split("/").size < 2
|
68
|
+
raise StandardError, "The last url segment needs to be a param" unless path_string.split("/").last.include?(":")
|
69
|
+
|
70
|
+
*prefix, _ = path_string.split("/")
|
71
|
+
prefix = prefix.join("/")
|
72
|
+
|
73
|
+
[
|
74
|
+
["GET", :index, "", :plural],
|
75
|
+
["GET", :new, "/new", :plural],
|
76
|
+
["POST", :create, "/new", :plural],
|
77
|
+
["GET", :show, ""],
|
78
|
+
["GET", :edit, "/edit"],
|
79
|
+
["POST", :update, "/edit"],
|
80
|
+
["POST", :delete, "/delete"]
|
81
|
+
].each do |method, method_name, suffix, plural|
|
82
|
+
if plural
|
83
|
+
match(method, full_path(prefix, suffix), class_name, method_name)
|
84
|
+
else
|
85
|
+
match(method, full_path(path_string, suffix), class_name, method_name)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
52
90
|
private
|
53
91
|
|
54
92
|
def sub_params_in_path(path, params = {})
|
data/lib/yescode/router.rb
CHANGED
@@ -9,11 +9,10 @@ module Yescode
|
|
9
9
|
|
10
10
|
class Router
|
11
11
|
class << self
|
12
|
-
attr_accessor :logger
|
12
|
+
attr_accessor :logger, :assets
|
13
13
|
end
|
14
14
|
|
15
|
-
def initialize(
|
16
|
-
@app = app
|
15
|
+
def initialize(routes)
|
17
16
|
@routes = routes
|
18
17
|
@logger = self.class.logger
|
19
18
|
end
|
@@ -39,27 +38,20 @@ module Yescode
|
|
39
38
|
rescue NameError => e
|
40
39
|
raise RouteClassDoesNotExist, e.message
|
41
40
|
end
|
42
|
-
|
43
|
-
raise RouteMethodDoesNotExist, "#{class_name}##{method} does not exist" unless
|
41
|
+
controller = klass.new(env)
|
42
|
+
raise RouteMethodDoesNotExist, "#{class_name}##{method} does not exist" unless controller.respond_to?(method)
|
44
43
|
|
45
44
|
@logger&.info(msg: "Request dispatched", route: "#{class_name}##{method}", params: params.except(:_csrf))
|
45
|
+
klass.assets = self.class.assets
|
46
46
|
klass.before_actions&.each do |before_action|
|
47
|
-
|
47
|
+
controller.send(before_action)
|
48
48
|
end
|
49
|
-
response =
|
49
|
+
response = controller.public_send(method)
|
50
50
|
raise NotFoundError if response.nil?
|
51
51
|
|
52
52
|
case response
|
53
53
|
when YesView
|
54
|
-
|
55
|
-
response.csrf_value = obj.csrf_value
|
56
|
-
response.assets = @app.assets.to_h
|
57
|
-
response.session = obj.session
|
58
|
-
response.ajax = env.key?("HTTP_YES_AJAX")
|
59
|
-
layout = klass.layout
|
60
|
-
content = response.render(response.template)
|
61
|
-
content = response.render(layout.template, content:) if layout && response.class < layout.class
|
62
|
-
obj.ok content
|
54
|
+
controller.render response
|
63
55
|
else
|
64
56
|
response
|
65
57
|
end
|
data/lib/yescode/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yescode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 22.05.24
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Walker
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-05-
|
11
|
+
date: 2022-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|