kilt-cms 0.9.13 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +3 -5
  3. data/app/controllers/kilt/kilt_controller.rb +1 -1
  4. data/app/views/kilt/form/{boolean.html.erb → _boolean.html.erb} +0 -0
  5. data/app/views/kilt/form/{datetime.html.erb → _datetime.html.erb} +0 -0
  6. data/app/views/kilt/form/{file.html.erb → _file.html.erb} +1 -1
  7. data/app/views/kilt/form/{html.html.erb → _html.html.erb} +0 -0
  8. data/app/views/kilt/form/{image.html.erb → _image.html.erb} +1 -1
  9. data/app/views/kilt/form/{longtext.html.erb → _longtext.html.erb} +0 -0
  10. data/app/views/kilt/form/{number.html.erb → _number.html.erb} +0 -0
  11. data/app/views/kilt/form/{select_one.html.erb → _select_one.html.erb} +0 -0
  12. data/app/views/kilt/form/{text.html.erb → _text.html.erb} +0 -0
  13. data/app/views/kilt/form/{vimeo.html.erb → _vimeo.html.erb} +0 -0
  14. data/app/views/kilt/form/{youtube.html.erb → _youtube.html.erb} +0 -0
  15. data/app/views/kilt/kilt/_form.html.erb +12 -10
  16. data/app/views/kilt/kilt/edit.html.erb +1 -1
  17. data/app/views/kilt/kilt/index.html.erb +3 -2
  18. data/app/views/kilt/kilt/list.html.erb +6 -9
  19. data/app/views/kilt/kilt/new.html.erb +1 -1
  20. data/app/views/layouts/kilt/cms/_menu.html.erb +2 -6
  21. data/lib/generators/kilt/backend_generator.rb +28 -6
  22. data/lib/generators/kilt/templates/backend/create_kilt_objects.rb +13 -0
  23. data/lib/generators/kilt/templates/backend/creds.yml.example +10 -5
  24. data/lib/generators/kilt/templates/backend/creds.yml.rethinkdb.example +22 -0
  25. data/lib/kilt.rb +34 -54
  26. data/lib/kilt/base.rb +3 -2
  27. data/lib/kilt/db/active_record.rb +50 -0
  28. data/lib/kilt/db/rethink_db.rb +108 -0
  29. data/lib/kilt/form.rb +7 -5
  30. data/lib/kilt/formatting.rb +39 -0
  31. data/lib/kilt/object.rb +32 -31
  32. data/lib/kilt/utils.rb +32 -39
  33. data/lib/kilt_object.rb +3 -0
  34. data/test/dummy/config/application.rb +1 -1
  35. data/test/dummy/config/database.yml +5 -0
  36. data/test/dummy/config/initializers/kilt.rb +1 -1
  37. data/test/dummy/config/kilt/config.yml +4 -13
  38. data/test/dummy/config/kilt/creds.yml +16 -11
  39. data/test/dummy/config/kilt/creds.yml.rethinkdb.example +22 -0
  40. data/test/dummy/config/routes.rb +1 -1
  41. data/test/dummy/db/migrate/20140519110428_create_kilt_objects.rb +13 -0
  42. data/test/dummy/db/schema.rb +29 -0
  43. data/test/dummy/log/development.log +551 -0
  44. data/test/dummy/public/uploads/image/timbo.jpg +0 -0
  45. data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  46. data/test/dummy/tmp/cache/assets/development/sprockets/18837248cb3274df9b7c6b0a5dcd56a5 +0 -0
  47. data/test/dummy/tmp/cache/assets/development/sprockets/20dffc9385ea740ceca470ee4e4b2197 +0 -0
  48. data/test/dummy/tmp/cache/assets/development/sprockets/23733156ea27da67211ba7ff763d76f0 +0 -0
  49. data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  50. data/test/dummy/tmp/cache/assets/development/sprockets/3148655edeef1c319d57d0f9570acfd5 +0 -0
  51. data/test/dummy/tmp/cache/assets/development/sprockets/32ab48c63ad3bb6ddc1f419e51adb5db +0 -0
  52. data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  53. data/test/dummy/tmp/cache/assets/development/sprockets/36715e644093cfcb33ac795f3c9d66fe +0 -0
  54. data/test/dummy/tmp/cache/assets/development/sprockets/36f9a7f6f43adb582ac6eec43b58eb30 +0 -0
  55. data/test/dummy/tmp/cache/assets/development/sprockets/3d8ca1585ee95c5efb388645d66cf377 +0 -0
  56. data/test/dummy/tmp/cache/assets/development/sprockets/413be9c73d25c7febe933f4619da7cf8 +0 -0
  57. data/test/dummy/tmp/cache/assets/development/sprockets/4a935342c0113b534ad7622234965544 +0 -0
  58. data/test/dummy/tmp/cache/assets/development/sprockets/4b5c4a1edd3823a6a6c39e06b6eb230a +0 -0
  59. data/test/dummy/tmp/cache/assets/development/sprockets/4c5736bf0bd429296d1a32930364897e +0 -0
  60. data/test/dummy/tmp/cache/assets/development/sprockets/4f26158b7a804a3e3c47ce0ceff2798c +0 -0
  61. data/test/dummy/tmp/cache/assets/development/sprockets/542fc810f9cd36e7bed9a3e5e9670995 +0 -0
  62. data/test/dummy/tmp/cache/assets/development/sprockets/56f1e7d57d31bf3315e1e33732d57faa +0 -0
  63. data/test/dummy/tmp/cache/assets/development/sprockets/5bea4c2d87ec725262213ed51575b485 +0 -0
  64. data/test/dummy/tmp/cache/assets/development/sprockets/6b6e86e81f5e8f80bb2b3d1e8f7ed7f3 +0 -0
  65. data/test/dummy/tmp/cache/assets/development/sprockets/6c2ddc22c04321c269de383e37cb519b +0 -0
  66. data/test/dummy/tmp/cache/assets/development/sprockets/7035e5c60f5da3b7fc12c472677483d0 +0 -0
  67. data/test/dummy/tmp/cache/assets/development/sprockets/704c682957c2beb38a1927ddb66cc557 +0 -0
  68. data/test/dummy/tmp/cache/assets/development/sprockets/74b6c3e00222b8bf31b0ecf50fcb0d38 +0 -0
  69. data/test/dummy/tmp/cache/assets/development/sprockets/91021bdb7ebb3d4f6fdf4e49909d4c07 +0 -0
  70. data/test/dummy/tmp/cache/assets/development/sprockets/914095efd3b33401a7f29f9fb05d72d6 +0 -0
  71. data/test/dummy/tmp/cache/assets/development/sprockets/9dd98bca318fb820a8451cafce020588 +0 -0
  72. data/test/dummy/tmp/cache/assets/development/sprockets/9f2c00a36b5b8c713a797b508c778a65 +0 -0
  73. data/test/dummy/tmp/cache/assets/development/sprockets/a88ab4e49bb7203b8e0586c38efdd2b0 +0 -0
  74. data/test/dummy/tmp/cache/assets/development/sprockets/acfc15d25fde8b933b06c91324755751 +0 -0
  75. data/test/dummy/tmp/cache/assets/development/sprockets/c0671678b70011547b80da0669d031cc +0 -0
  76. data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  77. data/test/dummy/tmp/cache/assets/development/sprockets/d6973c1d43f8ca41b98a6b640fda2616 +0 -0
  78. data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  79. data/test/dummy/tmp/cache/assets/development/sprockets/dc676330961fd22be77c48cb77ec065f +0 -0
  80. data/test/dummy/tmp/cache/assets/development/sprockets/ddc29f2c13cd99d017fd526b61dcb951 +0 -0
  81. data/test/dummy/tmp/cache/assets/development/sprockets/de45247cb814cafe20e9e46c79e470fe +0 -0
  82. data/test/dummy/tmp/cache/assets/development/sprockets/df0b7c3ac590a286561806e813c2974f +0 -0
  83. data/test/dummy/tmp/cache/assets/development/sprockets/dfa8b85e3c1273b7e69839e4e607c3e1 +0 -0
  84. data/test/dummy/tmp/cache/assets/development/sprockets/e22d705d0c889ec4837f183a9beec0f3 +0 -0
  85. data/test/dummy/tmp/cache/assets/development/sprockets/e3a4ad3549e1e57d03698a36daeff406 +0 -0
  86. data/test/dummy/tmp/cache/assets/development/sprockets/ef7c8ce46dfc9e9087ce84dbdfdd0011 +0 -0
  87. data/test/dummy/tmp/cache/assets/development/sprockets/f4b5dd06a6113950c0f481cbc5a31a66 +0 -0
  88. data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  89. data/test/dummy/tmp/data/meta_request/1c3d4a4b-d7e1-4126-8bfc-572acbc2f675.json +1 -0
  90. data/test/dummy/tmp/data/meta_request/449ff78e-30d2-4cc5-bbb7-3397d04a4c46.json +1 -0
  91. data/test/dummy/tmp/data/meta_request/5974cfb9-99bd-4d5c-a4e1-6e352ecd2dd8.json +1 -0
  92. data/test/dummy/tmp/data/meta_request/960de12b-b1c5-4d44-937b-e3d8c00d682c.json +1 -0
  93. data/test/dummy/tmp/data/meta_request/9df9ad77-1b70-4fb7-ad18-f31f28c60c6c.json +1 -0
  94. data/test/dummy/tmp/data/meta_request/a5374758-4e16-487a-ab11-9a69a1abed2e.json +1 -0
  95. data/test/dummy/tmp/data/meta_request/a65d97b2-df1f-445e-99d5-615c4db5c4e1.json +1 -0
  96. data/test/dummy/tmp/data/meta_request/b3693c6f-23cd-4afe-ae82-38078eaa643a.json +1 -0
  97. data/test/dummy/tmp/data/meta_request/daa1c80a-bad3-4bc1-8f67-d586979cbedc.json +1 -0
  98. data/test/dummy/tmp/data/meta_request/e2e7621f-08e5-46dd-83c2-b87eb6d5fd45.json +1 -0
  99. data/test/empty.sqlite3 +0 -0
  100. data/test/generators/kilt/backend_generator_spec.rb +70 -0
  101. data/test/kilt/form_spec.rb +40 -51
  102. data/test/kilt/formatting_spec.rb +66 -0
  103. data/test/kilt/object_spec.rb +204 -0
  104. data/test/kilt/utils_spec.rb +147 -0
  105. data/test/kilt_object_spec.rb +12 -0
  106. data/test/kilt_spec.rb +422 -0
  107. data/test/minitest_helper.rb +58 -0
  108. metadata +164 -66
  109. data/test/dummy/tmp/data/meta_request/191f094a-5e87-4654-bc80-5acb51d3f903.json +0 -1
  110. data/test/dummy/tmp/data/meta_request/1eb9499d-2e84-47df-ac0a-da308031aa3a.json +0 -1
  111. data/test/dummy/tmp/data/meta_request/300cabd2-6e51-4b1b-ab55-a072049c2a0f.json +0 -1
  112. data/test/dummy/tmp/data/meta_request/3ec7ea74-e7a7-4f4d-9434-e08edfc12b8a.json +0 -1
  113. data/test/dummy/tmp/data/meta_request/5bb81411-321e-4cba-9ffa-87fcd8105ef4.json +0 -1
  114. data/test/dummy/tmp/data/meta_request/9d6e10c1-5b14-4199-852e-9f1e97132b8f.json +0 -1
  115. data/test/dummy/tmp/data/meta_request/a6403ed9-21f1-4a00-9725-4a1c544214f6.json +0 -1
  116. data/test/dummy/tmp/data/meta_request/b4487e0b-0a08-40a3-a364-e715e6765631.json +0 -1
  117. data/test/dummy/tmp/data/meta_request/d399f913-d3a5-4de3-b012-848377a702fc.json +0 -1
  118. data/test/dummy/tmp/data/meta_request/dcf95267-1855-4062-85c8-e880f8d62443.json +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cea124fc5db8137e9f0977072b63f52893b67786
