nyara 0.0.1.pre.9 → 0.1.pre.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.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/bin/nyara +3 -3
  3. data/changes +1 -0
  4. data/ext/event.c +16 -22
  5. data/ext/hashes.c +222 -4
  6. data/ext/inc/rdtsc.h +56 -0
  7. data/ext/inc/status_codes.inc +64 -0
  8. data/ext/inc/version.inc +1 -1
  9. data/ext/nyara.c +12 -10
  10. data/ext/nyara.h +5 -5
  11. data/ext/request.c +18 -24
  12. data/ext/request_parse.c +1 -1
  13. data/ext/route.cc +2 -4
  14. data/ext/url_encoded.c +51 -193
  15. data/lib/nyara/command.rb +39 -12
  16. data/lib/nyara/config.rb +10 -10
  17. data/lib/nyara/controller.rb +60 -14
  18. data/lib/nyara/cookie.rb +1 -1
  19. data/lib/nyara/hashes/config_hash.rb +2 -24
  20. data/lib/nyara/nyara.rb +33 -19
  21. data/lib/nyara/part.rb +7 -3
  22. data/lib/nyara/reload.rb +85 -0
  23. data/lib/nyara/request.rb +1 -1
  24. data/lib/nyara/route.rb +55 -19
  25. data/lib/nyara/templates/Gemfile +10 -1
  26. data/lib/nyara/templates/Rakefile +6 -1
  27. data/lib/nyara/templates/app/controllers/application_controller.rb +3 -0
  28. data/lib/nyara/templates/app/controllers/welcome_controller.rb +5 -0
  29. data/lib/nyara/templates/app/views/layouts/application.erb +12 -0
  30. data/lib/nyara/templates/app/views/welcome/index.erb +1 -0
  31. data/lib/nyara/templates/config/application.rb +34 -0
  32. data/lib/nyara/templates/config/boot.rb +4 -0
  33. data/lib/nyara/templates/config/development.rb +5 -0
  34. data/lib/nyara/templates/config/production.rb +8 -0
  35. data/lib/nyara/templates/config/test.rb +2 -0
  36. data/lib/nyara/templates/public/css/app.css +1 -0
  37. data/lib/nyara/templates/public/js/app.js +1 -0
  38. data/lib/nyara/templates/spec/spec_helper.rb +9 -0
  39. data/lib/nyara/test.rb +10 -2
  40. data/lib/nyara/view.rb +116 -67
  41. data/nyara.gemspec +3 -1
  42. data/rakefile +1 -1
  43. data/readme.md +1 -1
  44. data/spec/command_spec.rb +28 -24
  45. data/spec/config_spec.rb +24 -1
  46. data/spec/dummy/app/controllers/dummy_controller.rb +2 -0
  47. data/spec/dummy/app/models/dmmy_model.rb +2 -0
  48. data/spec/evented_io_spec.rb +2 -1
  49. data/spec/ext_route_spec.rb +2 -2
  50. data/spec/flash_spec.rb +8 -0
  51. data/spec/hashes_spec.rb +127 -0
  52. data/spec/integration_spec.rb +15 -0
  53. data/spec/path_helper_spec.rb +17 -5
  54. data/spec/performance/escape.rb +15 -4
  55. data/spec/performance/layout_render.rb +15 -10
  56. data/spec/performance/parse_accept_value.rb +24 -8
  57. data/spec/performance/parse_param.rb +14 -8
  58. data/spec/performance/performance_helper.rb +8 -21
  59. data/spec/performance_spec.rb +5 -4
  60. data/spec/route_spec.rb +7 -2
  61. data/spec/url_encoded_spec.rb +18 -74
  62. data/spec/view_spec.rb +1 -3
  63. data/spec/views/_partial.slim +1 -0
  64. data/spec/views/_partial_with_yield.erb +1 -0
  65. metadata +73 -43
  66. data/example/factorial.rb +0 -19
  67. data/example/hello.rb +0 -5
  68. data/example/project.rb +0 -11
  69. data/example/stream.rb +0 -14
  70. data/lib/nyara/controllers/public_controller.rb +0 -14
  71. data/lib/nyara/templates/config/session.key +0 -1
  72. data/tools/bench-cookie.rb +0 -22
  73. data/tools/foo.rb +0 -9
  74. data/tools/hello.rb +0 -46
  75. data/tools/memcheck.rb +0 -33
  76. data/tools/s.rb +0 -11
