yaframework 0.4.2 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8009597e2e41965f0ad078918d629c4b88eaf2536d9c001053079cdfd24705a
4
- data.tar.gz: 44386071847fd8a44299d967a8d8605b615a3fc865afd21a4f555410c10b3cba
3
+ metadata.gz: 4aec9734b89fbd8a9c87fb63506f49f53df83c0f141efd612d5cdceb9d4d8c64
4
+ data.tar.gz: 8d43e4889c14798d20400ae36bfa9c6b76797bf7348eac539d85c690dcf250a3
5
5
  SHA512:
6
- metadata.gz: 505e79eee033484f4ecd2eb08daca91521e2d93f5b780051fe82968d9a5510b0ac5152d4cc61aee77827e85d1e40d053451881e623e9f0f713fc1e0f0e03b1fa
7
- data.tar.gz: 842210c79e38f9c984018c38377f704d235bd4f795ce3753cd89fdcddceb9c2d93db654c94d68dec23a4de818ade9719a08d382f5b6abb4fed5d29b5259cf8a1
6
+ metadata.gz: 00af9a420fd2edffe78d77d6a2ecfc81973cbadb9543424153a6a5e689409a06d4c98a5ff54e7ddbda2a122cbe3bcd2d5b563968f8820738c6f21747269201d7
7
+ data.tar.gz: ba55916ef3b9776ab8711e82af51406b5d4e00b6991acf04418fc1526f6a0aa803757b9744296180843cf201534f4ed14292ac2f738a92d00bb8d5ad11bf6925
data/.gitignore CHANGED
@@ -13,3 +13,4 @@
13
13
  *.gem
14
14
  *.rbc
15
15
  /examples/**/Gemfile.lock
16
+ /lib/app.rb
data/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ ## [0.4.7] - 2021-07-25
2
+
3
+ - Handling 404 error fixed
4
+
5
+ ## [0.4.6] - 2021-07-25
6
+
7
+ - Content duplication fixed
8
+
9
+ ## [0.4.5] - 2021-07-25
10
+
11
+ - Error handling added
12
+
13
+ ## [0.4.4] - 2021-07-25
14
+
15
+ - Interaction with cookies has been updated
16
+
17
+ ## [0.4.3] - 2021-07-25
18
+
19
+ - Updated the method for changing the Content-Type
20
+ - Interaction with headers has been improved
21
+
1
22
  ## [0.4.2] - 2021-07-24
2
23
 
3
24
  - DB module removed
data/Gemfile CHANGED
@@ -3,7 +3,3 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gemspec
6
-
7
- gem "minitest", "~> 5.0"
8
- gem "pg", "~> 1.2", ">= 1.2.3"
9
- gem "rack", "~> 2.2", ">= 2.2.3"
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- yaframework (0.4.1)
5
- rack (~> 2.2)
4
+ yaframework (0.4.7)
5
+ rack (~> 2.2, >= 2.2.3)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -10,39 +10,36 @@ GEM
10
10
  ast (2.4.2)
11
11
  minitest (5.14.4)
12
12
  parallel (1.20.1)
13
- parser (3.0.2.0)
13
+ parser (3.0.1.1)
14
14
  ast (~> 2.4.1)
15
- pg (1.2.3)
16
15
  rack (2.2.3)
17
16
  rainbow (3.0.0)
18
- rake (13.0.6)
17
+ rake (13.0.3)
19
18
  regexp_parser (2.1.1)
20
19
  rexml (3.2.5)
21
- rubocop (1.18.4)
20
+ rubocop (1.18.2)
22
21
  parallel (~> 1.10)
23
22
  parser (>= 3.0.0.0)
24
23
  rainbow (>= 2.2.2, < 4.0)
25
24
  regexp_parser (>= 1.8, < 3.0)
26
25
  rexml
27
- rubocop-ast (>= 1.8.0, < 2.0)
26
+ rubocop-ast (>= 1.7.0, < 2.0)
28
27
  ruby-progressbar (~> 1.7)
29
28
  unicode-display_width (>= 1.4.0, < 3.0)
30
- rubocop-ast (1.8.0)
29
+ rubocop-ast (1.7.0)
31
30
  parser (>= 3.0.1.1)
32
31
  ruby-progressbar (1.11.0)
33
32
  unicode-display_width (2.0.0)
34
33
 
35
34
  PLATFORMS
36
- ruby
35
+ x86_64-linux
37
36
 
38
37
  DEPENDENCIES
39
- bundler (~> 2.1.4)
38
+ bundler (>= 2.2.10)
40
39
  minitest (~> 5.0)
