ki 0.3.3 → 0.4.1

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 (170) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +1 -1
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/Gemfile +2 -21
  7. data/Gemfile.lock +60 -100
  8. data/Guardfile +1 -1
  9. data/LICENSE.md +21 -0
  10. data/README.md +63 -0
  11. data/Rakefile +3 -45
  12. data/bin/ki +1 -1
  13. data/ki.gemspec +31 -137
  14. data/lib/ki.rb +21 -21
  15. data/lib/ki/api_error.rb +28 -0
  16. data/lib/ki/base_request.rb +34 -0
  17. data/lib/ki/helpers.rb +55 -0
  18. data/lib/ki/ki.rb +40 -0
  19. data/lib/ki/ki_cli.rb +46 -0
  20. data/lib/ki/ki_config.rb +20 -0
  21. data/lib/ki/middleware.rb +155 -0
  22. data/lib/ki/model.rb +70 -0
  23. data/lib/{modules → ki/modules}/callbacks.rb +0 -0
  24. data/lib/ki/modules/format_of.rb +10 -0
  25. data/lib/{modules → ki/modules}/model_helpers.rb +0 -12
  26. data/lib/ki/modules/public_file_helper.rb +13 -0
  27. data/lib/ki/modules/query_interface.rb +36 -0
  28. data/lib/{modules → ki/modules}/restrictions.rb +0 -30
  29. data/lib/ki/modules/view_helper.rb +13 -0
  30. data/lib/ki/orm.rb +65 -0
  31. data/lib/ki/version.rb +3 -0
  32. data/spec/examples/base/.ruby-gemset +1 -0
  33. data/spec/examples/base/.ruby-version +1 -0
  34. data/spec/examples/base/Gemfile +4 -0
  35. data/spec/examples/base/app.rb +1 -0
  36. data/{examples → spec/examples}/base/config.ru +0 -3
  37. data/spec/examples/base/config.yml +17 -0
  38. data/spec/examples/base/public/favicon.ico +0 -0
  39. data/spec/examples/base/public/javascripts/.gitkeep +0 -0
  40. data/spec/examples/base/public/stylesheets/.gitkeep +0 -0
  41. data/spec/examples/base/views/index.haml +6 -0
  42. data/spec/examples/couch-lock/.ruby-gemset +1 -0
  43. data/spec/examples/couch-lock/.ruby-version +1 -0
  44. data/spec/examples/couch-lock/Gemfile +4 -0
  45. data/spec/examples/couch-lock/Gemfile.lock +48 -0
  46. data/spec/examples/couch-lock/app.rb +42 -0
  47. data/spec/examples/couch-lock/config.ru +3 -0
  48. data/spec/examples/couch-lock/config.yml +17 -0
  49. data/spec/examples/couch-lock/install.sh +3 -0
  50. data/spec/examples/couch-lock/public/favicon.ico +0 -0
  51. data/spec/examples/couch-lock/public/javascripts/.gitkeep +0 -0
  52. data/spec/examples/couch-lock/public/stylesheets/.gitkeep +0 -0
  53. data/spec/examples/couch-lock/views/index.haml +18 -0
  54. data/spec/examples/json.northpole.ro/.ruby-gemset +1 -0
  55. data/spec/examples/json.northpole.ro/.ruby-version +1 -0
  56. data/spec/examples/json.northpole.ro/Capfile +25 -0
  57. data/spec/examples/json.northpole.ro/Gemfile +6 -0
  58. data/spec/examples/json.northpole.ro/Gemfile.lock +68 -0
  59. data/spec/examples/json.northpole.ro/app.rb +79 -0
  60. data/spec/examples/json.northpole.ro/client.rb +25 -0
  61. data/spec/examples/json.northpole.ro/config.ru +3 -0
  62. data/spec/examples/json.northpole.ro/config.yml +17 -0
  63. data/spec/examples/json.northpole.ro/config/deploy.rb +59 -0
  64. data/spec/examples/json.northpole.ro/config/deploy/production.rb +39 -0
  65. data/spec/examples/json.northpole.ro/foo.rb +10 -0
  66. data/spec/examples/json.northpole.ro/public/JNorthPole.jar +0 -0
  67. data/spec/examples/json.northpole.ro/public/favicon.ico +0 -0
  68. data/spec/examples/json.northpole.ro/public/font/FontAwesome.otf +0 -0
  69. data/spec/examples/json.northpole.ro/public/font/fontawesome-webfont.eot +0 -0
  70. data/spec/examples/json.northpole.ro/public/font/fontawesome-webfont.svg +284 -0
  71. data/spec/examples/json.northpole.ro/public/font/fontawesome-webfont.ttf +0 -0
  72. data/spec/examples/json.northpole.ro/public/font/fontawesome-webfont.woff +0 -0
  73. data/spec/examples/json.northpole.ro/public/images/bear.png +0 -0
  74. data/spec/examples/json.northpole.ro/public/images/bg.png +0 -0
  75. data/spec/examples/json.northpole.ro/public/images/cloud.png +0 -0
  76. data/spec/examples/json.northpole.ro/public/images/dotnet.png +0 -0
  77. data/spec/examples/json.northpole.ro/public/images/dotnet_small.png +0 -0
  78. data/spec/examples/json.northpole.ro/public/images/footer.png +0 -0
  79. data/spec/examples/json.northpole.ro/public/images/glyphicons-halflings-white.png +0 -0
  80. data/spec/examples/json.northpole.ro/public/images/glyphicons-halflings.png +0 -0
  81. data/spec/examples/json.northpole.ro/public/images/ice.png +0 -0
  82. data/spec/examples/json.northpole.ro/public/images/java.png +0 -0
  83. data/spec/examples/json.northpole.ro/public/images/java_small.png +0 -0
  84. data/spec/examples/json.northpole.ro/public/images/json.png +0 -0
  85. data/spec/examples/json.northpole.ro/public/images/json_small.png +0 -0
  86. data/spec/examples/json.northpole.ro/public/images/logo.png +0 -0
  87. data/spec/examples/json.northpole.ro/public/images/mobile.png +0 -0
  88. data/spec/examples/json.northpole.ro/public/images/php.png +0 -0
  89. data/spec/examples/json.northpole.ro/public/images/php_small.png +0 -0
  90. data/spec/examples/json.northpole.ro/public/images/python.png +0 -0
  91. data/spec/examples/json.northpole.ro/public/images/python_small.png +0 -0
  92. data/spec/examples/json.northpole.ro/public/images/ruby.png +0 -0
  93. data/spec/examples/json.northpole.ro/public/images/ruby_small.png +0 -0
  94. data/spec/examples/json.northpole.ro/public/images/shell.png +0 -0
  95. data/spec/examples/json.northpole.ro/public/images/shell_small.png +0 -0
  96. data/spec/examples/json.northpole.ro/public/javascripts/analytics.js +9 -0
  97. data/spec/examples/json.northpole.ro/public/javascripts/app.coffee +133 -0
  98. data/spec/examples/json.northpole.ro/public/javascripts/docs.min.js +16 -0
  99. data/spec/examples/json.northpole.ro/public/javascripts/jnorthpole.coffee +34 -0
  100. data/spec/examples/json.northpole.ro/public/javascripts/util.coffee +31 -0
  101. data/spec/examples/json.northpole.ro/public/stylesheets/app.sass +23 -0
  102. data/spec/examples/json.northpole.ro/public/stylesheets/application.sass +222 -0
  103. data/spec/examples/json.northpole.ro/public/stylesheets/cover.css +154 -0
  104. data/spec/examples/json.northpole.ro/views/curl.haml +19 -0
  105. data/spec/examples/json.northpole.ro/views/doc.haml +16 -0
  106. data/spec/examples/json.northpole.ro/views/doc_table.haml +45 -0
  107. data/spec/examples/json.northpole.ro/views/dotnet.haml +24 -0
  108. data/spec/examples/json.northpole.ro/views/examples.haml +28 -0
  109. data/spec/examples/json.northpole.ro/views/faq.haml +32 -0
  110. data/spec/examples/json.northpole.ro/views/foo.haml +7 -0
  111. data/spec/examples/json.northpole.ro/views/index.haml +4 -0
  112. data/spec/examples/json.northpole.ro/views/java.haml +0 -0
  113. data/spec/examples/json.northpole.ro/views/layout.haml +42 -0
  114. data/spec/examples/json.northpole.ro/views/php.haml +37 -0
  115. data/spec/examples/json.northpole.ro/views/playground.haml +38 -0
  116. data/spec/examples/json.northpole.ro/views/python.haml +17 -0
  117. data/spec/examples/json.northpole.ro/views/ruby.haml +12 -0
  118. data/spec/examples/json.northpole.ro/views/signup.haml +2 -0
  119. data/spec/examples/json.northpole.ro/views/thanks.haml +12 -0
  120. data/spec/functional_spec.rb +4 -0
  121. data/spec/lib/ki/base_request_spec.rb +88 -0
  122. data/spec/lib/ki/helpers_spec.rb +12 -0
  123. data/spec/lib/ki/ki_config_spec.rb +7 -0
  124. data/spec/lib/ki/middleware_spec.rb +11 -0
  125. data/spec/lib/ki/model_spec.rb +100 -0
  126. data/spec/lib/ki/modules/format_of_spec.rb +15 -0
  127. data/spec/lib/ki/orm_spec.rb +83 -0
  128. data/spec/spec_helper.rb +18 -5
  129. data/spec/util_spec.rb +7 -36
  130. metadata +269 -193
  131. data/.document +0 -5
  132. data/.rvmrc +0 -1
  133. data/LICENSE.txt +0 -20
  134. data/README.rdoc +0 -3
  135. data/VERSION +0 -1
  136. data/examples/base/Gemfile +0 -3
  137. data/examples/base/Gemfile.lock +0 -24
  138. data/examples/base/app.rb +0 -4
  139. data/examples/base/config.yml +0 -16
  140. data/gfx/colors.xcf +0 -0
  141. data/gfx/ki3.eps +0 -0
  142. data/gfx/logo.png +0 -0
  143. data/ki_wrap.rb +0 -35
  144. data/lib/conf.rb +0 -28
  145. data/lib/db.rb +0 -73
  146. data/lib/helpers.rb +0 -34
  147. data/lib/ki_cli.rb +0 -76
  148. data/lib/mockreq.rb +0 -45
  149. data/lib/model.rb +0 -110
  150. data/lib/modules/email.rb +0 -51
  151. data/lib/modules/query_interface.rb +0 -42
  152. data/lib/req.rb +0 -57
  153. data/lib/resp.rb +0 -70
  154. data/lib/static_file.rb +0 -68
  155. data/lib/util.rb +0 -114
  156. data/lib/views/404.haml +0 -1
  157. data/lib/views/406.haml +0 -1
  158. data/lib/views/index.haml +0 -7
  159. data/lib/views/layout.haml +0 -1
  160. data/spec/conf_spec.rb +0 -6
  161. data/spec/db_spec.rb +0 -93
  162. data/spec/integration/integration_spec.rb +0 -114
  163. data/spec/ki_spec.rb +0 -7
  164. data/spec/model_spec.rb +0 -91
  165. data/spec/modules/callbacks_spec.rb +0 -25
  166. data/spec/modules/email_spec.rb +0 -19
  167. data/spec/modules/query_interface_spec.rb +0 -93
  168. data/spec/modules/restrictions_spec.rb +0 -110
  169. data/spec/performance/performance.sh +0 -1
  170. data/spec/req_spec.rb +0 -29
