ki 0.3.3 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +1 -1
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -21
- data/Gemfile.lock +60 -100
- data/Guardfile +1 -1
- data/LICENSE.md +21 -0
- data/README.md +63 -0
- data/Rakefile +3 -45
- data/bin/ki +1 -1
- data/ki.gemspec +31 -137
- data/lib/ki.rb +21 -21
- data/lib/ki/api_error.rb +28 -0
- data/lib/ki/base_request.rb +34 -0
- data/lib/ki/helpers.rb +55 -0
- data/lib/ki/ki.rb +40 -0
- data/lib/ki/ki_cli.rb +46 -0
- data/lib/ki/ki_config.rb +20 -0
- data/lib/ki/middleware.rb +155 -0
- data/lib/ki/model.rb +70 -0
- data/lib/{modules → ki/modules}/callbacks.rb +0 -0
- data/lib/ki/modules/format_of.rb +10 -0
- data/lib/{modules → ki/modules}/model_helpers.rb +0 -12
- data/lib/ki/modules/public_file_helper.rb +13 -0
- data/lib/ki/modules/query_interface.rb +36 -0
- data/lib/{modules → ki/modules}/restrictions.rb +0 -30
- data/lib/ki/modules/view_helper.rb +13 -0
- data/lib/ki/orm.rb +65 -0
- data/lib/ki/version.rb +3 -0
- data/spec/examples/base/.ruby-gemset +1 -0
- data/spec/examples/base/.ruby-version +1 -0
- data/spec/examples/base/Gemfile +4 -0
- data/spec/examples/base/app.rb +1 -0
- data/{examples → spec/examples}/base/config.ru +0 -3
- data/spec/examples/base/config.yml +17 -0
- data/spec/examples/base/public/favicon.ico +0 -0
- data/spec/examples/base/public/javascripts/.gitkeep +0 -0
- data/spec/examples/base/public/stylesheets/.gitkeep +0 -0
- data/spec/examples/base/views/index.haml +6 -0
- data/spec/examples/couch-lock/.ruby-gemset +1 -0
- data/spec/examples/couch-lock/.ruby-version +1 -0
- data/spec/examples/couch-lock/Gemfile +4 -0
- data/spec/examples/couch-lock/Gemfile.lock +48 -0
- data/spec/examples/couch-lock/app.rb +42 -0
- data/spec/examples/couch-lock/config.ru +3 -0
- data/spec/examples/couch-lock/config.yml +17 -0
- data/spec/examples/couch-lock/install.sh +3 -0
- data/spec/examples/couch-lock/public/favicon.ico +0 -0
- data/spec/examples/couch-lock/public/javascripts/.gitkeep +0 -0
- data/spec/examples/couch-lock/public/stylesheets/.gitkeep +0 -0
- data/spec/examples/couch-lock/views/index.haml +18 -0
- data/spec/examples/json.northpole.ro/.ruby-gemset +1 -0
- data/spec/examples/json.northpole.ro/.ruby-version +1 -0
- data/spec/examples/json.northpole.ro/Capfile +25 -0
- data/spec/examples/json.northpole.ro/Gemfile +6 -0
- data/spec/examples/json.northpole.ro/Gemfile.lock +68 -0
- data/spec/examples/json.northpole.ro/app.rb +79 -0
- data/spec/examples/json.northpole.ro/client.rb +25 -0
- data/spec/examples/json.northpole.ro/config.ru +3 -0
- data/spec/examples/json.northpole.ro/config.yml +17 -0
- data/spec/examples/json.northpole.ro/config/deploy.rb +59 -0
- data/spec/examples/json.northpole.ro/config/deploy/production.rb +39 -0
- data/spec/examples/json.northpole.ro/foo.rb +10 -0
- data/spec/examples/json.northpole.ro/public/JNorthPole.jar +0 -0
- data/spec/examples/json.northpole.ro/public/favicon.ico +0 -0
- data/spec/examples/json.northpole.ro/public/font/FontAwesome.otf +0 -0
- data/spec/examples/json.northpole.ro/public/font/fontawesome-webfont.eot +0 -0
- data/spec/examples/json.northpole.ro/public/font/fontawesome-webfont.svg +284 -0
- data/spec/examples/json.northpole.ro/public/font/fontawesome-webfont.ttf +0 -0
- data/spec/examples/json.northpole.ro/public/font/fontawesome-webfont.woff +0 -0
- data/spec/examples/json.northpole.ro/public/images/bear.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/bg.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/cloud.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/dotnet.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/dotnet_small.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/footer.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/glyphicons-halflings-white.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/glyphicons-halflings.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/ice.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/java.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/java_small.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/json.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/json_small.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/logo.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/mobile.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/php.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/php_small.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/python.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/python_small.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/ruby.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/ruby_small.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/shell.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/shell_small.png +0 -0
- data/spec/examples/json.northpole.ro/public/javascripts/analytics.js +9 -0
- data/spec/examples/json.northpole.ro/public/javascripts/app.coffee +133 -0
- data/spec/examples/json.northpole.ro/public/javascripts/docs.min.js +16 -0
- data/spec/examples/json.northpole.ro/public/javascripts/jnorthpole.coffee +34 -0
- data/spec/examples/json.northpole.ro/public/javascripts/util.coffee +31 -0
- data/spec/examples/json.northpole.ro/public/stylesheets/app.sass +23 -0
- data/spec/examples/json.northpole.ro/public/stylesheets/application.sass +222 -0
- data/spec/examples/json.northpole.ro/public/stylesheets/cover.css +154 -0
- data/spec/examples/json.northpole.ro/views/curl.haml +19 -0
- data/spec/examples/json.northpole.ro/views/doc.haml +16 -0
- data/spec/examples/json.northpole.ro/views/doc_table.haml +45 -0
- data/spec/examples/json.northpole.ro/views/dotnet.haml +24 -0
- data/spec/examples/json.northpole.ro/views/examples.haml +28 -0
- data/spec/examples/json.northpole.ro/views/faq.haml +32 -0
- data/spec/examples/json.northpole.ro/views/foo.haml +7 -0
- data/spec/examples/json.northpole.ro/views/index.haml +4 -0
- data/spec/examples/json.northpole.ro/views/java.haml +0 -0
- data/spec/examples/json.northpole.ro/views/layout.haml +42 -0
- data/spec/examples/json.northpole.ro/views/php.haml +37 -0
- data/spec/examples/json.northpole.ro/views/playground.haml +38 -0
- data/spec/examples/json.northpole.ro/views/python.haml +17 -0
- data/spec/examples/json.northpole.ro/views/ruby.haml +12 -0
- data/spec/examples/json.northpole.ro/views/signup.haml +2 -0
- data/spec/examples/json.northpole.ro/views/thanks.haml +12 -0
- data/spec/functional_spec.rb +4 -0
- data/spec/lib/ki/base_request_spec.rb +88 -0
- data/spec/lib/ki/helpers_spec.rb +12 -0
- data/spec/lib/ki/ki_config_spec.rb +7 -0
- data/spec/lib/ki/middleware_spec.rb +11 -0
- data/spec/lib/ki/model_spec.rb +100 -0
- data/spec/lib/ki/modules/format_of_spec.rb +15 -0
- data/spec/lib/ki/orm_spec.rb +83 -0
- data/spec/spec_helper.rb +18 -5
- data/spec/util_spec.rb +7 -36
- metadata +269 -193
- data/.document +0 -5
- data/.rvmrc +0 -1
- data/LICENSE.txt +0 -20
- data/README.rdoc +0 -3
- data/VERSION +0 -1
- data/examples/base/Gemfile +0 -3
- data/examples/base/Gemfile.lock +0 -24
- data/examples/base/app.rb +0 -4
- data/examples/base/config.yml +0 -16
- data/gfx/colors.xcf +0 -0
- data/gfx/ki3.eps +0 -0
- data/gfx/logo.png +0 -0
- data/ki_wrap.rb +0 -35
- data/lib/conf.rb +0 -28
- data/lib/db.rb +0 -73
- data/lib/helpers.rb +0 -34
- data/lib/ki_cli.rb +0 -76
- data/lib/mockreq.rb +0 -45
- data/lib/model.rb +0 -110
- data/lib/modules/email.rb +0 -51
- data/lib/modules/query_interface.rb +0 -42
- data/lib/req.rb +0 -57
- data/lib/resp.rb +0 -70
- data/lib/static_file.rb +0 -68
- data/lib/util.rb +0 -114
- data/lib/views/404.haml +0 -1
- data/lib/views/406.haml +0 -1
- data/lib/views/index.haml +0 -7
- data/lib/views/layout.haml +0 -1
- data/spec/conf_spec.rb +0 -6
- data/spec/db_spec.rb +0 -93
- data/spec/integration/integration_spec.rb +0 -114
- data/spec/ki_spec.rb +0 -7
- data/spec/model_spec.rb +0 -91
- data/spec/modules/callbacks_spec.rb +0 -25
- data/spec/modules/email_spec.rb +0 -19
- data/spec/modules/query_interface_spec.rb +0 -93
- data/spec/modules/restrictions_spec.rb +0 -110
- data/spec/performance/performance.sh +0 -1
- data/spec/req_spec.rb +0 -29
File without changes
|
@@ -1,9 +1,5 @@
|
|
1
1
|
module Ki
|
2
2
|
module ModelHelpers
|
3
|
-
def params
|
4
|
-
@req.params
|
5
|
-
end
|
6
|
-
|
7
3
|
def get?
|
8
4
|
@req.get?
|
9
5
|
end
|
@@ -24,10 +20,6 @@ module Ki
|
|
24
20
|
[]
|
25
21
|
end
|
26
22
|
|
27
|
-
def responds_to_formats
|
28
|
-
[:json, :html]
|
29
|
-
end
|
30
|
-
|
31
23
|
def required_attributes
|
32
24
|
[]
|
33
25
|
end
|
@@ -39,9 +31,5 @@ module Ki
|
|
39
31
|
def unique_attributes
|
40
32
|
[]
|
41
33
|
end
|
42
|
-
|
43
|
-
def selected_layout
|
44
|
-
:layout
|
45
|
-
end
|
46
34
|
end
|
47
35
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Ki
|
2
|
+
module PublicFileHelper
|
3
|
+
def public_file_exists? path
|
4
|
+
path = path.path if path.class == BaseRequest
|
5
|
+
File.file?(public_file_path(path))
|
6
|
+
end
|
7
|
+
|
8
|
+
def public_file_path path
|
9
|
+
path = path.path if path.class == BaseRequest
|
10
|
+
File.join(Ki::PUBLIC_PATH, path)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Ki
|
2
|
+
# the query interface does not respect before/after filters,
|
3
|
+
# unique attributes, required attributes or anything of the
|
4
|
+
# sort.
|
5
|
+
# it writes directly to the database
|
6
|
+
module QueryInterface
|
7
|
+
def count hash={}
|
8
|
+
Orm::Db.instance.count class_name, hash
|
9
|
+
end
|
10
|
+
|
11
|
+
def find hash={}
|
12
|
+
Orm::Db.instance.find class_name, hash
|
13
|
+
end
|
14
|
+
|
15
|
+
def create hash
|
16
|
+
Orm::Db.instance.insert class_name, hash
|
17
|
+
end
|
18
|
+
|
19
|
+
def find_or_create hash
|
20
|
+
r = find hash
|
21
|
+
r.empty? ? create(hash) : r
|
22
|
+
end
|
23
|
+
|
24
|
+
def update hash
|
25
|
+
Orm::Db.instance.update class_name, hash
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete hash
|
29
|
+
Orm::Db.instance.delete class_name, hash
|
30
|
+
end
|
31
|
+
|
32
|
+
def class_name
|
33
|
+
self.to_s
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -15,21 +15,6 @@ module Ki
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def responds_to_formats
|
19
|
-
[:json, :html]
|
20
|
-
end
|
21
|
-
|
22
|
-
def respond_to *formats
|
23
|
-
send :define_method, :responds_to_formats do
|
24
|
-
formats
|
25
|
-
end
|
26
|
-
|
27
|
-
eigen_class = class << self; self; end
|
28
|
-
eigen_class.send(:define_method, :responds_to_formats) do
|
29
|
-
formats
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
18
|
def required_attributes
|
34
19
|
[]
|
35
20
|
end
|
@@ -59,20 +44,5 @@ module Ki
|
|
59
44
|
attributes
|
60
45
|
end
|
61
46
|
end
|
62
|
-
|
63
|
-
def selected_layout
|
64
|
-
:layout
|
65
|
-
end
|
66
|
-
|
67
|
-
def layout l
|
68
|
-
send :define_method, :selected_layout do
|
69
|
-
l
|
70
|
-
end
|
71
|
-
|
72
|
-
eigen_class = class << self; self; end
|
73
|
-
eigen_class.send(:define_method, :selected_layout) do
|
74
|
-
l
|
75
|
-
end
|
76
|
-
end
|
77
47
|
end
|
78
48
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Ki
|
2
|
+
module ViewHelper
|
3
|
+
def view_exists? path
|
4
|
+
path = path.path if path.class == BaseRequest
|
5
|
+
File.file?(view_path(path))
|
6
|
+
end
|
7
|
+
|
8
|
+
def view_path path
|
9
|
+
path = path.path if path.class == BaseRequest
|
10
|
+
File.join(Ki::VIEWS_PATH, path + ".haml")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/ki/orm.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module Ki
|
4
|
+
module Orm
|
5
|
+
class Db
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
attr_reader :config, :connection, :db
|
9
|
+
|
10
|
+
def establish_connection
|
11
|
+
@config = KiConfig.instance.database
|
12
|
+
@connection = Mongo::Connection.new(@config['host'], @config['port'])
|
13
|
+
@db = @connection.db(@config['name'])
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def collection_names
|
18
|
+
@db.collection_names.delete_if{|name| name =~ /^system/}
|
19
|
+
end
|
20
|
+
|
21
|
+
def insert name, hash
|
22
|
+
@db[name].insert(hash)
|
23
|
+
[hash].stringify_ids.first
|
24
|
+
end
|
25
|
+
|
26
|
+
def find name, hash={}
|
27
|
+
hash = nourish_hash_id hash
|
28
|
+
@db[name].find(hash).to_a.stringify_ids
|
29
|
+
end
|
30
|
+
|
31
|
+
def update name, hash
|
32
|
+
hash = nourish_hash_id hash
|
33
|
+
id = hash['_id'].to_s
|
34
|
+
hash.delete('_id')
|
35
|
+
@db[name].update({'_id' => BSON::ObjectId(id)}, hash)
|
36
|
+
hash['id'] = id
|
37
|
+
hash
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete name, hash
|
41
|
+
hash = nourish_hash_id hash
|
42
|
+
@db[name].remove hash
|
43
|
+
{}
|
44
|
+
end
|
45
|
+
|
46
|
+
def count name, hash={}
|
47
|
+
@db[name].count hash
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def nourish_hash_id hash
|
53
|
+
hash = { '_id' => BSON::ObjectId(hash) } if hash.class == String
|
54
|
+
if hash['id']
|
55
|
+
hash['_id'] = hash['id']
|
56
|
+
hash.delete('id')
|
57
|
+
end
|
58
|
+
if hash['_id'].class == String
|
59
|
+
hash['_id'] = BSON::ObjectId(hash['_id'].to_s)
|
60
|
+
end
|
61
|
+
hash
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/ki/version.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ki
|
@@ -0,0 +1 @@
|
|
1
|
+
2.1.0
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'ki'
|
Binary file
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
couch-lock
|
@@ -0,0 +1 @@
|
|
1
|
+
2.1.2
|
@@ -0,0 +1,48 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../../..
|
3
|
+
specs:
|
4
|
+
ki (0.4.0)
|
5
|
+
bson_ext
|
6
|
+
bundler (~> 1.5)
|
7
|
+
coffee-script
|
8
|
+
haml
|
9
|
+
mongo
|
10
|
+
rack
|
11
|
+
rack-parser
|
12
|
+
sass
|
13
|
+
thor
|
14
|
+
|
15
|
+
GEM
|
16
|
+
remote: https://rubygems.org/
|
17
|
+
specs:
|
18
|
+
bson (1.11.1)
|
19
|
+
bson_ext (1.11.1)
|
20
|
+
bson (~> 1.11.1)
|
21
|
+
coffee-script (2.3.0)
|
22
|
+
coffee-script-source
|
23
|
+
execjs
|
24
|
+
coffee-script-source (1.8.0)
|
25
|
+
daemon_controller (1.2.0)
|
26
|
+
execjs (2.2.1)
|
27
|
+
haml (4.0.5)
|
28
|
+
tilt
|
29
|
+
mongo (1.11.1)
|
30
|
+
bson (= 1.11.1)
|
31
|
+
passenger (4.0.53)
|
32
|
+
daemon_controller (>= 1.2.0)
|
33
|
+
rack
|
34
|
+
rake (>= 0.8.1)
|
35
|
+
rack (1.5.2)
|
36
|
+
rack-parser (0.6.1)
|
37
|
+
rack
|
38
|
+
rake (10.3.2)
|
39
|
+
sass (3.4.5)
|
40
|
+
thor (0.19.1)
|
41
|
+
tilt (2.0.1)
|
42
|
+
|
43
|
+
PLATFORMS
|
44
|
+
ruby
|
45
|
+
|
46
|
+
DEPENDENCIES
|
47
|
+
ki!
|
48
|
+
passenger
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'ki'
|
2
|
+
|
3
|
+
class Monitors < Ki::Model
|
4
|
+
forbid :create, :update, :delete
|
5
|
+
|
6
|
+
def after_find
|
7
|
+
return if params["q"].nil?
|
8
|
+
return unless ['c', 'e'].include? params["q"]
|
9
|
+
|
10
|
+
`disper -#{params["q"]}`
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Fireplace < Ki::Model
|
15
|
+
forbid :create, :update, :delete
|
16
|
+
|
17
|
+
def after_find
|
18
|
+
return if params["q"].nil?
|
19
|
+
return unless ['kill', 'start'].include? params["q"]
|
20
|
+
|
21
|
+
if params["q"] == "kill"
|
22
|
+
`killall -9 vlc`
|
23
|
+
else
|
24
|
+
`vlc https://www.youtube.com/watch?v=rH79BmeeM0o --fullscreen`
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Sound < Ki::Model
|
30
|
+
forbid :create, :update, :delete
|
31
|
+
|
32
|
+
def after_find
|
33
|
+
return if params["q"].nil?
|
34
|
+
return unless ['speakers', 'hdmi'].include? params["q"]
|
35
|
+
|
36
|
+
if params["q"] == "speakers"
|
37
|
+
`pacmd set-default-sink alsa_output.pci-0000_00_1b.0.analog-stereo`
|
38
|
+
else
|
39
|
+
`pacmd set-default-sink alsa_output.pci-0000_01_00.1.hdmi-stereo-extra1`
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
development:
|
2
|
+
database:
|
3
|
+
name: couch-lock_development
|
4
|
+
host: 127.0.0.1
|
5
|
+
port: 27017
|
6
|
+
|
7
|
+
test:
|
8
|
+
database:
|
9
|
+
name: couch-lock_test
|
10
|
+
host: 127.0.0.1
|
11
|
+
port: 27017
|
12
|
+
|
13
|
+
production:
|
14
|
+
database:
|
15
|
+
name: couch-lock
|
16
|
+
host: 127.0.0.1
|
17
|
+
port: 27017
|
Binary file
|
File without changes
|
File without changes
|
@@ -0,0 +1,18 @@
|
|
1
|
+
!!!
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
%title Ki Framework
|
5
|
+
%body
|
6
|
+
%ul
|
7
|
+
%li
|
8
|
+
%a{ href: '/monitors.json?q=c&redirect_to=/' } clone
|
9
|
+
%li
|
10
|
+
%a{ href: '/monitors.json?q=e&redirect_to=/' } extend
|
11
|
+
%li
|
12
|
+
%a{ href: '/fireplace.json?q=start&redirect_to=/' } fireplace
|
13
|
+
%li
|
14
|
+
%a{ href: '/fireplace.json?q=kill&redirect_to=/' } fireplace kill
|
15
|
+
%li
|
16
|
+
%a{ href: '/sound.json?q=speakers&redirect_to=/' } speakers
|
17
|
+
%li
|
18
|
+
%a{ href: '/sound.json?q=hdmi&redirect_to=/' } hdmi
|
@@ -0,0 +1 @@
|
|
1
|
+
json.northpole.ro
|
@@ -0,0 +1 @@
|
|
1
|
+
2.1.2
|