41
- pg (~> 1.2, >= 1.2.3)
42
- rack (~> 2.2, >= 2.2.3)
43
40
  rake (~> 13.0)
44
41
  rubocop (~> 1.7)
45
42
  yaframework!
46
43
 
47
44
  BUNDLED WITH
48
- 2.1.4
45
+ 2.2.16
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Yaframework
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/yaframework.svg)](https://badge.fury.io/rb/sinatra)
3
+ [![Gem Version](https://badge.fury.io/rb/yaframework.svg)](https://badge.fury.io/rb/yaframework)
4
4
  [![Build Status](https://app.travis-ci.com/maxbarsukov/yaframework.svg?token=T4CL2EqKG6FY816F3W3F&branch=master)](https://app.travis-ci.com/maxbarsukov/yaframework)
5
5
 
6
6
  Yaframework is a [DSL](https://en.wikipedia.org/wiki/Domain-specific_language) for
File without changes
data/examples/README.md CHANGED
@@ -2,16 +2,27 @@
2
2
 
3
3
  Here are some examples of applications created with Yaframework:
4
4
 
5
- 1. ###[Hello World](https://github.com/maxbarsukov/yaframework/tree/master/examples/hello-world)
5
+ 1. [**Hello World**](https://github.com/maxbarsukov/yaframework/tree/master/examples/hello_world.rb)
6
6
 
7
- A simple application that displays "Hello world" to you.
7
+ A simple application that displays "Hello world" to you. Go to `http://localhost:4567/` and see `Hello World`!
8
8
 
9
9
 
10
- 2. ###[Params](https://github.com/maxbarsukov/yaframework/tree/master/examples/params)
10
+ 2. [**Params**](https://github.com/maxbarsukov/yaframework/tree/master/examples/params.rb)
11
11
 
12
12
  Shows how the application parameters can be used
13
13
 
14
14
 
15
- 3. ###[Halts and Redirects](https://github.com/maxbarsukov/yaframework/tree/master/examples/halts-and-redirects)
15
+ 3. [**Halts and Redirects**](https://github.com/maxbarsukov/yaframework/tree/master/examples/halts_and_redirects.rb)
16
16
 
17
17
  Shows how to use halts and redirects
18
+
19
+
20
+ ## Installation
21
+
22
+ Clone this repo and go to this folder.
23
+ Then, run `bundle install` to install this gem.
24
+
25
+ ## Run
26
+
27
+ Run with `ruby hello-world.rb` or any other file and view at http://localhost:4567
28
+
@@ -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)
@@ -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_relative "../lib/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)
@@ -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,6 +3,7 @@
3
3
  require "yaframework"
4
4
  app = Yaframework::Application
5
5
 
6
+ # Just go to the root page and say hello
6
7
  app.get "/" do
7
8
  "Hello world!"
8
9
  end
@@ -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
- app.get "/:name/foo/:bar" do
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
 
@@ -8,6 +8,7 @@ module Yaframework
8
8
 
9
9
  def initialize
10
10
  @routes = Hash.new([])
11
+ @inbox = {}
11
12
  end
12
13
 
13
14
  %w[GET POST PATCH PUT DELETE HEAD OPTIONS].each do |verb|
@@ -27,6 +28,10 @@ module Yaframework
27
28
  throw :halt, response
28
29
  end
29
30
 
31
+ def handle(status, &block)
32
+ @inbox[status] = block
33
+ end
34
+
30
35
  def listen(port = 5000)
31
36
  Rack::Handler::WEBrick.run self, Port: port
32
37
  end
@@ -51,11 +56,14 @@ module Yaframework
51
56
 
52
57
  def route_eval
53
58
  route = find_route
54
- if route
55
- response.write instance_eval(&route[:handler])
56
- else
57
- response.status = 404
59
+ response.status = 404 unless route
60
+
61
+ if @inbox[response.status]
62
+ response.write instance_eval(&@inbox[response.status])
63
+ return response.finish
58
64
  end
65
+
66
+ response.write instance_eval(&route[:handler]) if route
59
67
  response.finish
60
68
  end
61
69
 
@@ -2,6 +2,14 @@
2
2
 
3
3
  module Yaframework
4
4
  class Response
5
+ LOCATION = "Location"
6
+
7
+ module ContentType
8
+ HTML = "text/html"
9
+ TEXT = "text/plain"
10
+ JSON = "application/json"
11
+ end
12
+
5
13
  attr_accessor :status
6
14
  attr_reader :headers, :body
7
15
 
@@ -21,19 +29,51 @@ module Yaframework
21
29
  end
22
30
 
23
31
  def finish
24
- headers["Content-Length"] = @length.to_s unless (100..199).include?(status) || status == 204
32
+ @headers[Rack::CONTENT_LENGTH] = @length.to_s unless (100..199).include?(status) || status == 204
25
33
  [status, headers, body]
26
34
  end
27
35
 
28
36
  def redirect(target, status = 302)
29
- self.status = status
30
- headers["Location"] = target
37
+ @status = status
38
+ @headers[LOCATION] = target
31
39
  end
32
40
 
33
41
  def write(string)
34
42
  s = string.to_s
35
43
  @length += s.bytesize
36
- body << s
44
+ @body << s
45
+ nil
46
+ end
47
+
48
+ def [](key)
49
+ @headers[key]
50
+ end
51
+
52
+ def []=(key, value)
53
+ @headers[key] = value
54
+ end
55
+
56
+ def html(str)
57
+ @headers[Rack::CONTENT_TYPE] = ContentType::HTML
58
+ write(str)
59
+ end
60
+
61
+ def text(str)
62
+ @headers[Rack::CONTENT_TYPE] = ContentType::TEXT
63
+ write(str)
64
+ end
65
+
66
+ def json(str)
67
+ @headers[Rack::CONTENT_TYPE] = ContentType::JSON
68
+ write(str)
69
+ end
70
+
71
+ def set_cookie(key, value)
72
+ Rack::Utils.set_cookie_header!(@headers, key, value)
73
+ end
74
+
75
+ def delete_cookie(key, value = {})
76
+ Rack::Utils.delete_cookie_header!(@headers, key, value)
37
77
  end
38
78
  end
39
79
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Yaframework
4
- VERSION = "0.4.2"
4
+ VERSION = "0.4.7"
5
5
  end
data/yaframework.gemspec CHANGED
@@ -29,8 +29,9 @@ Gem::Specification.new do |spec|
29
29
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
30
 
31
31
  spec.add_development_dependency "bundler", ">= 2.2.10"
32
+ spec.add_development_dependency "minitest", "~> 5.0"
32
33
  spec.add_development_dependency "rake", "~> 13.0"
33
34
  spec.add_development_dependency "rubocop", "~> 1.7"
34
35
 
35
- spec.add_runtime_dependency "rack", "~> 2.2"
36
+ spec.add_runtime_dependency "rack", "~> 2.2", ">= 2.2.3"
36
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaframework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - maxbarsukov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-24 00:00:00.000000000 Z
11
+ date: 2021-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.2.10
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -59,6 +73,9 @@ dependencies:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
75
  version: '2.2'
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 2.2.3
62
79
  type: :runtime
63
80
  prerelease: false
64
81
  version_requirements: !ruby/object:Gem::Requirement
@@ -66,6 +83,9 @@ dependencies:
66
83
  - - "~>"
67
84
  - !ruby/object:Gem::Version
68
85
  version: '2.2'
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 2.2.3
69
89
  description: What could be better than one more Sinatra?
70
90
  email:
71
91
  - maximbarsukov@bk.ru
@@ -85,19 +105,15 @@ files:
85
105
  - Rakefile
86
106
  - bin/console
87
107
  - bin/setup
108
+ - examples/Gemfile
88
109
  - examples/README.md
89
- - examples/halts-and-redirects/Gemfile
90
- - examples/halts-and-redirects/README.md
91
- - examples/halts-and-redirects/app.rb
92
- - examples/halts-and-redirects/config.ru
93
- - examples/hello-world/Gemfile
94
- - examples/hello-world/README.md
95
- - examples/hello-world/app.rb
96
- - examples/hello-world/config.ru
97
- - examples/params/Gemfile
98
- - examples/params/README.md
99
- - examples/params/app.rb
100
- - examples/params/config.ru
110
+ - examples/content_types.rb
111
+ - examples/cookies.rb
112
+ - examples/error_handling.rb
113
+ - examples/halts_and_redirects.rb
114
+ - examples/headers.rb
115
+ - examples/hello_world.rb
116
+ - examples/params.rb
101
117
  - lib/yaframework.rb
102
118
  - lib/yaframework/base.rb
103
119
  - lib/yaframework/request.rb
@@ -1,12 +0,0 @@
1
- # Params
2
-
3
- Shows how to use halts and redirects
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
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "yaframework"
4
- require "./app"
5
-
6
- run app
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "yaframework"
@@ -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
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "yaframework"
4
- require "./app"
5
-
6
- run app
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "yaframework"
@@ -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
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "yaframework"
4
- require "./app"
5
-
6
- run app