yaframework 0.4.5 → 0.4.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +16 -0
- data/Gemfile.lock +7 -7
- data/examples/{halts-and-redirects/Gemfile → Gemfile} +0 -0
- data/examples/README.md +38 -3
- data/examples/before_after_hooks.rb +20 -0
- data/examples/content_types.rb +24 -0
- data/examples/cookies.rb +16 -0
- data/examples/error_handling.rb +18 -0
- data/examples/{halts-and-redirects/app.rb → halts_and_redirects.rb} +1 -1
- data/examples/headers.rb +11 -0
- data/examples/{hello-world/app.rb → hello_world.rb} +1 -0
- data/examples/{params/app.rb → params.rb} +3 -1
- data/lib/yaframework/base.rb +48 -7
- data/lib/yaframework/response.rb +1 -0
- data/lib/yaframework/version.rb +1 -1
- metadata +10 -13
- data/examples/halts-and-redirects/README.md +0 -12
- data/examples/halts-and-redirects/config.ru +0 -6
- data/examples/hello-world/Gemfile +0 -5
- data/examples/hello-world/README.md +0 -12
- data/examples/hello-world/config.ru +0 -6
- data/examples/params/Gemfile +0 -5
- data/examples/params/README.md +0 -12
- data/examples/params/config.ru +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6cfe57c449982f1b19f548975c965a520181ae0f83937efbfd60cb51c3d20446
|
4
|
+
data.tar.gz: 237e0074011df90023813924fcf40217f0f168cd0237868e56f6903ca367df9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6459c931aaed3114f701f6d096dff733a007e94230d6d71320c64847ecba74d99656189a960ab299c58257542968e8e131c6f1dd54f6d96f2f1f1c1a6ea42cdd
|
7
|
+
data.tar.gz: 561ab785fcf23d3101249f79751b129678a3e00b0e6dd087a98ac8fb4773709e45b80363bd723b563d7f98b1066b035ab09c0911793c430ce99fc045e0771e1b
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
## [0.4.9] - 2021-07-25
|
2
|
+
|
3
|
+
- Some useful aliases added
|
4
|
+
|
5
|
+
## [0.4.8] - 2021-07-25
|
6
|
+
|
7
|
+
- Before/after hooks added
|
8
|
+
|
9
|
+
## [0.4.7] - 2021-07-25
|
10
|
+
|
11
|
+
- Handling 404 error fixed
|
12
|
+
|
13
|
+
## [0.4.6] - 2021-07-25
|
14
|
+
|
15
|
+
- Content duplication fixed
|
16
|
+
|
1
17
|
## [0.4.5] - 2021-07-25
|
2
18
|
|
3
19
|
- Error handling added
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
yaframework (0.4.
|
4
|
+
yaframework (0.4.9)
|
5
5
|
rack (~> 2.2, >= 2.2.3)
|
6
6
|
|
7
7
|
GEM
|
@@ -10,29 +10,29 @@ GEM
|
|
10
10
|
ast (2.4.2)
|
11
11
|
minitest (5.14.4)
|
12
12
|
parallel (1.20.1)
|
13
|
-
parser (3.0.
|
13
|
+
parser (3.0.1.1)
|
14
14
|
ast (~> 2.4.1)
|
15
15
|
rack (2.2.3)
|
16
16
|
rainbow (3.0.0)
|
17
|
-
rake (13.0.
|
17
|
+
rake (13.0.3)
|
18
18
|
regexp_parser (2.1.1)
|
19
19
|
rexml (3.2.5)
|
20
|
-
rubocop (1.18.
|
20
|
+
rubocop (1.18.2)
|
21
21
|
parallel (~> 1.10)
|
22
22
|
parser (>= 3.0.0.0)
|
23
23
|
rainbow (>= 2.2.2, < 4.0)
|
24
24
|
regexp_parser (>= 1.8, < 3.0)
|
25
25
|
rexml
|
26
|
-
rubocop-ast (>= 1.
|
26
|
+
rubocop-ast (>= 1.7.0, < 2.0)
|
27
27
|
ruby-progressbar (~> 1.7)
|
28
28
|
unicode-display_width (>= 1.4.0, < 3.0)
|
29
|
-
rubocop-ast (1.
|
29
|
+
rubocop-ast (1.7.0)
|
30
30
|
parser (>= 3.0.1.1)
|
31
31
|
ruby-progressbar (1.11.0)
|
32
32
|
unicode-display_width (2.0.0)
|
33
33
|
|
34
34
|
PLATFORMS
|
35
|
-
|
35
|
+
x86_64-linux
|
36
36
|
|
37
37
|
DEPENDENCIES
|
38
38
|
bundler (>= 2.2.10)
|
File without changes
|
data/examples/README.md
CHANGED
@@ -2,16 +2,51 @@
|
|
2
2
|
|
3
3
|
Here are some examples of applications created with Yaframework:
|
4
4
|
|
5
|
-
1.
|
5
|
+
1. [**Hello World**](https://github.com/maxbarsukov/yaframework/blob/master/examples/hello_world.rb)
|
6
6
|
|
7
7
|
A simple application that displays "Hello world" to you.
|
8
8
|
|
9
9
|
|
10
|
-
2.
|
10
|
+
2. [**Params**](https://github.com/maxbarsukov/yaframework/blob/master/examples/params.rb)
|
11
11
|
|
12
12
|
Shows how the application parameters can be used
|
13
13
|
|
14
14
|
|
15
|
-
3.
|
15
|
+
3. [**Halts and Redirects**](https://github.com/maxbarsukov/yaframework/blob/master/examples/halts_and_redirects.rb)
|
16
16
|
|
17
17
|
Shows how to use halts and redirects
|
18
|
+
|
19
|
+
|
20
|
+
4. [**Headers**](https://github.com/maxbarsukov/yaframework/blob/master/examples/headers.rb)
|
21
|
+
|
22
|
+
How to add and view headers.
|
23
|
+
|
24
|
+
|
25
|
+
5. [**Error handling**](https://github.com/maxbarsukov/yaframework/blob/master/examples/error_handling.rb)
|
26
|
+
|
27
|
+
How to handle errors
|
28
|
+
|
29
|
+
|
30
|
+
6. [**Content Types**](https://github.com/maxbarsukov/yaframework/blob/master/examples/content_types.rb)
|
31
|
+
|
32
|
+
Using json, html, or plain text
|
33
|
+
|
34
|
+
|
35
|
+
7. [**Cookies**](https://github.com/maxbarsukov/yaframework/blob/master/examples/cookies.rb)
|
36
|
+
|
37
|
+
Adding and deleting cookies
|
38
|
+
|
39
|
+
|
40
|
+
8. [**Hooks**](https://github.com/maxbarsukov/yaframework/blob/master/examples/before_after_hooks.rb)
|
41
|
+
|
42
|
+
How to use `before` and `after` hooks
|
43
|
+
|
44
|
+
|
45
|
+
## Installation
|
46
|
+
|
47
|
+
Clone this repo and go to this folder.
|
48
|
+
Then, run `bundle install` to install this gem.
|
49
|
+
|
50
|
+
## Run
|
51
|
+
|
52
|
+
Run with `ruby hello-world.rb` or any other file and view at http://localhost:4567
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "yaframework"
|
4
|
+
app = Yaframework::Application
|
5
|
+
|
6
|
+
app.before do
|
7
|
+
@page_updates ||= 0
|
8
|
+
@page_updates += 1
|
9
|
+
end
|
10
|
+
|
11
|
+
app.after do
|
12
|
+
puts "Some log info: #{response.body}"
|
13
|
+
response.write "<br>Refresh the page and your next number will be #{@page_updates + 1}!"
|
14
|
+
end
|
15
|
+
|
16
|
+
app.get "/" do
|
17
|
+
"Hello, your num is: #{@page_updates}"
|
18
|
+
end
|
19
|
+
|
20
|
+
app.listen(4567)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "yaframework"
|
4
|
+
app = Yaframework::Application
|
5
|
+
|
6
|
+
app.get "/" do
|
7
|
+
response.redirect "/html"
|
8
|
+
end
|
9
|
+
|
10
|
+
app.get "/html" do
|
11
|
+
response.html "This is <b>HTML</b>, where you cat use some <small>tags</small>.
|
12
|
+
<br/>JSON <a href=\"/json\">here</a>,
|
13
|
+
<br/>Plain text <a href=\"/text\">here</a>"
|
14
|
+
end
|
15
|
+
|
16
|
+
app.get "/text" do
|
17
|
+
response.text "Just plain text.<br/>Boring, even tags don't work..."
|
18
|
+
end
|
19
|
+
|
20
|
+
app.get "/json" do
|
21
|
+
response.json "{ \"The awesomeness of this framework\": \"100/100\" }"
|
22
|
+
end
|
23
|
+
|
24
|
+
app.listen(4567)
|
data/examples/cookies.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "yaframework"
|
4
|
+
app = Yaframework::Application
|
5
|
+
|
6
|
+
app.get "/" do
|
7
|
+
response.set_cookie("foo", "bar")
|
8
|
+
"Your cookies, sir: #{response["Set-Cookie"]}.<br/>Go <a href=\"/delete\">here</a> to delete them"
|
9
|
+
end
|
10
|
+
|
11
|
+
app.get "/delete" do
|
12
|
+
response.delete_cookie("foo")
|
13
|
+
"Your cookies, sir: #{response["Set-Cookie"]}"
|
14
|
+
end
|
15
|
+
|
16
|
+
app.listen(4567)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "yaframework"
|
4
|
+
app = Yaframework::Application
|
5
|
+
|
6
|
+
app.get "/" do
|
7
|
+
"This is the root, go somewhere else..<br/>Maybe <a href=\"/asdfg\">here</a>, idk"
|
8
|
+
end
|
9
|
+
|
10
|
+
app.handle 404 do
|
11
|
+
"Hey, I just handled a 404 error!<br/>The dude from the previous page deceived you!"
|
12
|
+
end
|
13
|
+
|
14
|
+
app.handle 500 do
|
15
|
+
"Error 500, this shouldn't have happened..."
|
16
|
+
end
|
17
|
+
|
18
|
+
app.listen(4567)
|
data/examples/headers.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "yaframework"
|
4
|
+
app = Yaframework::Application
|
5
|
+
|
6
|
+
app.get "/" do
|
7
|
+
request[:username] = "IVAN!"
|
8
|
+
"Now 'request[:username]': #{request[:username]} contains in 'request.params': #{request.params}"
|
9
|
+
end
|
10
|
+
|
11
|
+
app.listen(4567)
|
@@ -3,11 +3,13 @@
|
|
3
3
|
require "yaframework"
|
4
4
|
app = Yaframework::Application
|
5
5
|
|
6
|
+
# Any route, like /max or /ivan
|
6
7
|
app.get "/:name" do
|
7
8
|
"Hello #{request.params[:name]}!"
|
8
9
|
end
|
9
10
|
|
10
|
-
|
11
|
+
# You can try /max/from/rnd and see it with your own eyes
|
12
|
+
app.get "/:name/from/:bar" do
|
11
13
|
"Hello #{request.params[:name]} from #{request.params[:bar]}!"
|
12
14
|
end
|
13
15
|
|
data/lib/yaframework/base.rb
CHANGED
@@ -5,9 +5,13 @@ require "rack"
|
|
5
5
|
module Yaframework
|
6
6
|
class Base
|
7
7
|
attr_reader :routes, :request, :response, :env
|
8
|
+
alias req request
|
9
|
+
alias res response
|
8
10
|
|
9
11
|
def initialize
|
10
12
|
@routes = Hash.new([])
|
13
|
+
@before_hooks = []
|
14
|
+
@after_hooks = []
|
11
15
|
@inbox = {}
|
12
16
|
end
|
13
17
|
|
@@ -28,6 +32,18 @@ module Yaframework
|
|
28
32
|
throw :halt, response
|
29
33
|
end
|
30
34
|
|
35
|
+
def before(&block)
|
36
|
+
@before_hooks << block
|
37
|
+
end
|
38
|
+
|
39
|
+
def after(&block)
|
40
|
+
@after_hooks << block
|
41
|
+
end
|
42
|
+
|
43
|
+
def params
|
44
|
+
request.params
|
45
|
+
end
|
46
|
+
|
31
47
|
def handle(status, &block)
|
32
48
|
@inbox[status] = block
|
33
49
|
end
|
@@ -55,17 +71,18 @@ module Yaframework
|
|
55
71
|
end
|
56
72
|
|
57
73
|
def route_eval
|
74
|
+
route = find_route
|
75
|
+
response.status = 404 unless route
|
76
|
+
|
58
77
|
if @inbox[response.status]
|
59
|
-
response.write
|
78
|
+
response.write exec(@inbox[response.status])
|
60
79
|
return response.finish
|
61
80
|
end
|
62
81
|
|
63
|
-
|
64
|
-
if route
|
65
|
-
|
66
|
-
|
67
|
-
response.status = 404
|
68
|
-
end
|
82
|
+
exec_before_hooks
|
83
|
+
response.write exec(route[:handler]) if route
|
84
|
+
exec_after_hooks
|
85
|
+
|
69
86
|
response.finish
|
70
87
|
end
|
71
88
|
|
@@ -82,6 +99,30 @@ module Yaframework
|
|
82
99
|
end
|
83
100
|
route
|
84
101
|
end
|
102
|
+
|
103
|
+
def exec(action)
|
104
|
+
if action.respond_to? :to_sym
|
105
|
+
send(action)
|
106
|
+
else
|
107
|
+
instance_exec(&action)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def exec_before_hooks
|
112
|
+
exec_hooks @before_hooks
|
113
|
+
end
|
114
|
+
|
115
|
+
def exec_after_hooks
|
116
|
+
exec_hooks @after_hooks
|
117
|
+
end
|
118
|
+
|
119
|
+
def exec_hooks(hooks)
|
120
|
+
return true if hooks.nil?
|
121
|
+
|
122
|
+
hooks.each do |hook|
|
123
|
+
return false if exec(hook) == false
|
124
|
+
end
|
125
|
+
end
|
85
126
|
end
|
86
127
|
|
87
128
|
Application = Base.new
|
data/lib/yaframework/response.rb
CHANGED
data/lib/yaframework/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaframework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- maxbarsukov
|
@@ -105,19 +105,16 @@ files:
|
|
105
105
|
- Rakefile
|
106
106
|
- bin/console
|
107
107
|
- bin/setup
|
108
|
+
- examples/Gemfile
|
108
109
|
- examples/README.md
|
109
|
-
- examples/
|
110
|
-
- examples/
|
111
|
-
- examples/
|
112
|
-
- examples/
|
113
|
-
- examples/
|
114
|
-
- examples/
|
115
|
-
- examples/
|
116
|
-
- examples/
|
117
|
-
- examples/params/Gemfile
|
118
|
-
- examples/params/README.md
|
119
|
-
- examples/params/app.rb
|
120
|
-
- examples/params/config.ru
|
110
|
+
- examples/before_after_hooks.rb
|
111
|
+
- examples/content_types.rb
|
112
|
+
- examples/cookies.rb
|
113
|
+
- examples/error_handling.rb
|
114
|
+
- examples/halts_and_redirects.rb
|
115
|
+
- examples/headers.rb
|
116
|
+
- examples/hello_world.rb
|
117
|
+
- examples/params.rb
|
121
118
|
- lib/yaframework.rb
|
122
119
|
- lib/yaframework/base.rb
|
123
120
|
- lib/yaframework/request.rb
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# Hello world
|
2
|
-
|
3
|
-
A simple application that displays "Hello world" to you.
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Clone this repo and go to this folder.
|
8
|
-
Then, run `bundle install` to install this gem.
|
9
|
-
|
10
|
-
## Run
|
11
|
-
|
12
|
-
Run with `ruby app.rb` or `rackup` and view at http://localhost:4567
|
data/examples/params/Gemfile
DELETED
data/examples/params/README.md
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# Params
|
2
|
-
|
3
|
-
Shows how the application parameters can be used
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Clone this repo and go to this folder.
|
8
|
-
Then, run `bundle install` to install this gem.
|
9
|
-
|
10
|
-
## Run
|
11
|
-
|
12
|
-
Run with `ruby app.rb` or `rackup` and view at http://localhost:4567
|