4
- data.tar.gz: 1c77d6e7b5c6ab5345c63902f470acf4593be569
3
+ metadata.gz: 92e36981513be1d52296ed4d4321e194a104c4dc
4
+ data.tar.gz: a6d90b7b31ef3246fa406a754dec05943469c030
5
5
  SHA512:
6
- metadata.gz: e6484b3682a25da1da72328fd7637479421719c1fa3232d6725d29a03d85fedf20fc1564ea6e3de031bd93dc2358c7fa0396718b072639e28fb62e975f8386b6
7
- data.tar.gz: a8c0440e8c765a0c4319a50908acf1ce378b4127f0f5027030f8a9636eb1c5a97f8b759786f1a451aa7f8b08752e1da567d475a894c3d2e59528d98e5e710e9e
6
+ metadata.gz: f4ab8a4e06b2a8c2b979040006f8d39557e1c091b9521e7293ee9d8bce710b7e6b9e3a1c84a29c6173cb05f1220ebbf0cc9cea9be12be35df0231c23fda782f4
7
+ data.tar.gz: 7a13dd0365393f397a46c328f40f77c0f416f4f3fd04662ebe1d55fa96f975492b7da31c405a4f41e560d282973c6bb2b54229fb5395859439022107360c253c
data/README.rdoc CHANGED
@@ -25,13 +25,11 @@ Note: We're trying to find a way around that last step, but for now we're just e
25
25
  - Run the Kilt generator:
