ki 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile.lock +1 -1
- data/README.md +18 -2
- data/Rakefile +8 -0
- data/bin/ki +1 -1
- data/lib/ki/api_error.rb +15 -7
- data/lib/ki/base_request.rb +1 -1
- data/lib/ki/helpers.rb +10 -1
- data/lib/ki/ki_cli.rb +53 -32
- data/lib/ki/middleware.rb +14 -9
- data/lib/ki/modules/callbacks.rb +22 -20
- data/lib/ki/modules/format_of.rb +10 -6
- data/lib/ki/modules/model_helpers.rb +26 -24
- data/lib/ki/modules/public_file_helper.rb +12 -8
- data/lib/ki/modules/query_interface.rb +28 -26
- data/lib/ki/modules/restrictions.rb +34 -32
- data/lib/ki/modules/view_helper.rb +12 -8
- data/lib/ki/orm.rb +125 -2
- data/lib/ki/version.rb +1 -1
- data/spec/examples/base/.ruby-version +1 -1
- data/spec/examples/base/Gemfile +1 -2
- data/spec/examples/couch-lock/Gemfile +0 -1
- data/spec/examples/couch-lock/app.rb +52 -0
- data/spec/examples/couch-lock/public/doorbell-1.wav +0 -0
- data/spec/examples/couch-lock/public/fonts/glyphicons-halflings-regular.eot +0 -0
- data/spec/examples/couch-lock/public/fonts/glyphicons-halflings-regular.svg +229 -0
- data/spec/examples/couch-lock/public/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/spec/examples/couch-lock/public/fonts/glyphicons-halflings-regular.woff +0 -0
- data/spec/examples/couch-lock/public/javascripts/angular.min.js +247 -0
- data/spec/examples/couch-lock/public/javascripts/clApp.coffee +68 -0
- data/spec/examples/couch-lock/public/stylesheets/bootstrap-theme.min.css +5 -0
- data/spec/examples/couch-lock/public/stylesheets/bootstrap.min.css +5 -0
- data/spec/examples/couch-lock/public/stylesheets/main.sass +29 -0
- data/spec/examples/couch-lock/views/index.haml +57 -57
- data/spec/examples/couch-lock/views/layout.haml +25 -0
- data/spec/examples/couch-lock/views/settings.haml +26 -0
- data/spec/examples/couch-lock/views/shop.haml +23 -0
- data/spec/examples/couch-lock/views/wiki.haml +6 -0
- data/spec/examples/json.northpole.ro/Gemfile.lock +1 -1
- data/spec/examples/todo/.ruby-version +1 -1
- data/spec/examples/todo/Gemfile +0 -1
- data/spec/lib/ki/model_spec.rb +1 -1
- data/spec/lib/ki/modules/format_of_spec.rb +2 -2
- metadata +29 -7
- data/spec/examples/couch-lock/Gemfile.lock +0 -48
- data/spec/examples/couch-lock/public/stylesheets/pure-min.css +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 848983c889362ba630e00014d4b670342d59ac68
|
4
|
+
data.tar.gz: a34e3829a0b471ba4f2cf3e31c7c3f0ba1a82231
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4c33d21423505f78dd4d20afa6bae4e8c42c6dafd79325290384db94f53162d346c6087c9b3e8fa4dace49dfa13f4be41c70b6e24cc6116bb5d1756e89c2117
|
7
|
+
data.tar.gz: 4c7442a2117142f8cd45a8e1c690ec6f7d42b7d7bc10cb0d96b71c8ca1fb2a6b891b12c6459f04dbb3ccb9e8c3b79e18faf94e1fbacd50d942b0b4b611a1283e
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -72,10 +72,11 @@ Views are in the *views* folder and you can find some database info in
|
|
72
72
|
```shell
|
73
73
|
cd todo
|
74
74
|
bundle
|
75
|
-
|
75
|
+
ki server
|
76
76
|
```
|
77
77
|
|
78
|
-
*
|
78
|
+
*ki server* is the command which starts the webserver. By default it starts on
|
79
|
+
port 1337.
|
79
80
|
|
80
81
|
### Adding a view
|
81
82
|
|
@@ -270,3 +271,18 @@ nginx, thin, apache, webrick).
|
|
270
271
|
|
271
272
|
In the webserver config, just remember to point the virtual host to the
|
272
273
|
*public* directory.
|
274
|
+
|
275
|
+
### Heroku deployment
|
276
|
+
|
277
|
+
```shell
|
278
|
+
ki new heroku-ki
|
279
|
+
cd heroku-ki
|
280
|
+
bundle
|
281
|
+
git init
|
282
|
+
git add .
|
283
|
+
git commit -m 'initial commit'
|
284
|
+
heroku create
|
285
|
+
heroku config:set MONGODB_URI="mongodb://user:pass@mongo_url:mongo_port/db_name"
|
286
|
+
git push heroku master
|
287
|
+
heroku open
|
288
|
+
```
|
data/Rakefile
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
2
|
require 'rspec/core/rake_task'
|
3
|
+
require 'rdoc/task'
|
4
|
+
|
5
|
+
RDoc::Task.new do |rdoc|
|
6
|
+
rdoc.main = "README.md"
|
7
|
+
rdoc.rdoc_files.
|
8
|
+
include("README.md", "lib/**/*.rb")
|
9
|
+
rdoc.rdoc_dir = 'doc'
|
10
|
+
end
|
3
11
|
|
4
12
|
RSpec::Core::RakeTask.new(:spec)
|
5
13
|
|
data/bin/ki
CHANGED
data/lib/ki/api_error.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Ki
|
2
|
-
class ApiError < StandardError
|
2
|
+
class ApiError < StandardError #:nodoc:
|
3
3
|
attr_reader :status
|
4
4
|
|
5
5
|
def initialize body, status=400
|
@@ -12,20 +12,28 @@ module Ki
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
class InvalidUrlError < ApiError
|
16
|
-
|
17
|
-
|
18
|
-
class
|
15
|
+
class InvalidUrlError < ApiError #:nodoc:
|
16
|
+
end
|
17
|
+
|
18
|
+
class RequiredAttributeMissing < ApiError #:nodoc:
|
19
|
+
end
|
20
|
+
|
21
|
+
class AttributeNotUnique < ApiError #:nodoc:
|
22
|
+
end
|
23
|
+
|
24
|
+
class ForbiddenAction < ApiError #:nodoc:
|
19
25
|
def initialize s='forbidden', code=403
|
20
26
|
super s, code
|
21
27
|
end
|
22
28
|
end
|
23
|
-
|
29
|
+
|
30
|
+
class UnauthorizedError < ApiError #:nodoc:
|
24
31
|
def initialize s='unauthroized', code=401
|
25
32
|
super s, code
|
26
33
|
end
|
27
34
|
end
|
28
|
-
|
35
|
+
|
36
|
+
class PartialNotFoundError < ApiError #:nodoc:
|
29
37
|
def initialize s
|
30
38
|
super "partial #{s} not found", 404
|
31
39
|
end
|
data/lib/ki/base_request.rb
CHANGED
data/lib/ki/helpers.rb
CHANGED
@@ -1,4 +1,13 @@
|
|
1
1
|
class String
|
2
|
+
# Converts a string to a class
|
3
|
+
#
|
4
|
+
# ==== Examples
|
5
|
+
#
|
6
|
+
# class User
|
7
|
+
# end
|
8
|
+
#
|
9
|
+
# "user".to_class == User
|
10
|
+
#
|
2
11
|
def to_class
|
3
12
|
chain = self.split "::"
|
4
13
|
klass = Kernel
|
@@ -29,7 +38,7 @@ end
|
|
29
38
|
|
30
39
|
module Ki
|
31
40
|
module Helpers
|
32
|
-
include
|
41
|
+
include Middleware::Helpers::View
|
33
42
|
|
34
43
|
def css url
|
35
44
|
render_haml "%link{:href => '#{url}', :rel => 'stylesheet'}"
|
data/lib/ki/ki_cli.rb
CHANGED
@@ -1,46 +1,67 @@
|
|
1
1
|
require 'thor'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module Ki
|
4
|
+
module Cli #:nodoc:
|
5
|
+
class KiGenerator < Thor::Group #:nodoc:
|
6
|
+
include Thor::Actions
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
8
|
+
def self.source_root
|
9
|
+
File.join(File.dirname(__FILE__), '..', '..')
|
10
|
+
end
|
11
|
+
end
|
10
12
|
|
11
|
-
class AppGenerator < KiGenerator
|
13
|
+
class AppGenerator < KiGenerator
|
12
14
|
|
13
|
-
|
15
|
+
argument :app_name
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
def prepare_dir
|
18
|
+
unless app_name =~ /^[a-zA-Z0-9-]*$/
|
19
|
+
say "App name must contain only alphanumeric characters and -"
|
20
|
+
exit 1
|
21
|
+
end
|
22
|
+
|
23
|
+
if Dir.exists? app_name
|
24
|
+
say "#{app_name} already exists"
|
25
|
+
exit 2
|
26
|
+
end
|
27
|
+
|
28
|
+
Dir.mkdir app_name
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_app
|
32
|
+
directory("spec/examples/base", app_name)
|
20
33
|
|
21
|
-
|
22
|
-
|
23
|
-
|
34
|
+
# Set database names
|
35
|
+
config_file = File.read("#{app_name}/config.yml")
|
36
|
+
config_file.gsub!("name: np_development", "name: #{app_name}_development")
|
37
|
+
config_file.gsub!("name: np_test", "name: #{app_name}_test")
|
38
|
+
config_file.gsub!("name: np", "name: #{app_name}")
|
39
|
+
File.open("#{app_name}/config.yml", "w") {|file| file.puts config_file}
|
40
|
+
|
41
|
+
# Set rvm gemset name
|
42
|
+
`echo #{app_name} > #{app_name}/.ruby-gemset`
|
43
|
+
end
|
24
44
|
end
|
25
45
|
|
26
|
-
|
27
|
-
|
46
|
+
class DevServer < KiGenerator
|
47
|
+
DEFAULT_PORT = 1337
|
28
48
|
|
29
|
-
|
30
|
-
|
49
|
+
argument :port, type: :numeric, desc: "port for ki server.", default: DEFAULT_PORT
|
50
|
+
desc "Starts the ki server"
|
31
51
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
File.open("#{app_name}/config.yml", "w") {|file| file.puts config_file}
|
52
|
+
def start_server
|
53
|
+
unless File.exists? 'config.ru'
|
54
|
+
say "Working directory should be a ki app."
|
55
|
+
exit 3
|
56
|
+
end
|
38
57
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
58
|
+
`bundle exec rackup -o 0.0.0.0 -p #{port}`
|
59
|
+
end
|
60
|
+
end
|
43
61
|
|
44
|
-
class
|
45
|
-
|
62
|
+
class Main < Thor
|
63
|
+
register AppGenerator, :new, 'new [APP_NAME]', 'generate a new app'
|
64
|
+
register DevServer, :server, 'server [PORT]', "start the ki server. Default port is #{DevServer::DEFAULT_PORT}"
|
65
|
+
end
|
66
|
+
end
|
46
67
|
end
|
data/lib/ki/middleware.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Ki
|
2
|
-
module Middleware
|
2
|
+
module Middleware #:nodoc:
|
3
3
|
module BaseMiddleware
|
4
|
-
include FormatOf
|
5
|
-
include
|
6
|
-
include
|
4
|
+
include Helpers::FormatOf
|
5
|
+
include Helpers::View
|
6
|
+
include Helpers::PublicFile
|
7
7
|
|
8
8
|
def initialize app
|
9
9
|
@app = app
|
@@ -29,9 +29,14 @@ module Ki
|
|
29
29
|
def call env
|
30
30
|
req = BaseRequest.new env
|
31
31
|
if req.root?
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
if public_file_exists? 'index.html'
|
33
|
+
env['PATH_INFO'] = '/index.html'
|
34
|
+
Rack::File.new(Ki::PUBLIC_PATH).call env
|
35
|
+
else
|
36
|
+
resp = Rack::Response.new
|
37
|
+
resp.redirect('/index')
|
38
|
+
resp.finish
|
39
|
+
end
|
35
40
|
else
|
36
41
|
env['CONTENT_TYPE'] = 'application/json' if format_of(req) == 'json'
|
37
42
|
@app.call env
|
@@ -80,7 +85,7 @@ module Ki
|
|
80
85
|
coffee_path = req.path.to_s[0...-3] + '.coffee'
|
81
86
|
if !public_file_exists?(req) && format_of(req) == 'js' && public_file_exists?(coffee_path)
|
82
87
|
js = CoffeeScript.compile(File.read(public_file_path(coffee_path)))
|
83
|
-
Rack::Response.new(js).finish
|
88
|
+
Rack::Response.new(js, 200, {"Content-Type" => "application/javascript"}).finish
|
84
89
|
else
|
85
90
|
@app.call env
|
86
91
|
end
|
@@ -96,7 +101,7 @@ module Ki
|
|
96
101
|
# if req ends with css and it does not exist, if a sass file exists instead
|
97
102
|
if !public_file_exists?(req) && format_of(req) == 'css' && public_file_exists?(sass_path)
|
98
103
|
eng = Sass::Engine.new(File.read(public_file_path(sass_path)), :syntax => :sass)
|
99
|
-
Rack::Response.new(eng.render).finish
|
104
|
+
Rack::Response.new(eng.render, 200, {"Content-Type" => "text/css"}).finish
|
100
105
|
else
|
101
106
|
@app.call env
|
102
107
|
end
|
data/lib/ki/modules/callbacks.rb
CHANGED
@@ -1,33 +1,35 @@
|
|
1
1
|
module Ki
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
class Model
|
3
|
+
module Callbacks
|
4
|
+
def before_all
|
5
|
+
end
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
def before_find
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
def after_find
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
def before_create
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
def after_create
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
19
|
+
def before_update
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
def after_update
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
25
|
+
def before_delete
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
28
|
+
def after_delete
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
+
def after_all
|
32
|
+
end
|
31
33
|
end
|
32
34
|
end
|
33
35
|
end
|
data/lib/ki/modules/format_of.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
module Ki
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
module Middleware
|
3
|
+
module Helpers
|
4
|
+
module FormatOf
|
5
|
+
def format_of uri
|
6
|
+
uri = uri.path if uri.class == BaseRequest
|
7
|
+
File.extname(URI.parse(uri).path).gsub('.','')
|
8
|
+
rescue URI::InvalidURIError => e
|
9
|
+
''
|
10
|
+
end
|
11
|
+
end
|
8
12
|
end
|
9
13
|
end
|
10
14
|
end
|
@@ -1,35 +1,37 @@
|
|
1
1
|
module Ki
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
class Model
|
3
|
+
module ModelHelpers
|
4
|
+
def get?
|
5
|
+
@req.get?
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def post?
|
9
|
+
@req.post?
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def put?
|
13
|
+
@req.put?
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
def delete?
|
17
|
+
@req.delete?
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
def forbidden_actions
|
21
|
+
[]
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
def required_attributes
|
25
|
+
[]
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
def skipped_params
|
29
|
+
[]
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
-
|
32
|
+
def unique_attributes
|
33
|
+
[]
|
34
|
+
end
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|