nyara 0.1.pre.1 → 0.1.pre.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/changes +6 -0
- data/ext/hashes.c +0 -2
- data/lib/nyara.rb +1 -2
- data/lib/nyara/command.rb +57 -11
- data/lib/nyara/config.rb +16 -16
- data/lib/nyara/nyara.rb +32 -23
- data/lib/nyara/optional_templates/activerecord.yml.erb +26 -0
- data/lib/nyara/{templates/config/database.yml.tt → optional_templates/mongoid.yml.erb} +0 -0
- data/lib/nyara/route.rb +3 -4
- data/lib/nyara/templates/%gitignore% +4 -0
- data/lib/nyara/templates/Gemfile.tt +22 -3
- data/lib/nyara/templates/Linnerfile +17 -0
- data/lib/nyara/templates/Rakefile +2 -3
- data/lib/nyara/templates/app/assets/scripts/app.coffee +3 -1
- data/lib/nyara/templates/app/assets/styles/app.scss +3 -1
- data/lib/nyara/templates/app/controllers/application_controller.rb +1 -1
- data/lib/nyara/templates/app/controllers/home_controller.rb +5 -0
- data/lib/nyara/templates/app/views/home/index.%template_ext%.tt +29 -0
- data/lib/nyara/templates/app/views/layouts/application.%template_ext%.tt +25 -0
- data/lib/nyara/templates/config/application.rb.tt +54 -0
- data/lib/nyara/templates/config/boot.rb +0 -1
- data/lib/nyara/templates/config/development.rb +10 -1
- data/lib/nyara/templates/config/production.rb +4 -1
- data/lib/nyara/templates/config/test.rb +1 -0
- data/lib/nyara/view.rb +1 -6
- data/nyara.gemspec +2 -2
- data/spec/apps/reload.rb +2 -1
- data/spec/command_spec.rb +4 -4
- data/spec/config_spec.rb +0 -12
- data/spec/nyara_spec.rb +43 -0
- data/spec/path_helper_spec.rb +3 -3
- data/spec/view_spec.rb +4 -4
- data/tools/hello.rb +1 -1
- metadata +10 -9
- data/lib/nyara/templates/app/controllers/welcome_controller.rb +0 -5
- data/lib/nyara/templates/app/views/layouts/application.erb.tt +0 -12
- data/lib/nyara/templates/app/views/welcome/index.erb +0 -1
- data/lib/nyara/templates/config/application.rb +0 -38
- data/tools/bug.rb +0 -53
- data/tools/memcheck.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d7c361394cdca151e6d52acc2dcb4e1b197f1b3
|
4
|
+
data.tar.gz: ce33aa73e3be6a53efe0c4013f6bbe95463f88a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2450d6d927b7c4b2771dcfdd81c4491a51ab8373a425fa9dea2d0114cd08892306d97a681f973a90f294c79a14b4b0c6abcd931a0138993f88c361760eef0850
|
7
|
+
data.tar.gz: 70e46c7d7353bab07e8e26d3a4023023060dc9fbacc1ef660a2712f52267e73c4427be4c6f3a073f238b05bda64eb8ef5e05ecb1c2729a2eb8f7167558928cc1
|
data/changes
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
0.1
|
2
|
+
|
3
|
+
2013-08-19 project generator now support `--template` and `--orm` options
|
4
|
+
you can see available options with `nyara help new`
|
5
|
+
2013-08-17 remove config option `app_files`, add options `watch` and `watch_assets`
|
6
|
+
2013-08-17 use un-converted class names in `Config.map`
|
1
7
|
2013-08-17 integrate with linner
|
2
8
|
2013-08-16 use thor for `nyara` commands
|
3
9
|
2013-08-15 (developers) migrated to git subtree, you don't need to hand-update submodules anymore
|
data/ext/hashes.c
CHANGED
@@ -240,7 +240,6 @@ static VALUE param_hash_nested_aset(VALUE output, VALUE keys, VALUE value) {
|
|
240
240
|
}
|
241
241
|
|
242
242
|
// s, len is the raw kv string
|
243
|
-
// returns trailing length
|
244
243
|
static void _cookie_kv(VALUE output, const char* s, long len) {
|
245
244
|
// strip
|
246
245
|
for (; len > 0; len--, s++) {
|
@@ -291,7 +290,6 @@ static VALUE param_hash_parse_cookie(VALUE _, VALUE output, VALUE str) {
|
|
291
290
|
}
|
292
291
|
|
293
292
|
// s, len is the raw kv string
|
294
|
-
// returns trailing length
|
295
293
|
static void _param_kv(VALUE output, const char* s, long len) {
|
296
294
|
// strip
|
297
295
|
for (; len > 0; len--, s++) {
|
data/lib/nyara.rb
CHANGED
@@ -4,7 +4,6 @@ require_relative "nyara/nyara"
|
|
4
4
|
END {
|
5
5
|
if $!.nil? and !Nyara.config.test?
|
6
6
|
Nyara.setup
|
7
|
-
Nyara.load_app
|
8
7
|
Nyara.start_server
|
9
8
|
end
|
10
9
|
}
|
@@ -23,5 +22,5 @@ end
|
|
23
22
|
end
|
24
23
|
|
25
24
|
configure do
|
26
|
-
map '/', '
|
25
|
+
map '/', 'Nyara::SimpleController'
|
27
26
|
end
|
data/lib/nyara/command.rb
CHANGED
@@ -4,6 +4,26 @@ require "shellwords"
|
|
4
4
|
module Nyara
|
5
5
|
class Command < Thor
|
6
6
|
include Thor::Actions
|
7
|
+
|
8
|
+
module FileNames
|
9
|
+
def template_ext
|
10
|
+
options[:template] == 'slim' ? 'slim' : 'erb'
|
11
|
+
end
|
12
|
+
|
13
|
+
def gitignore
|
14
|
+
'.gitignore'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
include FileNames
|
18
|
+
|
19
|
+
module ORM
|
20
|
+
def orm
|
21
|
+
# it can be nil when called as method
|
22
|
+
options[:orm] || 'mongoid'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
include ORM
|
26
|
+
|
7
27
|
map '-v' => :version
|
8
28
|
|
9
29
|
def self.source_root
|
@@ -16,7 +36,10 @@ module Nyara
|
|
16
36
|
end
|
17
37
|
|
18
38
|
desc "new APP_NAME", "Create a project"
|
19
|
-
method_option :
|
39
|
+
method_option :orm, aliases: %w'-o -O', type: :string, default: 'mongoid',
|
40
|
+
desc: 'Specify object relationship mapping (ORM)', enum: %w'mongoid activerecord none'
|
41
|
+
method_option :template, aliases: %w'-t -T', type: :string, default: 'erubis',
|
42
|
+
desc: 'Specify template engine', enum: %w'erubis slim'
|
20
43
|
def new name
|
21
44
|
require 'fileutils'
|
22
45
|
|
@@ -25,13 +48,9 @@ module Nyara
|
|
25
48
|
@app_name = File.basename app_dir
|
26
49
|
templte_dir = File.join(File.dirname(__FILE__), "templates")
|
27
50
|
|
28
|
-
FileUtils.rm_rf(app_dir) if options[:force]
|
29
51
|
directory 'templates', name
|
30
|
-
|
31
|
-
create_file app_dir + '/.gitignore' do
|
32
|
-
%w".DS_Store config/session.key config/session_cipher.key".join "\n"
|
33
|
-
end
|
34
52
|
generate 'session.key'
|
53
|
+
generate 'database.yml'
|
35
54
|
puts ' \\ 👻 /'
|
36
55
|
ensure
|
37
56
|
@app_name = nil
|
@@ -40,7 +59,10 @@ module Nyara
|
|
40
59
|
|
41
60
|
desc "generate THING", "(PROJECT) Generate things, THING can be:
|
42
61
|
session.key # config/session.key
|
43
|
-
session_cipher.key # config/session_cipher.key
|
62
|
+
session_cipher.key # config/session_cipher.key
|
63
|
+
database.yml # config/database.yml"
|
64
|
+
method_option :orm, aliases: %w'-o -O', type: :string, default: 'mongoid',
|
65
|
+
desc: 'Specify ORM (for generating database.yml)', enum: %w'mongoid activerecord'
|
44
66
|
def generate thing, app_dir=nil
|
45
67
|
case thing
|
46
68
|
when 'session.key'
|
@@ -55,19 +77,42 @@ module Nyara
|
|
55
77
|
create_file file do
|
56
78
|
Session.generate_cipher_key
|
57
79
|
end
|
80
|
+
when 'database.yml'
|
81
|
+
@app_name ||= File.dirname Dir.pwd
|
82
|
+
file = 'config/database.yml'
|
83
|
+
file = File.join @rel_dir, file if @rel_dir
|
84
|
+
case orm
|
85
|
+
when 'mongoid', 'activerecord'
|
86
|
+
src = "#{__dir__}/optional_templates/#{orm}.yml.erb"
|
87
|
+
create_file file do
|
88
|
+
ERB.new(File.read src).result binding
|
89
|
+
end
|
90
|
+
end
|
58
91
|
end
|
59
92
|
end
|
60
93
|
|
61
94
|
desc "server", "(PROJECT) Start server"
|
62
95
|
method_option :environment, aliases: %w'-e -E', default: 'development'
|
96
|
+
method_option :port, aliases: %w'-p -P', type: :numeric
|
97
|
+
method_option :daemon, aliases: %w'-d -D', type: :boolean,
|
98
|
+
desc: 'run server on the background'
|
63
99
|
def server
|
64
100
|
env = options[:environment].shellescape
|
65
|
-
|
101
|
+
cmd = "NYARA_ENV=#{env} ruby config/boot.rb"
|
102
|
+
|
103
|
+
if options[:port]
|
104
|
+
cmd << " -p" << options[:port].shellescape
|
105
|
+
end
|
106
|
+
if options[:daemon]
|
107
|
+
cmd << " -d"
|
108
|
+
end
|
109
|
+
exec cmd
|
66
110
|
end
|
67
111
|
|
68
112
|
desc "console", "(PROJECT) Start console"
|
69
113
|
method_option :environment, aliases: %w'-e -E', default: 'development'
|
70
|
-
method_option :shell, aliases: '-s',
|
114
|
+
method_option :shell, aliases: %w'-s -S', enum: %w'pry irb',
|
115
|
+
desc: "Tell me which shell you want to use"
|
71
116
|
def console
|
72
117
|
env = options[:environment].shellescape
|
73
118
|
cmd = options[:shell]
|
@@ -76,11 +121,12 @@ module Nyara
|
|
76
121
|
cmd = 'pry'
|
77
122
|
end
|
78
123
|
end
|
124
|
+
|
79
125
|
cmd ||= 'irb'
|
80
126
|
if cmd != 'irb'
|
81
|
-
cmd = "bundle exec
|
127
|
+
cmd = "bundle exec pry"
|
82
128
|
end
|
83
|
-
exec "NYARA_ENV=#{env} #{cmd} -r./config/application.rb"
|
129
|
+
exec "NYARA_SHELL=1 NYARA_ENV=#{env} #{cmd} -r./config/application.rb"
|
84
130
|
end
|
85
131
|
|
86
132
|
end
|
data/lib/nyara/config.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
module Nyara
|
2
2
|
# #### Options
|
3
3
|
#
|
4
|
-
# * `env`
|
5
|
-
# * `port`
|
6
|
-
# * `
|
7
|
-
# * `
|
8
|
-
# * `
|
9
|
-
# * `
|
10
|
-
# * `
|
11
|
-
# * `public`
|
12
|
-
# * `x_send_file`
|
13
|
-
# * `session`
|
14
|
-
# * `prefer_erb`
|
15
|
-
# * `logger`
|
16
|
-
# * `
|
17
|
-
#
|
18
|
-
# * `
|
19
|
-
# * `
|
4
|
+
# * `env` - environment, default is `'development'`
|
5
|
+
# * `port` - listen port number, default is 3000. you can pass `-p` in the command line to override it
|
6
|
+
# * `daemon` - whether run in the background, default is false. you can pass `-d` in the command line to override it
|
7
|
+
# * `workers` - number of workers
|
8
|
+
# * `host` - host name used in `url_to` helper
|
9
|
+
# * `root` - root path, default is `Dir.pwd`
|
10
|
+
# * `views` - views (templates) directory, relative to root, default is `"views"`
|
11
|
+
# * `public` - static files directory, relative to root, default is `"public"`
|
12
|
+
# * `x_send_file` - header field name for `X-Sendfile` or `X-Accel-Redirect`, see [Nyara::Controller#send_file](Controller#send_file.html-instance_method) for details
|
13
|
+
# * `session` - see [Nyara::Session](Session.html) for sub options
|
14
|
+
# * `prefer_erb` - use ERB instead of ERubis for `.erb` templates
|
15
|
+
# * `logger` - if set, every request is logged, and you can use `Nyara.logger` to do your own logging.
|
16
|
+
# * `before_fork` - a proc to run before forking
|
17
|
+
# * `after_fork` - a proc to run after forking
|
18
|
+
# * `watch` - if `true`, watch `app` change and reload automaticly, useful for development. default is `false`
|
19
|
+
# * `watch_assets` - if `true`, watch `app/assets` change with linner (you need `gem install linner` first), useful for development. default is `false`
|
20
20
|
#
|
21
21
|
# #### logger example
|
22
22
|
#
|
data/lib/nyara/nyara.rb
CHANGED
@@ -76,25 +76,9 @@ module Nyara
|
|
76
76
|
View.init
|
77
77
|
end
|
78
78
|
|
79
|
-
# load with Config['app_files']
|
80
|
-
def load_app
|
81
|
-
app_files = Config['app_files']
|
82
|
-
return unless app_files
|
83
|
-
|
84
|
-
Dir.chdir Config.root do
|
85
|
-
# NOTE app_files can be an array
|
86
|
-
Dir.glob Config['app_files'] do |file|
|
87
|
-
require Config.project_path file
|
88
|
-
end
|
89
|
-
if Config.development?
|
90
|
-
require_relative "reload"
|
91
|
-
Reload.listen
|
92
|
-
@reload = Reload
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
79
|
def start_server
|
80
|
+
reconfig_with_command_line_options
|
81
|
+
Process.daemon if Config['daemon']
|
98
82
|
port = Config['port']
|
99
83
|
env = Config['env']
|
100
84
|
|
@@ -107,15 +91,21 @@ module Nyara
|
|
107
91
|
when 'test'
|
108
92
|
# don't
|
109
93
|
else
|
110
|
-
|
94
|
+
start_watch
|
111
95
|
start_development_server port
|
112
96
|
end
|
113
97
|
end
|
114
98
|
|
115
|
-
def
|
116
|
-
|
117
|
-
|
118
|
-
|
99
|
+
def start_watch
|
100
|
+
if Config['watch_assets']
|
101
|
+
Process.fork do
|
102
|
+
exec 'bundle exec linner watch'
|
103
|
+
end
|
104
|
+
end
|
105
|
+
if Config['watch']
|
106
|
+
require_relative "reload"
|
107
|
+
Reload.listen
|
108
|
+
@reload = Reload
|
119
109
|
end
|
120
110
|
end
|
121
111
|
|
@@ -192,6 +182,25 @@ module Nyara
|
|
192
182
|
|
193
183
|
private
|
194
184
|
|
185
|
+
def reconfig_with_command_line_options argv=ARGV.dup
|
186
|
+
until argv.empty?
|
187
|
+
case opt = argv.shift
|
188
|
+
when '-d', '--daemon'
|
189
|
+
Config['daemon'] = true
|
190
|
+
when '-p', /--port(?:=(\d+))?/
|
191
|
+
port = ($1 || argv.shift)
|
192
|
+
port = port.to_i if port
|
193
|
+
if port >= 0 && port <= 65535
|
194
|
+
Config['port'] = port
|
195
|
+
else
|
196
|
+
raise "invalid port: #{port.inspect}"
|
197
|
+
end
|
198
|
+
else
|
199
|
+
raise "unkown command line option: #{opt}"
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
195
204
|
def create_tcp_server port
|
196
205
|
if (server_fd = ENV['NYARA_FD'].to_i) > 0
|
197
206
|
puts "inheriting server fd #{server_fd}"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# for other databases, see
|
2
|
+
# http://guides.rubyonrails.org/configuring.html#configuring-a-database
|
3
|
+
|
4
|
+
defaults: &defaults
|
5
|
+
adapter: postgresql
|
6
|
+
encoding: unicode
|
7
|
+
username: postgres
|
8
|
+
## mysql/mariadb example:
|
9
|
+
# adapter: mysql2
|
10
|
+
# encoding: utf8
|
11
|
+
# username: root
|
12
|
+
password:
|
13
|
+
pool: 5
|
14
|
+
host: localhost
|
15
|
+
|
16
|
+
development:
|
17
|
+
<<: *defaults
|
18
|
+
database: <%= @app_name %>_dev
|
19
|
+
|
20
|
+
test:
|
21
|
+
<<: *defaults
|
22
|
+
database: <%= @app_name %>_test
|
23
|
+
|
24
|
+
production:
|
25
|
+
<<: *defaults
|
26
|
+
database: <%= @app_name %>_prod
|
File without changes
|
data/lib/nyara/route.rb
CHANGED
@@ -167,7 +167,7 @@ module Nyara
|
|
167
167
|
def routes
|
168
168
|
@routes || []
|
169
169
|
end
|
170
|
-
|
170
|
+
|
171
171
|
# #### Param
|
172
172
|
#
|
173
173
|
# * `controller` - string or class which inherits [Nyara::Controller](Controller.html)
|
@@ -240,9 +240,7 @@ module Nyara
|
|
240
240
|
def print_routes
|
241
241
|
puts "All routes:"
|
242
242
|
Nyara::Route.routes.each do |route|
|
243
|
-
cname = route.controller
|
244
|
-
cname.gsub!("Controller", "")
|
245
|
-
cname.downcase!
|
243
|
+
cname = const2name route.controller
|
246
244
|
print "#{cname}#{route.id}".rjust(30), " "
|
247
245
|
print route.http_method_to_s.ljust(6), " "
|
248
246
|
print route.path_template
|
@@ -260,6 +258,7 @@ module Nyara
|
|
260
258
|
end
|
261
259
|
|
262
260
|
def name2const name
|
261
|
+
return Module.const_get(name) if name[0] =~ /[A-Z]/
|
263
262
|
name = name.gsub /(?<=\b|_)[a-z]/, &:upcase
|
264
263
|
name.gsub! '_', ''
|
265
264
|
name << 'Controller'
|
@@ -1,11 +1,30 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
|
3
|
+
# web framework
|
4
4
|
gem 'nyara', '<%= Nyara::VERSION %>', require: 'nyara/nyara'
|
5
|
-
|
5
|
+
|
6
|
+
# template engine
|
7
|
+
<%- if template_ext == 'erb' -%>
|
8
|
+
gem 'erubis'
|
9
|
+
<%- else -%>
|
10
|
+
gem 'slim'
|
11
|
+
<%- end -%>
|
12
|
+
|
13
|
+
<%- case orm -%>
|
14
|
+
<%- when 'mongoid' -%>
|
15
|
+
# orm
|
16
|
+
gem 'mongoid', '~> 3.1.4'
|
17
|
+
<%- when 'activerecord' -%>
|
18
|
+
# orm
|
19
|
+
gem 'activerecord', '~> 4.0.0'
|
20
|
+
|
21
|
+
# database driver
|
22
|
+
gem 'pg'
|
23
|
+
# gem 'mysql2'
|
24
|
+
<%- end -%>
|
6
25
|
|
7
26
|
group :development do
|
8
|
-
gem 'linner', github: "SaitoWu/linner"
|
27
|
+
gem 'linner', github: "SaitoWu/linner", require: false
|
9
28
|
end
|
10
29
|
|
11
30
|
group :deploy do
|
@@ -1,28 +1,45 @@
|
|
1
|
+
# -*- mode: yaml -*-
|
2
|
+
# vim: set syntax=yaml:
|
1
3
|
paths:
|
4
|
+
# source
|
2
5
|
app: "app/assets"
|
6
|
+
# destination
|
3
7
|
public: "public"
|
8
|
+
|
4
9
|
groups:
|
10
|
+
# js src
|
5
11
|
scripts:
|
12
|
+
# load paths for require("some-module")
|
6
13
|
paths:
|
7
14
|
- app/assets/scripts
|
15
|
+
# assemble k with v
|
8
16
|
concat:
|
9
17
|
"/assets/app.js": "app/assets/**/*.{js,coffee}"
|
18
|
+
# manage js module dependencies by specifying the concat order
|
10
19
|
order:
|
20
|
+
# "..." means any other files
|
11
21
|
- "..."
|
12
22
|
- app/assets/scripts/app.coffee
|
23
|
+
|
24
|
+
# css src
|
13
25
|
styles:
|
26
|
+
# load paths for @import "some-module"
|
14
27
|
paths:
|
15
28
|
- app/assets/styles
|
16
29
|
concat:
|
17
30
|
"/assets/app.css": "app/assets/**/[a-z]*.{css,scss,sass}"
|
31
|
+
|
32
|
+
# files to copy directly into `public`
|
18
33
|
files:
|
19
34
|
paths:
|
20
35
|
- app/assets/files
|
21
36
|
copy:
|
22
37
|
"/": "app/assets/**/*.{ico,txt}"
|
38
|
+
|
23
39
|
modules:
|
24
40
|
wrapper: "cmd"
|
25
41
|
ignored: "{vendor/**/*,app/assets/scripts/app.{js,coffee}}"
|
26
42
|
definition: "/assets/app.js"
|
43
|
+
|
27
44
|
revision: true
|
28
45
|
notification: true
|
@@ -3,17 +3,16 @@ require "rake"
|
|
3
3
|
desc "print all routes"
|
4
4
|
task :routes do
|
5
5
|
require_relative "config/application"
|
6
|
-
Nyara.setup
|
7
6
|
Nyara::Route.print_routes
|
8
7
|
end
|
9
8
|
|
10
9
|
namespace :assets do
|
11
|
-
desc "compile assets into public"
|
10
|
+
desc "compile assets into public (requires linner)"
|
12
11
|
task :build do
|
13
12
|
sh 'bundle exec linner build'
|
14
13
|
end
|
15
14
|
|
16
|
-
desc "clean assets in public"
|
15
|
+
desc "clean assets in public (requires linner)"
|
17
16
|
task :clean do
|
18
17
|
sh 'bundle exec linner clean'
|
19
18
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# coffeescript reference -- http://coffeescript.org
|
2
|
+
|
3
|
+
# linner lets you organize script assets more easily
|
2
4
|
# see module-example.coffee for how to define a module
|
3
5
|
module = require 'module-example'
|
4
6
|
module.bounce()
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<% if template_ext == 'erb' -%>
|
2
|
+
<h1>Congratulations!<h1>
|
3
|
+
<h2>You completed the first step of creating an awesome website!</h2>
|
4
|
+
|
5
|
+
You may also like to:
|
6
|
+
|
7
|
+
<ul>
|
8
|
+
<li><a href="https://github.com/luikore/nyara/wiki/Manual#configure-options">Learn more about nyara</a></li>
|
9
|
+
<li><a href="http://slim-lang.com/">Switch template engine to slim</a></li>
|
10
|
+
<li><a href="https://github.com/SaitoWu/linner">See how assets work</a></li>
|
11
|
+
<li><a href="https://chrome.google.com/webstore/detail/livereload/jnihajbhpnppcggbcgedagnkighmdlei?hl=en">Install the livereload plugin on Chrome</a></li>
|
12
|
+
</ul>
|
13
|
+
<% else -%>
|
14
|
+
h1 Congratulations!
|
15
|
+
h2 You completed the first step of creating an awesome website!
|
16
|
+
|
17
|
+
| You may also like to:
|
18
|
+
|
19
|
+
ul
|
20
|
+
li
|
21
|
+
a href="https://github.com/luikore/nyara/wiki/Manual#configure-options"
|
22
|
+
| Learn more about nyara
|
23
|
+
li
|
24
|
+
a href="https://github.com/SaitoWu/linner"
|
25
|
+
| See how assets work
|
26
|
+
li
|
27
|
+
a href="https://chrome.google.com/webstore/detail/livereload/jnihajbhpnppcggbcgedagnkighmdlei?hl=en"
|
28
|
+
| Install the livereload plugin on Chrome
|
29
|
+
<% end -%>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<% if template_ext == 'erb' -%>
|
2
|
+
<!DOCTYPE html>
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
6
|
+
<title><%= @app_name %></title>
|
7
|
+
<link type="text/css" rel="stylesheet" href="<%%= asset_path "/assets/app.css" %>">
|
8
|
+
<script type="text/javascript" src="<%%= asset_path "/assets/app.js" %>"></script>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
<%%== yield %>
|
12
|
+
</body>
|
13
|
+
</html>
|
14
|
+
<% else -%>
|
15
|
+
doctype html
|
16
|
+
html
|
17
|
+
head
|
18
|
+
meta http-equiv="Content-type" content="text/html; charset=utf-8"
|
19
|
+
title
|
20
|
+
| <%= @app_name %>
|
21
|
+
link type="text/css" rel="stylesheet" href=asset_path("/assets/app.css")
|
22
|
+
script type="text/javascript" src=asset_path("/assets/app.js")
|
23
|
+
body
|
24
|
+
== yield
|
25
|
+
<% end -%>
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler.require :default, ENV['NYARA_ENV'] || 'development'
|
3
|
+
|
4
|
+
configure do
|
5
|
+
set :env, ENV['NYARA_ENV'] || 'development'
|
6
|
+
|
7
|
+
set :port, ENV['NYARA_PORT']
|
8
|
+
|
9
|
+
# directory containing view templates
|
10
|
+
set :views, 'app/views'
|
11
|
+
|
12
|
+
## change cookie based session name
|
13
|
+
# set :session, :name, '_aaa'
|
14
|
+
|
15
|
+
## if you've configured https with nginx:
|
16
|
+
# set :session, :secure, true
|
17
|
+
|
18
|
+
## default session expires when browser closes.
|
19
|
+
## if you need time-based expiration, 30 minutes for example:
|
20
|
+
# set :session, :expires, 30 * 60
|
21
|
+
|
22
|
+
# you can regenerate session key with `nyara g session.key`
|
23
|
+
set 'session', 'key', File.read(project_path 'config/session.key')
|
24
|
+
|
25
|
+
# map routing prefix to controllers
|
26
|
+
map '/', 'HomeController'
|
27
|
+
|
28
|
+
# environment specific configure at last
|
29
|
+
require_relative env
|
30
|
+
|
31
|
+
# invoked after forking a worker
|
32
|
+
set :after_fork, ->{
|
33
|
+
<%- case orm -%>
|
34
|
+
<%- when 'mongoid' -%>
|
35
|
+
Mongoid.load!(Nyara.config.project_path('config/database.yml'), Nyara.config.env)
|
36
|
+
<%- when 'activerecord' -%>
|
37
|
+
ActiveRecord::Base.establish_connection Nyara.config.project_path('config/database.yml')
|
38
|
+
<%- end -%>
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
# load app
|
43
|
+
Dir.glob %w|
|
44
|
+
app/controllers/application_controller.rb
|
45
|
+
app/{helpers,models,controllers}/**/*.rb
|
46
|
+
| do |file|
|
47
|
+
require_relative "../#{file}"
|
48
|
+
end
|
49
|
+
|
50
|
+
# compile routes and finish misc setup stuffs
|
51
|
+
Nyara.setup
|
52
|
+
|
53
|
+
# connect db in interactive shell
|
54
|
+
Nyara.config[:after_fork].call if ENV['NYARA_SHELL']
|
@@ -1,5 +1,14 @@
|
|
1
|
+
# config specific to development environment
|
1
2
|
configure do
|
2
|
-
|
3
|
+
# enable Nyara.logger
|
3
4
|
set :logger, true
|
5
|
+
|
6
|
+
# serve static files in public
|
4
7
|
set :public, 'public'
|
8
|
+
|
9
|
+
# auto reload app
|
10
|
+
set :watch, true
|
11
|
+
|
12
|
+
# auto re-compile assets
|
13
|
+
set :watch_assets, true
|
5
14
|
end
|
@@ -1,9 +1,12 @@
|
|
1
|
+
# config specific to production environment
|
1
2
|
configure do
|
2
|
-
set :port, 3000
|
3
3
|
## worker number can be detected by CPU count
|
4
4
|
# set :workers, 4
|
5
|
+
|
6
|
+
# enable Nyara.logger
|
5
7
|
set :logger, true
|
6
8
|
|
9
|
+
# assets manifest is generated by `rake assets:build`
|
7
10
|
set :manifest, (YAML.load_file Nyara.project_path 'public/manifest.yml')
|
8
11
|
|
9
12
|
# todo after_fork
|
data/lib/nyara/view.rb
CHANGED
@@ -209,7 +209,6 @@ module Nyara
|
|
209
209
|
#
|
210
210
|
# `[meth_obj, ext_without_dot]`
|
211
211
|
def template path, locals={}
|
212
|
-
raw_path = path
|
213
212
|
if File.extname(path).empty?
|
214
213
|
Dir.chdir @root do
|
215
214
|
paths = Dir.glob("#{path}.{#@ext_list}")
|
@@ -220,16 +219,12 @@ module Nyara
|
|
220
219
|
end
|
221
220
|
end
|
222
221
|
|
223
|
-
if path.blank?
|
224
|
-
raise ArgumentError, "template '#{raw_path}' file not found in view dir."
|
225
|
-
end
|
226
|
-
|
227
222
|
meth = path2meth path
|
228
223
|
ext = @meth2ext[meth]
|
229
224
|
return [RENDER[meth], ext] if ext
|
230
225
|
|
231
226
|
@meth2sig[meth] = locals.keys
|
232
|
-
ext = on_modified path
|
227
|
+
ext = on_modified path if path
|
233
228
|
raise "template not found or not valid in Tilt: #{path}" unless ext
|
234
229
|
[RENDER[meth], ext]
|
235
230
|
end
|
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.2"
|
4
4
|
s.author = "Zete Lui"
|
5
5
|
s.email = "nobody@example.com"
|
6
6
|
s.homepage = "https://github.com/luikore/nyara"
|
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.files += Dir.glob('spec/**/*')
|
15
15
|
s.files += Dir.glob('ext/http-parser/{AUTHORS,CONTRIBUTIONS,LICENSE-MIT}')
|
16
16
|
s.files += Dir.glob('ext/multipart-parser-c/README.md')
|
17
|
-
s.files += Dir.glob('lib/nyara/templates/**/*') - %w[.DS_Store]
|
17
|
+
s.files += Dir.glob('lib/nyara/{optional_templates,templates}/**/*') - %w[.DS_Store]
|
18
18
|
s.files.uniq!
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
s.executables << 'nyara'
|
data/spec/apps/reload.rb
CHANGED
data/spec/command_spec.rb
CHANGED
@@ -32,7 +32,7 @@ module Nyara
|
|
32
32
|
Dir.chdir @tmp_dir do
|
33
33
|
@stdout = capture(:stdout) do
|
34
34
|
@command = Command.new
|
35
|
-
@command.new
|
35
|
+
@command.new @app_name
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -47,15 +47,15 @@ module Nyara
|
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should copy same files into new dir" do
|
50
|
-
des_files = filter_files Dir.glob(File.join @tmp_dir, @app_name, "
|
50
|
+
des_files = filter_files Dir.glob(File.join @tmp_dir, @app_name, "**/{*,.*}")
|
51
51
|
assert_not_equal(des_files.count, 0)
|
52
|
-
src_files = filter_files Dir.glob("#{@old_dir}/lib/nyara/templates
|
52
|
+
src_files = filter_files Dir.glob("#{@old_dir}/lib/nyara/templates/**/{*,.*}")
|
53
53
|
assert_equal(des_files.count, src_files.count)
|
54
54
|
end
|
55
55
|
|
56
56
|
def filter_files files
|
57
57
|
files.select do |f|
|
58
|
-
File.basename
|
58
|
+
!(%w[.DS_Store session.key database.yml].include? File.basename f)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
data/spec/config_spec.rb
CHANGED
@@ -128,17 +128,5 @@ module Nyara
|
|
128
128
|
Config.init
|
129
129
|
assert_nil Nyara.logger
|
130
130
|
end
|
131
|
-
|
132
|
-
it "auto load file" do
|
133
|
-
Config.configure do
|
134
|
-
set :env, 'test'
|
135
|
-
set :root, File.join(__dir__, 'dummy')
|
136
|
-
set :app_files, 'app/**/*.rb'
|
137
|
-
end
|
138
|
-
Config.init
|
139
|
-
Nyara.load_app
|
140
|
-
assert_equal true, Object.const_defined?('DummyModel')
|
141
|
-
assert_equal true, Object.const_defined?('DummyController')
|
142
|
-
end
|
143
131
|
end
|
144
132
|
end
|
data/spec/nyara_spec.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
describe Nyara do
|
4
|
+
context ".reconfig_with_command_line_options" do
|
5
|
+
before :each do
|
6
|
+
Nyara.config.reset
|
7
|
+
end
|
8
|
+
|
9
|
+
def config cmd_opts
|
10
|
+
Nyara.send :reconfig_with_command_line_options, cmd_opts
|
11
|
+
end
|
12
|
+
|
13
|
+
it "works" do
|
14
|
+
config %w'-p 1234 -d'
|
15
|
+
assert_equal 1234, Nyara.config['port']
|
16
|
+
assert_equal true, Nyara.config['daemon']
|
17
|
+
end
|
18
|
+
|
19
|
+
it "works without -d" do
|
20
|
+
config %w'-p 100'
|
21
|
+
assert_equal 100, Nyara.config['port']
|
22
|
+
assert_equal true, !Nyara.config['daemon']
|
23
|
+
end
|
24
|
+
|
25
|
+
it "raises for bad options" do
|
26
|
+
assert_raise RuntimeError do
|
27
|
+
config %w'xx'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "recognizes --daemon and --port" do
|
32
|
+
config %w'--port=1245 --daemon'
|
33
|
+
assert_equal 1245, Nyara.config['port']
|
34
|
+
assert_equal true, Nyara.config['daemon']
|
35
|
+
end
|
36
|
+
|
37
|
+
it "raises for bad port" do
|
38
|
+
assert_raise RuntimeError do
|
39
|
+
config %w'--port 100000'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/spec/path_helper_spec.rb
CHANGED
@@ -30,9 +30,9 @@ module Nyara
|
|
30
30
|
Config.configure do
|
31
31
|
reset
|
32
32
|
set 'host', 'yavaeye.com'
|
33
|
-
map '/', '
|
34
|
-
map '/bar-prefix', '
|
35
|
-
map '/baz-prefix', '
|
33
|
+
map '/', 'FooController'
|
34
|
+
map '/bar-prefix', 'FooController::BarController'
|
35
|
+
map '/baz-prefix', 'FooController::BazController'
|
36
36
|
end
|
37
37
|
Nyara.setup
|
38
38
|
end
|
data/spec/view_spec.rb
CHANGED
@@ -47,16 +47,16 @@ module Nyara
|
|
47
47
|
assert_raise ArgumentError do
|
48
48
|
render 'edit', nil, nil, {}
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
render 'edit.slim', nil, nil, {}
|
52
52
|
assert_equal "<div>slim:edit</div>", @instance.result.gsub(/\s/, '')
|
53
53
|
render 'edit.haml', nil, nil, {}
|
54
54
|
assert_equal "<div>haml:edit</div>", @instance.result.gsub(/\s/, '')
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
it "raises error with template not found" do
|
58
|
-
assert_raise
|
59
|
-
render '
|
58
|
+
assert_raise RuntimeError do
|
59
|
+
render 'not-exist-template', nil, nil, {}
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
data/tools/hello.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nyara
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.pre.
|
4
|
+
version: 0.1.pre.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zete Lui
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tilt
|
@@ -94,8 +94,7 @@ files:
|
|
94
94
|
- lib/nyara/route.rb
|
95
95
|
- lib/nyara/session.rb
|
96
96
|
- lib/nyara/templates/app/controllers/application_controller.rb
|
97
|
-
- lib/nyara/templates/app/controllers/
|
98
|
-
- lib/nyara/templates/config/application.rb
|
97
|
+
- lib/nyara/templates/app/controllers/home_controller.rb
|
99
98
|
- lib/nyara/templates/config/boot.rb
|
100
99
|
- lib/nyara/templates/config/development.rb
|
101
100
|
- lib/nyara/templates/config/production.rb
|
@@ -125,6 +124,7 @@ files:
|
|
125
124
|
- spec/integration_spec.rb
|
126
125
|
- spec/mini_support_spec.rb
|
127
126
|
- spec/multipart_spec.rb
|
127
|
+
- spec/nyara_spec.rb
|
128
128
|
- spec/path_helper_spec.rb
|
129
129
|
- spec/performance/escape.rb
|
130
130
|
- spec/performance/layout_render.rb
|
@@ -140,9 +140,7 @@ files:
|
|
140
140
|
- spec/spec_helper.rb
|
141
141
|
- spec/url_encoded_spec.rb
|
142
142
|
- spec/view_spec.rb
|
143
|
-
- tools/bug.rb
|
144
143
|
- tools/hello.rb
|
145
|
-
- tools/memcheck.rb
|
146
144
|
- ext/http-parser/http_parser.h
|
147
145
|
- ext/inc/ary_intern.h
|
148
146
|
- ext/inc/epoll.h
|
@@ -191,14 +189,17 @@ files:
|
|
191
189
|
- ext/http-parser/CONTRIBUTIONS
|
192
190
|
- ext/http-parser/LICENSE-MIT
|
193
191
|
- ext/multipart-parser-c/README.md
|
192
|
+
- lib/nyara/optional_templates/activerecord.yml.erb
|
193
|
+
- lib/nyara/optional_templates/mongoid.yml.erb
|
194
|
+
- lib/nyara/templates/%gitignore%
|
194
195
|
- lib/nyara/templates/app/assets/files/favicon.ico
|
195
196
|
- lib/nyara/templates/app/assets/files/robots.txt
|
196
197
|
- lib/nyara/templates/app/assets/scripts/app.coffee
|
197
198
|
- lib/nyara/templates/app/assets/scripts/module-example.coffee
|
198
199
|
- lib/nyara/templates/app/assets/styles/app.scss
|
199
|
-
- lib/nyara/templates/app/views/
|
200
|
-
- lib/nyara/templates/app/views/
|
201
|
-
- lib/nyara/templates/config/
|
200
|
+
- lib/nyara/templates/app/views/home/index.%template_ext%.tt
|
201
|
+
- lib/nyara/templates/app/views/layouts/application.%template_ext%.tt
|
202
|
+
- lib/nyara/templates/config/application.rb.tt
|
202
203
|
- lib/nyara/templates/Gemfile.tt
|
203
204
|
- lib/nyara/templates/Linnerfile
|
204
205
|
- lib/nyara/templates/Rakefile
|
@@ -1,12 +0,0 @@
|
|
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>
|
@@ -1 +0,0 @@
|
|
1
|
-
Welcome to use Nyara.
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'bundler'
|
2
|
-
Bundler.require :default, ENV['NYARA_ENV'] || 'development'
|
3
|
-
|
4
|
-
configure do
|
5
|
-
set :env, ENV['NYARA_ENV'] || 'development'
|
6
|
-
|
7
|
-
set :views, 'app/views'
|
8
|
-
|
9
|
-
set :assets, "app/assets"
|
10
|
-
|
11
|
-
set :session, :name, '_aaa'
|
12
|
-
|
13
|
-
## If you've configured https with nginx:
|
14
|
-
# set :session, :secure, true
|
15
|
-
|
16
|
-
## Default session expires when browser closes.
|
17
|
-
## If you need time-based expiration, 30 minutes for example:
|
18
|
-
# set :session, :expires, 30 * 60
|
19
|
-
|
20
|
-
set 'session', 'key', File.read(project_path 'config/session.key')
|
21
|
-
|
22
|
-
# Routing
|
23
|
-
map '/', 'welcome'
|
24
|
-
|
25
|
-
# Application loading order
|
26
|
-
set :app_files, %w|
|
27
|
-
app/controllers/application_controller.rb
|
28
|
-
app/{helpers,models,controllers}/**/*.rb
|
29
|
-
|
|
30
|
-
|
31
|
-
# Environment specific configure at last
|
32
|
-
require_relative env
|
33
|
-
end
|
34
|
-
|
35
|
-
# Configure Mongoid
|
36
|
-
Mongoid.load!(Nyara.config.project_path('config/database.yml'), Nyara.config.env)
|
37
|
-
|
38
|
-
Nyara.load_app
|
data/tools/bug.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
require_relative "../lib/nyara/nyara"
|
2
|
-
|
3
|
-
configure do
|
4
|
-
map '/posts', 'posts'
|
5
|
-
end
|
6
|
-
|
7
|
-
class ApplicationController < Nyara::Controller
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
class PostsController < ApplicationController
|
12
|
-
meta '#index'
|
13
|
-
get '/' do
|
14
|
-
send_string 'index'
|
15
|
-
end
|
16
|
-
|
17
|
-
meta '#show'
|
18
|
-
get '/%u' do |id|
|
19
|
-
@post = Post.find(id)
|
20
|
-
render "posts/show"
|
21
|
-
end
|
22
|
-
|
23
|
-
meta '#new'
|
24
|
-
get '/new' do
|
25
|
-
@post = Post.new
|
26
|
-
render "posts/new"
|
27
|
-
end
|
28
|
-
|
29
|
-
meta '#create'
|
30
|
-
post '/' do
|
31
|
-
@post = Post.new(params[:post])
|
32
|
-
if @post.save
|
33
|
-
success "Post created."
|
34
|
-
redirect_to 'posts#show', @post.id
|
35
|
-
else
|
36
|
-
render "posts/new"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
meta '#edit'
|
41
|
-
get '/%u/edit' do
|
42
|
-
@post = Post.find(id)
|
43
|
-
render 'posts/edit'
|
44
|
-
end
|
45
|
-
|
46
|
-
meta '#update'
|
47
|
-
post '/%u' do |id|
|
48
|
-
@post = Post.find(id)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
Nyara.setup
|
53
|
-
Nyara.start_server
|
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
|