26
26
 
27
27
  $ rails g kilt:install
28
-
29
- - Create a creds file:
30
28
 
31
- $ mv config/kilt/creds.yml.example config/kilt/creds.yml
29
+ If you would like to use RethinkDB as your datastore, you'll need to copy the rethinkdb example. Add your database info to the creds.yml. You should have a RethinkDB set up and running already.
30
+
31
+ $ mv config/kilt/creds.yml.rethinkdb.example config/kilt/creds.yml
32
32
 
33
- - Add your database info to the creds.yml. You should have a RethinkDB set up and running already.
34
-
35
33
  - If you want to use S3 for your image and file uploads, add your S3 info to creds.yml. Also set the following in your config.yml:
36
34
 
37
35
  storage:
@@ -114,7 +114,7 @@ module Kilt
114
114
  private
115
115
 
116
116
  def ensure_config
117
- if Kilt.config.empty? || !Kilt.config.db
117
+ unless Kilt::Utils.config_is_valid?
118
118
  lines = []
119
119
  lines << '<pre>'
120
120
  lines << 'The Kilt gem has been installed, but you haven\'t configured it yet.'
@@ -3,7 +3,7 @@
3
3
 
4
4
  <% if object["#{field_name}"] && object["#{field_name}"] != '' %>
5
5
  <div class="filename">
