nyara 0.1.pre.0 → 0.1.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/nyara +2 -14
- data/changes +3 -0
- data/example/factorial.rb +19 -0
- data/example/hello.rb +5 -0
- data/example/project.rb +11 -0
- data/example/stream.rb +14 -0
- data/ext/extconf.rb +19 -0
- data/ext/hashes.c +160 -57
- data/ext/inc/ary_intern.h +36 -0
- data/ext/route.cc +2 -1
- data/ext/url_encoded.c +1 -0
- data/lib/nyara.rb +1 -0
- data/lib/nyara/command.rb +60 -79
- data/lib/nyara/config.rb +19 -1
- data/lib/nyara/controller.rb +64 -7
- data/lib/nyara/hashes/config_hash.rb +3 -20
- data/lib/nyara/hashes/header_hash.rb +2 -2
- data/lib/nyara/hashes/param_hash.rb +1 -0
- data/lib/nyara/nyara.rb +45 -37
- data/lib/nyara/part.rb +2 -2
- data/lib/nyara/reload.rb +63 -64
- data/lib/nyara/route.rb +7 -6
- data/lib/nyara/session.rb +4 -0
- data/lib/nyara/templates/{Gemfile → Gemfile.tt} +4 -0
- data/lib/nyara/templates/Linnerfile +28 -0
- data/lib/nyara/templates/Rakefile +16 -2
- data/lib/nyara/templates/app/assets/files/favicon.ico +1 -0
- data/lib/nyara/templates/app/assets/files/robots.txt +5 -0
- data/lib/nyara/templates/app/assets/scripts/app.coffee +4 -0
- data/lib/nyara/templates/app/assets/scripts/module-example.coffee +4 -0
- data/lib/nyara/templates/app/assets/styles/app.scss +2 -0
- data/lib/nyara/templates/app/controllers/application_controller.rb +8 -0
- data/lib/nyara/templates/app/views/layouts/application.erb.tt +12 -0
- data/lib/nyara/templates/config/application.rb +4 -0
- data/lib/nyara/templates/config/{database.yml → database.yml.tt} +3 -3
- data/lib/nyara/templates/config/production.rb +2 -0
- data/lib/nyara/view.rb +6 -2
- data/nyara.gemspec +3 -1
- data/rakefile +7 -26
- data/spec/apps/reload.rb +35 -0
- data/spec/command_spec.rb +24 -10
- data/spec/config_spec.rb +19 -8
- data/spec/controller_spec.rb +14 -0
- data/spec/evented_io_spec.rb +3 -1
- data/spec/ext_route_spec.rb +25 -3
- data/spec/hashes_spec.rb +45 -21
- data/spec/integration_spec.rb +28 -2
- data/spec/path_helper_spec.rb +7 -0
- data/spec/performance_spec.rb +1 -1
- data/spec/public/test.css +1 -0
- data/{lib/nyara/templates/public/robot.txt → spec/public/test.jpg} +0 -0
- data/spec/public/test.js +1 -0
- data/spec/reload_spec.rb +50 -0
- data/spec/route_spec.rb +4 -4
- data/spec/spec_helper.rb +15 -9
- data/spec/url_encoded_spec.rb +5 -0
- data/spec/view_spec.rb +7 -0
- data/spec/views/_partial.slim +1 -1
- data/tools/bug.rb +53 -0
- data/tools/hello.rb +49 -0
- data/tools/memcheck.rb +33 -0
- metadata +73 -41
- data/ext/inc/status_codes.inc +0 -64
- data/lib/nyara/templates/app/views/layouts/application.erb +0 -12
- data/lib/nyara/templates/public/css/app.css +0 -1
- data/lib/nyara/templates/public/js/app.js +0 -1
@@ -0,0 +1 @@
|
|
1
|
+
favicon.ico
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
5
|
+
<title><%= @app_name %></title>
|
6
|
+
<link type="text/css" rel="stylesheet" href="<%%= asset_path("/assets/app.css") %>">
|
7
|
+
<script type="text/javascript" src="<%%= asset_path("/assets/app.js") %>"></script>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<%%== yield %>
|
11
|
+
</body>
|
12
|
+
</html>
|
@@ -5,6 +5,8 @@ configure do
|
|
5
5
|
set :env, ENV['NYARA_ENV'] || 'development'
|
6
6
|
|
7
7
|
set :views, 'app/views'
|
8
|
+
|
9
|
+
set :assets, "app/assets"
|
8
10
|
|
9
11
|
set :session, :name, '_aaa'
|
10
12
|
|
@@ -14,6 +16,8 @@ configure do
|
|
14
16
|
## Default session expires when browser closes.
|
15
17
|
## If you need time-based expiration, 30 minutes for example:
|
16
18
|
# set :session, :expires, 30 * 60
|
19
|
+
|
20
|
+
set 'session', 'key', File.read(project_path 'config/session.key')
|
17
21
|
|
18
22
|
# Routing
|
19
23
|
map '/', 'welcome'
|
@@ -8,7 +8,7 @@ development:
|
|
8
8
|
default:
|
9
9
|
hosts:
|
10
10
|
- 127.0.0.1:27017
|
11
|
-
database: '<%= app_name %>_dev'
|
11
|
+
database: '<%= @app_name %>_dev'
|
12
12
|
|
13
13
|
test:
|
14
14
|
<<: *defaults
|
@@ -16,7 +16,7 @@ test:
|
|
16
16
|
default:
|
17
17
|
hosts:
|
18
18
|
- 127.0.0.1:27017
|
19
|
-
database: '<%= app_name %>_test'
|
19
|
+
database: '<%= @app_name %>_test'
|
20
20
|
|
21
21
|
# set these environment variables on your prod server
|
22
22
|
production:
|
@@ -25,4 +25,4 @@ production:
|
|
25
25
|
default:
|
26
26
|
hosts:
|
27
27
|
- 127.0.0.1:27017
|
28
|
-
database: '<%= app_name %>'
|
28
|
+
database: '<%= @app_name %>'
|
data/lib/nyara/view.rb
CHANGED
@@ -171,8 +171,7 @@ module Nyara
|
|
171
171
|
RENDER[meth] = Renderable.make_render_method path, 0, sig, src
|
172
172
|
else
|
173
173
|
t = Dir.chdir @root do
|
174
|
-
|
175
|
-
Tilt.new path rescue return
|
174
|
+
Tilt.new path
|
176
175
|
end
|
177
176
|
# partly precompiled
|
178
177
|
RENDER[meth] = TiltRenderable.new t
|
@@ -210,6 +209,7 @@ module Nyara
|
|
210
209
|
#
|
211
210
|
# `[meth_obj, ext_without_dot]`
|
212
211
|
def template path, locals={}
|
212
|
+
raw_path = path
|
213
213
|
if File.extname(path).empty?
|
214
214
|
Dir.chdir @root do
|
215
215
|
paths = Dir.glob("#{path}.{#@ext_list}")
|
@@ -220,6 +220,10 @@ module Nyara
|
|
220
220
|
end
|
221
221
|
end
|
222
222
|
|
223
|
+
if path.blank?
|
224
|
+
raise ArgumentError, "template '#{raw_path}' file not found in view dir."
|
225
|
+
end
|
226
|
+
|
223
227
|
meth = path2meth path
|
224
228
|
ext = @meth2ext[meth]
|
225
229
|
return [RENDER[meth], ext] if ext
|
data/nyara.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "nyara"
|
3
|
-
s.version = "0.1.pre.
|
3
|
+
s.version = "0.1.pre.1"
|
4
4
|
s.author = "Zete Lui"
|
5
5
|
s.email = "nobody@example.com"
|
6
6
|
s.homepage = "https://github.com/luikore/nyara"
|
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.rubygems_version = '2.0.3'
|
23
23
|
s.add_runtime_dependency 'tilt', '>= 1.3'
|
24
24
|
s.add_runtime_dependency 'listen', '>= 1.1.3'
|
25
|
+
s.add_runtime_dependency 'thor', '>= 0.18'
|
25
26
|
|
26
27
|
s.rdoc_options += %w[
|
27
28
|
-v
|
@@ -33,5 +34,6 @@ Gem::Specification.new do |s|
|
|
33
34
|
-x ext/inc/.*
|
34
35
|
-x .*\.o
|
35
36
|
-x .*\.bundle
|
37
|
+
-x .*\.so
|
36
38
|
]
|
37
39
|
end
|
data/rakefile
CHANGED
@@ -3,13 +3,9 @@ require "rake"
|
|
3
3
|
Dir.chdir __dir__
|
4
4
|
|
5
5
|
status_file = "ext/inc/status_codes.h"
|
6
|
-
version_file = "ext/inc/version.inc"
|
7
6
|
makefile = "ext/Makefile"
|
8
7
|
extconf = "ext/extconf.rb"
|
9
8
|
|
10
|
-
desc "code generate"
|
11
|
-
task :gen => [version_file]
|
12
|
-
|
13
9
|
desc "generate #{status_file}"
|
14
10
|
file status_file => __FILE__ do
|
15
11
|
puts "generating: #{status_file}"
|
@@ -27,25 +23,8 @@ file status_file => __FILE__ do
|
|
27
23
|
f.close
|
28
24
|
end
|
29
25
|
|
30
|
-
desc "generate #{version_file}"
|
31
|
-
file version_file => ['nyara.gemspec', __FILE__] do
|
32
|
-
puts "generating: #{version_file}"
|
33
|
-
lines = File.readlines('nyara.gemspec')
|
34
|
-
version = nil
|
35
|
-
lines.each do |line|
|
36
|
-
if line =~ /s\.version =/
|
37
|
-
version = line[/\d+(\.\d+)*(\.pre\.\d+)?/]
|
38
|
-
break
|
39
|
-
end
|
40
|
-
end
|
41
|
-
abort 'version not found' unless version
|
42
|
-
File.open version_file, 'w' do |f|
|
43
|
-
f.puts %Q{#define NYARA_VERSION "#{version}"}
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
26
|
desc "generate makefile"
|
48
|
-
file makefile => extconf do
|
27
|
+
file makefile => [extconf, 'nyara.gemspec', __FILE__] do
|
49
28
|
Dir.chdir 'ext' do
|
50
29
|
sh 'make clean' if File.exist?('Makefile')
|
51
30
|
sh 'ruby extconf.rb'
|
@@ -65,16 +44,18 @@ task :test => :build do
|
|
65
44
|
end
|
66
45
|
|
67
46
|
desc "build and test"
|
68
|
-
task :default =>
|
47
|
+
task :default => :test
|
69
48
|
|
70
49
|
desc "build and install gem"
|
71
|
-
task :gem
|
50
|
+
task :gem do
|
72
51
|
Dir.glob('*.gem') do |f|
|
73
52
|
sh 'rm', f
|
74
53
|
end
|
54
|
+
# we need to run gem command without the mess of bundler
|
55
|
+
ENV['RUBYOPT'] &&= ENV['RUBYOPT'].gsub /\S*bundler\S*/, ''
|
75
56
|
sh 'gem', 'build', 'nyara.gemspec'
|
76
57
|
gem_package = Dir.glob('*.gem').first
|
77
|
-
sh 'gem', 'install', '--rdoc', '--ri', gem_package
|
58
|
+
sh 'gem', 'install', '-l', '--rdoc', '--ri', gem_package
|
78
59
|
end
|
79
60
|
|
80
61
|
desc "clean"
|
@@ -146,7 +127,7 @@ end
|
|
146
127
|
desc "audit arity of rb_define_method/rb_define_singleton_method"
|
147
128
|
task :audit_arity do
|
148
129
|
Dir.glob 'ext/*.{c,cc}' do |f|
|
149
|
-
puts "
|
130
|
+
puts "validating #{f}"
|
150
131
|
arities = {}
|
151
132
|
data = File.read f
|
152
133
|
data.scan /^(?:static )?VALUE (\w+)\((.+)\)/ do |func, params|
|
data/spec/apps/reload.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# reload views and files
|
2
|
+
|
3
|
+
require_relative "../../lib/nyara"
|
4
|
+
|
5
|
+
if ENV['RELOAD_ROOT']
|
6
|
+
configure do
|
7
|
+
set :logger, false
|
8
|
+
end
|
9
|
+
else
|
10
|
+
puts "running outside spec, ENV['RELOAD_ROOT'] is nil, creating root dir"
|
11
|
+
require 'tmpdir'
|
12
|
+
require 'pry'
|
13
|
+
ENV['RELOAD_ROOT'] = Dir.mktmpdir 'root'
|
14
|
+
Dir.mkdir ENV['RELOAD_ROOT'] + '/views'
|
15
|
+
File.open ENV['RELOAD_ROOT'] + '/reloadee.rb', 'w' do |f|
|
16
|
+
f << "RELOADEE = 1"
|
17
|
+
end
|
18
|
+
File.open ENV['RELOAD_ROOT'] + '/views/index.slim', 'w' do |f|
|
19
|
+
f << "== 1"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
configure do
|
24
|
+
set :port, 3004
|
25
|
+
set :root, ENV['RELOAD_ROOT']
|
26
|
+
set :app_files, 'reloadee.rb'
|
27
|
+
end
|
28
|
+
|
29
|
+
get '/views' do
|
30
|
+
render 'index'
|
31
|
+
end
|
32
|
+
|
33
|
+
get '/app' do
|
34
|
+
send_string RELOADEE
|
35
|
+
end
|
data/spec/command_spec.rb
CHANGED
@@ -2,34 +2,48 @@ require_relative "spec_helper"
|
|
2
2
|
|
3
3
|
module Nyara
|
4
4
|
describe Command do
|
5
|
-
|
6
|
-
|
5
|
+
before :each do
|
6
|
+
@command = Command.new
|
7
7
|
end
|
8
8
|
|
9
9
|
it "#version" do
|
10
|
-
assert_equal(stdout {
|
10
|
+
assert_equal(capture(:stdout) { @command.version }.strip, "Nyara #{Nyara::VERSION}")
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
it "#generate" do
|
14
|
+
pending
|
15
|
+
end
|
16
|
+
|
17
|
+
it "#server" do
|
18
|
+
pending
|
19
|
+
end
|
20
|
+
|
21
|
+
it "#console" do
|
22
|
+
pending
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#new" do
|
26
|
+
before :each do
|
27
|
+
GC.stress = false
|
15
28
|
@tmp_dir = Dir.mktmpdir 'nyara'
|
16
29
|
@old_dir = File.dirname __dir__
|
17
30
|
FileUtils.mkdir_p(@tmp_dir)
|
18
31
|
@app_name = "app_#{Time.now.to_i}"
|
19
|
-
@
|
20
|
-
|
21
|
-
|
32
|
+
Dir.chdir @tmp_dir do
|
33
|
+
@stdout = capture(:stdout) do
|
34
|
+
@command = Command.new
|
35
|
+
@command.new(@app_name)
|
22
36
|
end
|
23
37
|
end
|
24
38
|
end
|
25
39
|
|
26
|
-
after :
|
40
|
+
after :each do
|
27
41
|
FileUtils.rm_rf(@tmp_dir)
|
28
42
|
end
|
29
43
|
|
30
44
|
describe "should create app dir" do
|
31
45
|
it "should run finish" do
|
32
|
-
assert_include(@stdout, "
|
46
|
+
assert_include(@stdout, "👻")
|
33
47
|
end
|
34
48
|
|
35
49
|
it "should copy same files into new dir" do
|
data/spec/config_spec.rb
CHANGED
@@ -34,25 +34,26 @@ module Nyara
|
|
34
34
|
assert_equal 3000, Config['port']
|
35
35
|
end
|
36
36
|
|
37
|
-
it "views and public default" do
|
38
|
-
Config[:root] =
|
37
|
+
it "views, assets and public default" do
|
38
|
+
Config[:root] = __dir__
|
39
39
|
Config.init
|
40
40
|
assert_equal nil, Config['public']
|
41
|
-
assert_equal '/
|
41
|
+
assert_equal __dir__ + '/views', Config['views']
|
42
|
+
assert_equal nil, Config['assets']
|
42
43
|
end
|
43
44
|
|
44
45
|
context "#project_path" do
|
45
46
|
before :each do
|
46
47
|
Config.configure do
|
47
48
|
reset
|
48
|
-
set :root,
|
49
|
+
set :root, __dir__
|
49
50
|
init
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
53
54
|
it "works" do
|
54
55
|
path = Config.project_path 'b/../../c', false
|
55
|
-
assert_equal '/c', path
|
56
|
+
assert_equal File.dirname(__dir__) + '/c', path
|
56
57
|
end
|
57
58
|
|
58
59
|
it "restrict mode ensures dir safety" do
|
@@ -62,18 +63,18 @@ module Nyara
|
|
62
63
|
|
63
64
|
it "restrict mode allows '..' if it doesn't get outside" do
|
64
65
|
path = Config.project_path 'b/../c', true
|
65
|
-
assert_equal '/
|
66
|
+
assert_equal __dir__ + '/c', path
|
66
67
|
end
|
67
68
|
end
|
68
69
|
|
69
70
|
it "#public_path" do
|
70
71
|
Config.configure do
|
71
|
-
set :root,
|
72
|
+
set :root, __dir__
|
72
73
|
set :public, 'a'
|
73
74
|
init
|
74
75
|
end
|
75
76
|
path = Config.public_path '/b'
|
76
|
-
assert_equal '/
|
77
|
+
assert_equal __dir__ + '/a/b', path
|
77
78
|
end
|
78
79
|
|
79
80
|
it "#views_path" do
|
@@ -86,6 +87,16 @@ module Nyara
|
|
86
87
|
assert_equal '/', path
|
87
88
|
end
|
88
89
|
|
90
|
+
it "#assets_path" do
|
91
|
+
Config.configure do
|
92
|
+
set :root, '/'
|
93
|
+
set :assets, '/a'
|
94
|
+
init
|
95
|
+
end
|
96
|
+
path = Config.assets_path '../..', false
|
97
|
+
assert_equal '/', path
|
98
|
+
end
|
99
|
+
|
89
100
|
it "env helpers" do
|
90
101
|
Config.set :env, 'test'
|
91
102
|
assert_equal true, Config.test?
|
data/spec/controller_spec.rb
CHANGED
@@ -20,5 +20,19 @@ module Nyara
|
|
20
20
|
assert_equal nil, AChildController.controller_name
|
21
21
|
assert_equal 'll', AChildController.default_layout
|
22
22
|
end
|
23
|
+
|
24
|
+
context "argument validation" do
|
25
|
+
class DummyController < Controller
|
26
|
+
get '/' do
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "#redirect_to checks first parameter" do
|
31
|
+
c = DummyController.new Ext.request_new
|
32
|
+
assert_raise ArgumentError do
|
33
|
+
c.redirect_to '/'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
23
37
|
end
|
24
38
|
end
|
data/spec/evented_io_spec.rb
CHANGED
@@ -8,10 +8,12 @@ module Nyara
|
|
8
8
|
exec 'ruby', __dir__ + '/apps/connect.rb'
|
9
9
|
end
|
10
10
|
GC.stress = false
|
11
|
-
sleep
|
11
|
+
sleep 2.3 # wait for server startup
|
12
12
|
end
|
13
13
|
|
14
14
|
after :all do
|
15
|
+
Process.kill :TERM, @server
|
16
|
+
sleep 0.2
|
15
17
|
Process.kill :KILL, @server
|
16
18
|
end
|
17
19
|
|
data/spec/ext_route_spec.rb
CHANGED
@@ -23,17 +23,27 @@ module Nyara
|
|
23
23
|
@controller = 'stub2'
|
24
24
|
}
|
25
25
|
@e3 = Route.new{
|
26
|
+
@http_method = 'GET'
|
27
|
+
@scope = '/hello'
|
28
|
+
@prefix = '/hello'
|
29
|
+
@suffix = '(\d+)'
|
30
|
+
@id = :'#third'
|
31
|
+
@conv = [:to_i]
|
32
|
+
@controller = 'stub3'
|
33
|
+
}
|
34
|
+
@e4 = Route.new{
|
26
35
|
@http_method = 'GET'
|
27
36
|
@scope = '/a目录'
|
28
37
|
@prefix = '/a目录/'
|
29
38
|
@suffix = '(\d+)-(\d+)-(\d+)'
|
30
39
|
@id = :'#dir'
|
31
40
|
@conv = [:to_i, :to_i, :to_i]
|
32
|
-
@controller = '
|
41
|
+
@controller = 'stub4'
|
33
42
|
}
|
34
43
|
Ext.register_route @e1
|
35
44
|
Ext.register_route @e2
|
36
45
|
Ext.register_route @e3
|
46
|
+
Ext.register_route @e4
|
37
47
|
end
|
38
48
|
|
39
49
|
after :all do
|
@@ -42,11 +52,12 @@ module Nyara
|
|
42
52
|
|
43
53
|
it '#register_route sub-prefix optimization' do
|
44
54
|
rules = Ext.list_route['GET']
|
45
|
-
assert_equal
|
55
|
+
assert_equal 4, rules.size
|
46
56
|
|
47
57
|
assert_equal false, rules[0].first # first
|
48
58
|
assert_equal true, rules[1].first # is sub of prev
|
49
|
-
assert_equal
|
59
|
+
assert_equal true, rules[2].first # is sub of prev
|
60
|
+
assert_equal false, rules[3].first # not sub of prev
|
50
61
|
end
|
51
62
|
|
52
63
|
it '#lookup_route' do
|
@@ -55,11 +66,22 @@ module Nyara
|
|
55
66
|
assert_equal @e2.controller, cont
|
56
67
|
assert_equal [:'#second'], args
|
57
68
|
|
69
|
+
scope, cont, args = Ext.lookup_route 'GET', '/hello.js', nil
|
70
|
+
assert_equal @e2.scope, scope
|
71
|
+
assert_equal @e2.controller, cont
|
72
|
+
assert_equal [:'#second'], args
|
73
|
+
|
58
74
|
scope, cont, args = Ext.lookup_route 'GET', '/hello/3world', nil
|
59
75
|
assert_equal @e1.scope, scope
|
60
76
|
assert_equal @e1.controller, cont
|
61
77
|
assert_equal [:'#1', 3], args
|
62
78
|
|
79
|
+
# same prefix as @e2, but should not be affected by @e2
|
80
|
+
scope, cont, args = Ext.lookup_route 'GET', '/hello3', nil
|
81
|
+
assert_equal @e3.scope, scope
|
82
|
+
assert_equal @e3.controller, cont
|
83
|
+
assert_equal [:'#third', 3], args
|
84
|
+
|
63
85
|
scope, _ = Ext.lookup_route 'GET', '/world', nil
|
64
86
|
assert_equal nil, scope
|
65
87
|
|