data/example/factorial.rb DELETED
@@ -1,19 +0,0 @@
1
- require 'nyara'
2
-
3
- get '/factorial(%u)' do |n|
4
- redirect_to '#product', 1, n
5
- end
6
-
7
- meta '#product'
8
- get '/%u*factorial(%u)' do |product, n|
9
- if n == 0
10
- redirect_to '#result', product
11
- else
12
- redirect_to '#product', product * n, n - 1
13
- end
14
- end
15
-
16
- meta '#result'
17
- get '/%u' do |result|
18
- send_string result
19
- end
data/example/hello.rb DELETED
@@ -1,5 +0,0 @@
1
- require "nyara"
2
-
3
- get '/' do
4
- send_string 'hello world'
5
- end
data/example/project.rb DELETED
@@ -1,11 +0,0 @@
1
- require_relative "../lib/nyara"
2
-
3
- configure do
4
- set :root, __dir__
5
- set :public, 'public'
6
- set :views, 'views'
7
- end
8
-
9
- get '/' do
10
- send_string 'hello'
11
- end
data/example/stream.rb DELETED
@@ -1,14 +0,0 @@
1
- require_relative "../lib/nyara"
2
- require "pry"
3
-
4
- configure do
5
- set :root, __dir__
6
- end
7
-
8
- get '/' do
9
- view = stream 'index'
10
- 4.times do
11
- sleep 1
12
- view.resume
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- module Nyara
2
- # serve public dir
3
- class PublicController < Controller
4
- get '/%z' do |path|
5
- path = Config.public_path path
6
- if path and File.file?(path)
7
- send_file path
8
- else
9
- status 404
10
- Ext.request_send_data request, "HTTP/1.1 404 Not Found\r\nConnection: close\r\nContent-Length: 0\r\n\r\n"
11
- end
12
- end
13
- end
14
- end
@@ -1 +0,0 @@
1
- <%= Nyara::Session.generate_key %>
@@ -1,22 +0,0 @@
1
- require_relative "../lib/nyara/nyara"
2
- include Nyara
3
- require "benchmark"
4
-
5
- def cookie1 s
6
- res = ParamHash.new
7
- s.split(/[,;] */n).reverse_each do |seg|
8
- Ext.parse_url_encoded_seg res, seg, false
9
- end
10
- end
11
-
12
- def cookie2 s
13
- res = ParamHash.new
14
- Ext.parse_cookie res, s
15
- end
16
-
17
- history = CGI.escape '历史'
18
- s = "pgv_pvi; pgv_si=; pgv_pvi=som; sid=1d6c75f0 ; PLHistory=<#{history}>;"
19
-
20
- puts Benchmark.measure{ 1000.times{cookie1 s} }
21
- puts Benchmark.measure{ 1000.times{cookie2 s} }
22
- # cookie2 should be faster
data/tools/foo.rb DELETED
@@ -1,9 +0,0 @@
1
- require_relative "../lib/nyara"
2
-
3
- post '/' do
4
- data = File.binread('text.gz')
5
- set_header 'Content-Length', data.bytesize
6
- set_header 'Content-Encoding', 'gzip'
7
- set_header 'Transfer-Encoding', 'chunked'
8
- send_string data
9
- end
data/tools/hello.rb DELETED
@@ -1,46 +0,0 @@
1
- require_relative "../lib/nyara/nyara"
2
- # require "open-uri"
3
- require "pry"
4
-
5
- configure do
6
- # set :env, 'production'
7
- # set :workers, 3
8
- map '/', 'my'
9
- # set :logger, false
10
- end
11
-
12
- class MyController < Nyara::Controller
13
- get '/' do
14
- p param
15
- send_string 'hello world'
16
- end
17
-
18
- get '/exit' do
19
- exit
20
- end
21
-
22
- get '/form' do
23
- send_string <<-HTML
24
- <form action="/form" enctype="multipart/form-data" method="post" accept-charset="utf-8">
25
- bar
26
- <input type="file" name="bar">
27
- <br>
28
- baz
29
- <input type="file" name="baz[你好]">
30
- <br>
31
- foo<input name="foo">
32
- <br>
33
- </form>
34
- HTML
35
- end
36
-
37
- post '/form' do
38
- b = request.body
39
- binding.pry
40
- end
41
- end
42
-
43
- Nyara.setup
44
- Nyara.start_server
45
-
46
- # GC.stress = true
data/tools/memcheck.rb DELETED
@@ -1,33 +0,0 @@
1
- require_relative "../lib/nyara/nyara"
2
-
3
- module Nyara
4
- class SimpleController < Controller
5
- end
6
- end
7
-
8
- %w[on tag get post put delete patch options].each do |m|
9
- eval <<-RUBY
10
- def #{m} *xs, &blk
11
- Nyara::SimpleController.#{m} *xs, &blk
12
- end
13
- RUBY
14
- end
15
-
16
- configure do
17
- map '/', 'nyara::simple'
18
- end
19
-
20
- get '/' do
21
- send_string 'hello world'
22
- end
23
-
24
- get '/gc' do
25
- GC.stress = true
26
- end
27
-
28
- get '/ngc' do
29
- GC.stress = false
30
- end
31
-
32
- Nyara.setup
33
- Nyara.start_server
data/tools/s.rb DELETED
@@ -1,11 +0,0 @@
1
- require "sinatra"
2
- require "active_support/core_ext"
3
-
4
- configure {
5
- disable :logging
6
- disable :protection
7
- }
8
-
9
- get '/' do
10
- 'hello world'
11
- end