6
- <span><%= link_to object["#{field_name}"], Kilt::Utils.download_location(field_name, object["#{field_name}"]), :target => '_blank' %>
6
+ <span><%= link_to object["#{field_name}"], Kilt::Utils.download_location('file', object["#{field_name}"]), :target => '_blank' %>
7
7
  <a class="button delete <% if !object["#{field_name}"] || object["#{field_name}"] == "" %>hidden<% end %>">Reset/remove file</a></span>
8
8
  </div>
9
9
  <% end %>
@@ -4,7 +4,7 @@
4
4
  <% if object["#{field_name}"] && object["#{field_name}"] != '' %>
5
5
  <div id="image-container-<%= index %>">
6
6
  <div id="image-<%= index %>">
7
- <%= image_tag Kilt::Utils.download_location(field_name, object["#{field_name}"]), :width => '100%' %>
7
+ <%= image_tag Kilt::Utils.download_location('image', object["#{field_name}"]), :width => '100%' %>
8
8
  </div>
9
9
  <div>
10
10
  <a id="image-reset-<%= index%>" class="button delete <% if !object["#{field_name}"] || object["#{field_name}"] == "" %>hidden<% end %>">Reset/remove image</a>
@@ -2,18 +2,15 @@
2
2
  <div class="wr">
3
3
 
4
4
  <%
5
- if Kilt.send(@type).name != nil
6
- name = Kilt.send(@type).name
7
- else
8
- name = @type.pluralize.capitalize
9
- end
5
+ singular = Kilt::Formatting.singular_name_of @type
6
+ plural = Kilt::Formatting.plural_name_of @type
10
7
  %>
11
8
 
12
- <h2><%= @object['name'] %> <small><%= name.singularize.capitalize %></small></h2>
9
+ <h2><%= @object['name'] %> <small><%= singular %></small></h2>
13
10
 
14
11
  <div class="page-actions">
15
- <%= link_to "← Back to #{name}", list_path(@type), :class => 'button back' %>
16
- <%= link_to "New #{@type.capitalize}", new_object_path(@type), :class => 'button back' if !@object.empty? %>
12
+ <%= link_to "← Back to #{plural}", list_path(@type), :class => 'button back' %>
13
+ <%= link_to "New #{singular}", new_object_path(@type), :class => 'button back' if !@object.empty? %>
17
14
  </div>