File without changes
@@ -0,0 +1,10 @@
1
+ module Ki
2
+ module FormatOf
3
+ def format_of uri
4
+ uri = uri.path if uri.class == BaseRequest
5
+ File.extname(URI.parse(uri).path).gsub('.','')
6
+ rescue URI::InvalidURIError => e
7
+ ''
8
+ end
9
+ end
10
+ end
@@ -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
@@ -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
@@ -0,0 +1,3 @@
1
+ module Ki
2
+ VERSION = "0.4.1"
3
+ end
@@ -0,0 +1 @@
1
+ ki
@@ -0,0 +1 @@
1
+ 2.1.0
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'ki'
4
+ gem 'passenger'
@@ -0,0 +1 @@
1
+ require 'ki'
@@ -1,6 +1,3 @@
1
1
  require './app'
2
-
3
- use Rack::CommonLogger
4
2
  use Rack::Reloader, 0
5
-
6
3
  run Ki::Ki.new
@@ -0,0 +1,17 @@
1
+ development:
2
+ database:
3
+ name: np_development
4
+ host: 127.0.0.1
5
+ port: 27017
6
+
7
+ test:
8
+ database:
9
+ name: np_test
10
+ host: 127.0.0.1
11
+ port: 27017
12
+
13
+ production:
14
+ database:
15
+ name: np
16
+ host: 127.0.0.1
17
+ port: 27017
@@ -0,0 +1,6 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %title Ki Framework
5
+ %body
6
+ %p Hello World
@@ -0,0 +1 @@
1
+ couch-lock
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'ki', :path => '../../..'
4
+ gem 'passenger'
@@ -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,3 @@
1
+ require './app'
2
+ use Rack::Reloader, 0
3
+ run Ki::Ki.new
@@ -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
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+
3
+ sudo apt-get install disper vlc
@@ -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