18
15
 
19
16
  <% if flash[:error] -%>
@@ -27,7 +24,12 @@
27
24
  <%= form_tag @path, :method => "post", :multipart => true do %>
28
25
 
29
26
  <% @object.fields.each_with_index do |(key, value), index| %>
30
- <%= Kilt::Form.prep_field(value, @object, key, index) %>
27
+ <%= Kilt::Form.render_field(self, {
28
+ key: key,
29
+ value: value,
30
+ object: @object,
31
+ index: index
32
+ } ) %>
31
33
  <% end %>
32
34
 
33
35
  <div class="form-input actions">
@@ -36,4 +38,4 @@
36
38
 
37
39
  <% end%>
38
40
 
39
- </div>
41
+ </div>
@@ -1,2 +1,2 @@
1
1
  <% @path = update_object_path(@type.pluralize, @slug) %>
2
- <%= render :partial => 'form' %>
2
+ <%= render :partial => 'form' %>
@@ -2,8 +2,9 @@
2
2
  <h2>Dashboard</h2>
3
3
 
4
4
  <ul class="object-list">
5
- <% @types.each do |type, name| %>
5
+ <% @types.each do |type, _| %>
6
+ <% name = Kilt::Formatting.plural_name_of(type) %>
6
7
  <li><%= link_to name, list_path(type.pluralize) %></li>
7
8
  <% end %>
8
9
  </ul>
9
- </div>
10
+ </div>
@@ -1,17 +1,14 @@
1
1
  <div class="wr">
2
2
 
3
3
  <%
4
- if Kilt.send(@type).name != nil
5
- name = Kilt.send(@type).name
6
- else
7
- name = @type.pluralize.capitalize
8
- end
4
+ singular = Kilt::Formatting.singular_name_of @type
5
+ plural = Kilt::Formatting.plural_name_of @type
9
6
  %>
10
7
 
11
- <h2><%= name %></h2>
8
+ <h2><%= plural %></h2>
12
9
 
13
10
  <div class="page-actions">
14
- <%= link_to "New #{name.singularize.capitalize}", new_object_path(@type.singularize), :class => 'button' %>
11
+ <%= link_to "New #{singular}", new_object_path(@type.singularize), :class => 'button' %>
15
12
  </div>
16
13
 
17
14
  <!-- todo: search by title -->
@@ -26,7 +23,7 @@
26
23
 
27
24
  <% if @objects.empty? %>
28
25
 
29
- No <%= name %> found.
26
+ No <%= plural %> found.
30
27
 
31
28
  <% else %>
32
29
 
@@ -72,4 +69,4 @@
72
69
 
73
70
  <% end %>
74
71
 
75
- </div>
72
+ </div>
@@ -1,2 +1,2 @@
1
1
  <% @path = create_object_path(@type.pluralize) %>
2
- <%= render :partial => 'form' %>
2
+ <%= render :partial => 'form' %>
@@ -4,13 +4,9 @@
4
4
  <a class="button small dashboard" href="<%= kilt_engine.root_path %>">Dashboard</a>
5
5
  <% Kilt.types.each do |type| %>
6
6
  <%
7
- if Kilt.send(type).name != nil
8
- name = Kilt.send(type).name
9
- else
10
- name = type.pluralize.capitalize
11
- end
7
+ plural = Kilt::Formatting.plural_name_of type
12
8
  %>
13
- <%= link_to name, list_path(type.pluralize), class: "button small dashboard" %>
9
+ <%= link_to plural, list_path(type.pluralize), class: "button small dashboard" %>
14
10
  <% end %>
15
11
  </div>
16
12
  </header>
@@ -7,14 +7,36 @@ module Kilt
7
7
  source_root File.expand_path("../templates/backend", __FILE__)
8
8
 
9
9
  def generate
10
-
11
- #copy files, templates for app-specific naming, inject engine mount to routes
10
+ add_the_config_file
11
+ add_the_credential_file_examples
12
+ add_the_database_migration_file
13
+ add_the_kilt_routes
14
+ add_the_initializer
15
+ end
16
+
17
+ private
18
+
19
+ def add_the_config_file
12
20
  template 'config.yml.erb', Rails.root.join('config', 'kilt', 'config.yml')
13
- copy_file 'creds.yml.example', Rails.root.join('config', 'kilt', 'creds.yml.example')
21
+ end
22
+
23
+ def add_the_credential_file_examples
24
+ copy_file 'creds.yml.example', Rails.root.join('config', 'kilt', 'creds.yml')
25
+ copy_file 'creds.yml.rethinkdb.example', Rails.root.join('config', 'kilt', 'creds.yml.rethinkdb.example')
26
+ end
27
+
28
+ def add_the_database_migration_file
29
+ copy_file 'create_kilt_objects.rb', Rails.root.join('db', 'migrate', Time.now.strftime("%Y%m%d%H%M%S") + "_create_kilt_objects.rb")
30
+ end
31
+
32
+ def add_the_kilt_routes
33
+ inject_into_file Rails.root.join('config', 'routes.rb'), "\n\tmount Kilt::Engine => '/admin', as: 'kilt_engine'\n", :after => ".routes.draw do\n"
34
+ end
35
+
36
+ def add_the_initializer
14
37
  copy_file 'kilt.rb', Rails.root.join('config', 'initializers', 'kilt.rb')
15
- inject_into_file Rails.root.join('config', 'routes.rb'), "\n\tmount Kilt::Engine => '/admin', as: 'kilt_engine'\n", :after => "#{Rails.application.class.parent_name.camelize}::Application.routes.draw do\n"
16
-
17
38
  end
39
+
18
40
  end
19
41
  end
20
- end
42
+ end
@@ -0,0 +1,13 @@
1
+ class CreateKiltObjects < ActiveRecord::Migration
2
+ def change
3
+ create_table :kilt_objects do |t|
4
+ t.string :unique_id
5
+ t.string :name
6
+ t.string :object_type
7
+ t.string :slug
8
+ t.text :data
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -1,11 +1,16 @@
1
- db:
2
- host: <DB host>
3
- port: <DB port>
4
- db: <DB database>
1
+ test:
2
+ db:
3
+ type: active_record
4
+ development:
5
+ db:
6
+ type: active_record
7
+ production:
8
+ db:
9
+ type: active_record
5
10
  s3:
6
11
  key: <S3 key>
7
12
  secret: <S3 secret>
8
13
  bucket: <S3 bucket>
9
14
  auth:
10
15
  username: <Username>
11
- password: <Password>
16
+ password: <Password>
@@ -0,0 +1,22 @@
1
+ test:
2
+ db:
3
+ host: 127.0.0.1
4
+ port: 28015
5
+ db: my_app_test
6
+ development:
7
+ db:
8
+ host: 127.0.0.1
9
+ port: 28015
10
+ db: my_app_development
11
+ production:
12
+ db:
13
+ host: ENV['KILT_HOST']
14
+ port: ENV['KILT_PORT']
15
+ db: ENV['KILT_DB']
16
+ s3:
17
+ key: <S3 key>
18
+ secret: <S3 secret>
19
+ bucket: <S3 bucket>
20
+ auth:
21
+ username: <Username>
22
+ password: <Password>
data/lib/kilt.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "kilt/base"
2
+ require_relative "kilt_object"
2
3
 
3
4
  # Include the Rethink shortcut module, which will among other things instantiate a new
4
5
  # Rethink object (as "r") if needed
@@ -38,20 +39,11 @@ module Kilt
38
39
  # Example: Kilt.create(object)
39
40
  def self.create(object)
40
41
  object['created_at'] = object['updated_at'] = Time.now
41
- object['unique_id'] = "#{(Time.now.to_f * 1000).to_i}"
42
- result = Utils.db do
43
-
44
- # Check for slug uniqueness
45
- results = r.db(Kilt.config.db.db).table('objects').filter({'slug' => "#{object['slug'].to_s}"}).run
46
- if results.to_a.length > 0
47
- object['slug'] = "#{object['slug']}-#{(Time.now.to_f * 1000).to_i}"
48
- end
49
-
50
- # Insert the record
51
- r.db(Kilt.config.db.db).table('objects').insert(object.values).run
52
-
53
- end
54
- (result['errors'] == 0)
42
+ object['unique_id'] = "#{(Time.now.to_f * 1000).to_i}"
43
+ object['type'] = object.instance_eval { @type }
44
+ object['slug'] = slug_for object
45
+
46
+ Utils.database.create object
55
47
  end
56
48
 
57
49
  # Update an object
@@ -59,52 +51,25 @@ module Kilt
59
51
  # Example: Kilt.update(object)
60
52
  def self.update(slug, object)
61
53
  object['updated_at'] = Time.now
62
- result = Utils.db do
63
-
64
- # Keep the original slug handy
65
- results = r.db(Kilt.config.db.db).table('objects').filter({'slug' => "#{slug}"}).limit(1).run
66
- original = results.to_a.first['unique_id']
67
-
68
- # Check for slug uniqueness
69
- results = r.db(Kilt.config.db.db).table('objects').filter({'slug' => "#{object['slug']}"}).run
70
- if results
71
- result = results.to_a.first
72
- if result && result['unique_id'] != original
73
- object['slug'] = "#{Kilt::Utils.slugify(object['name'])}-#{(Time.now.to_f * 1000).to_i}"
74
- end
75
- end
76
-
77
- # Update the record
78
- r.db(Kilt.config.db.db).table('objects').filter({'unique_id' => "#{original}"}).update(object.values).run
79
-
80
- end
81
- (result['errors'] == 0)
82
- end
54
+ object['slug'] = slug_for object
83
55
 
56
+ Utils.database.update object
57
+ end
84
58
 
85
59
  # Delete an object
86
60
  # Returns: boolean
87
61
  # Example: Kilt.delete('some-object')
88
62
  def self.delete(slug)
89
- result = Utils.db do
90
- r.db(Kilt.config.db.db).table('objects').filter({'slug' => "#{slug.to_s}"}).delete().run
91
- end
92
- (result['errors'] == 0)
63
+ Utils.database.delete slug
93
64
  end
94
65
 
95
66
  # Get the content for a specific object
96
67
  # Returns: Kilt::Object instance
97
68
  # Example: Kilt.object('big-event')
98
69
  def self.get(slug)
99
- # connect to the db, get the object, close the connection, return the object
100
- values = Utils.db do
101
- r.db(Kilt.config.db.db).table('objects').filter({'slug' => "#{slug.to_s}"}).run
102
- end
103
-
104
- result = values.to_a.first
105
-
106
- # create an object and return it
107
- Kilt::Object.new(result['type'], result)
70
+ result = Utils.database.find(slug)
71
+ result ? Kilt::Object.new(result['type'], result)
72
+ : nil
108
73
  end
109
74
 
110
75
  # Get a list of objects
@@ -112,13 +77,28 @@ module Kilt
112
77
  # Example: Kilt.objects('events')
113
78
  # Used directly or via method_missing
114
79
  def self.get_collection(object_type)
115
- # connect to the db, get the date, close the connection, return the array
116
- results = Utils.db do
117
- r.db(Kilt.config.db.db).table('objects').filter({'type' => "#{object_type.singularize.to_s}"}).run
80
+ results = Utils.database.find_all_by_type object_type
81
+ Kilt::ObjectCollection.new results
82
+ end
83
+
84
+ class << self
85
+
86
+ private
87
+
88
+ def slug_is_unique_for? slug, object
89
+ result = Utils.database.find(slug)
90
+ return true if result.nil?
91
+
92
+ "#{result['unique_id']}" == "#{object['unique_id']}"
118
93
  end
119
-
120
- # create an object collection
121
- Kilt::ObjectCollection.new(results.to_a)
94
+
95
+ def slug_for object
96
+ slug = object['slug'].to_s.strip == '' ? Utils.slugify(object['name'])
97
+ : "#{object['slug']}"
98
+ slug_is_unique_for?(slug, object) ? slug
99
+ : "#{slug}-#{(Time.now.to_f * 1000).to_i}"
100
+ end
101
+
122
102
  end
123
103
 
124
104
  end
data/lib/kilt/base.rb CHANGED
@@ -6,7 +6,8 @@ require "kilt/object_collection"
6
6
 
7
7
  require 'kilt/upload'
8
8
 
9
+ require "kilt/db/rethink_db"
10
+ require "kilt/db/active_record"
9
11
  require "kilt/utils"
10
12
  require "kilt/form"
11
-
12
- r = RethinkDB::RQL.new
13
+ require "kilt/formatting"