kilt-cms 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +8 -8
  3. data/Rakefile +1 -0
  4. data/app/assets/images/kilt/logo.png +0 -0
  5. data/app/assets/images/kilt/tartan.png +0 -0
  6. data/app/assets/stylesheets/kilt/screen.css +1962 -4
  7. data/app/controllers/kilt/kilt_controller.rb +14 -6
  8. data/app/views/kilt/kilt/_field_setup.html.erb +6 -0
  9. data/app/views/kilt/kilt/_form.html.erb +9 -5
  10. data/app/views/kilt/kilt/index.html.erb +0 -2
  11. data/app/views/kilt/kilt/list.html.erb +3 -3
  12. data/app/views/layouts/kilt/cms.html.erb +12 -1
  13. data/app/views/layouts/kilt/cms/_default_creds_warning.html.erb +4 -0
  14. data/app/views/layouts/kilt/cms/_menu.html.erb +1 -7
  15. data/lib/generators/kilt/backend_generator.rb +0 -1
  16. data/lib/generators/kilt/templates/backend/creds.yml.example +6 -2
  17. data/lib/kilt.rb +17 -25
  18. data/lib/kilt/base.rb +3 -1
  19. data/lib/kilt/engine.rb +1 -2
  20. data/lib/kilt/object.rb +1 -1
  21. data/lib/kilt/slugger.rb +55 -0
  22. data/lib/kilt/upload.rb +18 -46
  23. data/lib/kilt/upload/local.rb +17 -0
  24. data/lib/kilt/upload/s3.rb +24 -0
  25. data/lib/kilt/utils.rb +1 -5
  26. data/lib/kilt_object.rb +7 -2
  27. data/lib/kilt_view_model.rb +44 -0
  28. data/test/dummy/config/kilt/config.yml +11 -2
  29. data/test/dummy/config/kilt/creds.yml.example +6 -2
  30. data/test/generators/kilt/backend_generator_spec.rb +0 -7
  31. data/test/kilt/upload_spec.rb +309 -0
  32. data/test/kilt/utils_spec.rb +4 -12
  33. data/test/kilt_spec.rb +132 -26
  34. data/test/kilt_view_model_spec.rb +128 -0
  35. data/test/minitest_helper.rb +6 -5
  36. metadata +47 -231
  37. data/lib/generators/kilt/frontend_generator.rb +0 -37
  38. data/lib/generators/kilt/templates/backend/creds.yml.rethinkdb.example +0 -22
  39. data/lib/generators/kilt/templates/frontend/application.html.erb +0 -24
  40. data/lib/generators/kilt/templates/frontend/assets/javascripts/application.js +0 -14
  41. data/lib/generators/kilt/templates/frontend/assets/javascripts/html5shiv.js +0 -2
  42. data/lib/generators/kilt/templates/frontend/assets/javascripts/mediaqueries.js +0 -1
  43. data/lib/generators/kilt/templates/frontend/assets/stylesheets/application.css +0 -13
  44. data/lib/generators/kilt/templates/frontend/assets/stylesheets/screen.css +0 -160
  45. data/lib/generators/kilt/templates/frontend/dummy.js.erb +0 -11
  46. data/lib/generators/kilt/templates/frontend/home_controller.rb.erb +0 -4
  47. data/lib/generators/kilt/templates/frontend/index.html.erb +0 -5
  48. data/lib/kilt/db/rethink_db.rb +0 -108
  49. data/test/dummy/config/kilt/creds.yml +0 -16
  50. data/test/dummy/log/development.log +0 -84143
  51. data/test/dummy/log/test.log +0 -36
  52. data/test/dummy/public/uploads/image/photo.JPG +0 -0
  53. data/test/dummy/public/uploads/image/timbo.jpg +0 -0
  54. data/test/dummy/tmp/cache/assets/development/sprockets/03cdc43618f8bef3dfc725a1886c40ed +0 -0
  55. data/test/dummy/tmp/cache/assets/development/sprockets/0d8e5c7178ebdb79e5b9cc4ef439eae8 +0 -0
  56. data/test/dummy/tmp/cache/assets/development/sprockets/13a3d23d13c1459a86283c4fe577a775 +0 -0
  57. data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  58. data/test/dummy/tmp/cache/assets/development/sprockets/18837248cb3274df9b7c6b0a5dcd56a5 +0 -0
  59. data/test/dummy/tmp/cache/assets/development/sprockets/1c198a7e1d4ae808a6adf4c4809061eb +0 -0
  60. data/test/dummy/tmp/cache/assets/development/sprockets/20dffc9385ea740ceca470ee4e4b2197 +0 -0
  61. data/test/dummy/tmp/cache/assets/development/sprockets/23733156ea27da67211ba7ff763d76f0 +0 -0
  62. data/test/dummy/tmp/cache/assets/development/sprockets/2e57def2c82ce30227eefea2360d5f50 +0 -0
  63. data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  64. data/test/dummy/tmp/cache/assets/development/sprockets/3148655edeef1c319d57d0f9570acfd5 +0 -0
  65. data/test/dummy/tmp/cache/assets/development/sprockets/32ab48c63ad3bb6ddc1f419e51adb5db +0 -0
  66. data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  67. data/test/dummy/tmp/cache/assets/development/sprockets/36715e644093cfcb33ac795f3c9d66fe +0 -0
  68. data/test/dummy/tmp/cache/assets/development/sprockets/36f9a7f6f43adb582ac6eec43b58eb30 +0 -0
  69. data/test/dummy/tmp/cache/assets/development/sprockets/36fff19076c588427464432f563a8d2d +0 -0
  70. data/test/dummy/tmp/cache/assets/development/sprockets/3878e0f19bbd21176b1bcc46160a3df3 +0 -0
  71. data/test/dummy/tmp/cache/assets/development/sprockets/3cee919b5b764629fbb01de361ad1b99 +0 -0
  72. data/test/dummy/tmp/cache/assets/development/sprockets/3d69f4783ceef2f5455635de03e6c62a +0 -0
  73. data/test/dummy/tmp/cache/assets/development/sprockets/3d8ca1585ee95c5efb388645d66cf377 +0 -0
  74. data/test/dummy/tmp/cache/assets/development/sprockets/3e0acde4cdc501f590a21ede6fac0b97 +0 -0
  75. data/test/dummy/tmp/cache/assets/development/sprockets/413be9c73d25c7febe933f4619da7cf8 +0 -0
  76. data/test/dummy/tmp/cache/assets/development/sprockets/4a935342c0113b534ad7622234965544 +0 -0
  77. data/test/dummy/tmp/cache/assets/development/sprockets/4b5c4a1edd3823a6a6c39e06b6eb230a +0 -0
  78. data/test/dummy/tmp/cache/assets/development/sprockets/4c5736bf0bd429296d1a32930364897e +0 -0
  79. data/test/dummy/tmp/cache/assets/development/sprockets/4f26158b7a804a3e3c47ce0ceff2798c +0 -0
  80. data/test/dummy/tmp/cache/assets/development/sprockets/542fc810f9cd36e7bed9a3e5e9670995 +0 -0
  81. data/test/dummy/tmp/cache/assets/development/sprockets/56f1e7d57d31bf3315e1e33732d57faa +0 -0
  82. data/test/dummy/tmp/cache/assets/development/sprockets/5bea4c2d87ec725262213ed51575b485 +0 -0
  83. data/test/dummy/tmp/cache/assets/development/sprockets/5eb5178b706a9b8bd0362b7ed487339a +0 -0
  84. data/test/dummy/tmp/cache/assets/development/sprockets/5fa6492da1cba5232b9e9799b5e2bf8f +0 -0
  85. data/test/dummy/tmp/cache/assets/development/sprockets/5fe3d26a30497da82978c9f7ee53068b +0 -0
  86. data/test/dummy/tmp/cache/assets/development/sprockets/66f697b8e4167ad9ebefbd8b5fc65b23 +0 -0
  87. data/test/dummy/tmp/cache/assets/development/sprockets/6b6e86e81f5e8f80bb2b3d1e8f7ed7f3 +0 -0
  88. data/test/dummy/tmp/cache/assets/development/sprockets/6c2ddc22c04321c269de383e37cb519b +0 -0
  89. data/test/dummy/tmp/cache/assets/development/sprockets/6caab0d3b759107ab41492546763aaf0 +0 -0
  90. data/test/dummy/tmp/cache/assets/development/sprockets/6d83c6efd2bf1080ba1dead9fcfdd0db +0 -0
  91. data/test/dummy/tmp/cache/assets/development/sprockets/7035e5c60f5da3b7fc12c472677483d0 +0 -0
  92. data/test/dummy/tmp/cache/assets/development/sprockets/704c682957c2beb38a1927ddb66cc557 +0 -0
  93. data/test/dummy/tmp/cache/assets/development/sprockets/70d4b3b9e59d0e01e90eebf94dbc2c47 +0 -0
  94. data/test/dummy/tmp/cache/assets/development/sprockets/74b6c3e00222b8bf31b0ecf50fcb0d38 +0 -0
  95. data/test/dummy/tmp/cache/assets/development/sprockets/8127282074e6ffd457b72c228a69f0c0 +0 -0
  96. data/test/dummy/tmp/cache/assets/development/sprockets/8ffacb4ba6e6ca3da12ac1100f664b30 +0 -0
  97. data/test/dummy/tmp/cache/assets/development/sprockets/91021bdb7ebb3d4f6fdf4e49909d4c07 +0 -0
  98. data/test/dummy/tmp/cache/assets/development/sprockets/914095efd3b33401a7f29f9fb05d72d6 +0 -0
  99. data/test/dummy/tmp/cache/assets/development/sprockets/9dd98bca318fb820a8451cafce020588 +0 -0
  100. data/test/dummy/tmp/cache/assets/development/sprockets/9f2c00a36b5b8c713a797b508c778a65 +0 -0
  101. data/test/dummy/tmp/cache/assets/development/sprockets/a88ab4e49bb7203b8e0586c38efdd2b0 +0 -0
  102. data/test/dummy/tmp/cache/assets/development/sprockets/acfc15d25fde8b933b06c91324755751 +0 -0
  103. data/test/dummy/tmp/cache/assets/development/sprockets/b259805c84c81064f20700498328f109 +0 -0
  104. data/test/dummy/tmp/cache/assets/development/sprockets/b7e1f059a53a1e79df01a336fb1f50f0 +0 -0
  105. data/test/dummy/tmp/cache/assets/development/sprockets/c0671678b70011547b80da0669d031cc +0 -0
  106. data/test/dummy/tmp/cache/assets/development/sprockets/c1006115f345f87cc152b851154e9e34 +0 -0
  107. data/test/dummy/tmp/cache/assets/development/sprockets/cf0d5ad037fbf541c6b982abf73b9938 +0 -0
  108. data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  109. data/test/dummy/tmp/cache/assets/development/sprockets/d6973c1d43f8ca41b98a6b640fda2616 +0 -0
  110. data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  111. data/test/dummy/tmp/cache/assets/development/sprockets/da31523b2e8cf32dd8db9f304d5b7395 +0 -0
  112. data/test/dummy/tmp/cache/assets/development/sprockets/dc676330961fd22be77c48cb77ec065f +0 -0
  113. data/test/dummy/tmp/cache/assets/development/sprockets/ddc29f2c13cd99d017fd526b61dcb951 +0 -0
  114. data/test/dummy/tmp/cache/assets/development/sprockets/de45247cb814cafe20e9e46c79e470fe +0 -0
  115. data/test/dummy/tmp/cache/assets/development/sprockets/df0b7c3ac590a286561806e813c2974f +0 -0
  116. data/test/dummy/tmp/cache/assets/development/sprockets/dfa8b85e3c1273b7e69839e4e607c3e1 +0 -0
  117. data/test/dummy/tmp/cache/assets/development/sprockets/e22d705d0c889ec4837f183a9beec0f3 +0 -0
  118. data/test/dummy/tmp/cache/assets/development/sprockets/e3a4ad3549e1e57d03698a36daeff406 +0 -0
  119. data/test/dummy/tmp/cache/assets/development/sprockets/e7ba95a61b1b9381906a88610dceb6dd +0 -0
  120. data/test/dummy/tmp/cache/assets/development/sprockets/ef7c8ce46dfc9e9087ce84dbdfdd0011 +0 -0
  121. data/test/dummy/tmp/cache/assets/development/sprockets/f3e1a8ba304f70dccefd77356c900ebc +0 -0
  122. data/test/dummy/tmp/cache/assets/development/sprockets/f4b5dd06a6113950c0f481cbc5a31a66 +0 -0
  123. data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  124. data/test/dummy/tmp/data/meta_request/1c3d4a4b-d7e1-4126-8bfc-572acbc2f675.json +0 -1
  125. data/test/dummy/tmp/data/meta_request/449ff78e-30d2-4cc5-bbb7-3397d04a4c46.json +0 -1
  126. data/test/dummy/tmp/data/meta_request/5974cfb9-99bd-4d5c-a4e1-6e352ecd2dd8.json +0 -1
  127. data/test/dummy/tmp/data/meta_request/960de12b-b1c5-4d44-937b-e3d8c00d682c.json +0 -1
  128. data/test/dummy/tmp/data/meta_request/9df9ad77-1b70-4fb7-ad18-f31f28c60c6c.json +0 -1
  129. data/test/dummy/tmp/data/meta_request/a5374758-4e16-487a-ab11-9a69a1abed2e.json +0 -1
  130. data/test/dummy/tmp/data/meta_request/a65d97b2-df1f-445e-99d5-615c4db5c4e1.json +0 -1
  131. data/test/dummy/tmp/data/meta_request/b3693c6f-23cd-4afe-ae82-38078eaa643a.json +0 -1
  132. data/test/dummy/tmp/data/meta_request/daa1c80a-bad3-4bc1-8f67-d586979cbedc.json +0 -1
  133. data/test/dummy/tmp/data/meta_request/e2e7621f-08e5-46dd-83c2-b87eb6d5fd45.json +0 -1
@@ -4,6 +4,7 @@ module Kilt
4
4
  protect_from_forgery
5
5
  before_filter :ensure_config
6
6
  before_filter :authorize
7
+ before_filter :show_default_creds_warning
7
8
 
8
9
  # Show all the object types
9
10
  def index
@@ -48,10 +49,10 @@ module Kilt
48
49
 
49
50
  # Call Kilt's update method
50
51
  if Kilt.create(object)
51
- flash[:notice] = "#{type.capitalize} successfully updated"
52
+ flash[:notice] = "#{Kilt::Formatting.singular_name_of(type)} successfully updated"
52
53
  redirect_to edit_object_path(type.pluralize, object.slug)
53
54
  else
54
- flash[:error] = "Couldn't save #{type.capitalize}"
55
+ flash[:error] = "Couldn't save #{Kilt::Formatting.singular_name_of(type)}"
55
56
  redirect_to new_object_path(type.pluralize)
56
57
  end
57
58
  end
@@ -84,9 +85,9 @@ module Kilt
84
85
 
85
86
  # Call Kilt's update method
86
87
  if Kilt.update(slug, object)
87
- flash[:notice] = "#{type.capitalize} successfully updated"
88
+ flash[:notice] = "#{Kilt::Formatting.singular_name_of(type)} successfully updated"
88
89
  else
89
- flash[:error] = "Couldn't save #{type.capitalize}"
90
+ flash[:error] = "Couldn't save #{Kilt::Formatting.singular_name_of(type)}"
90
91
  end
91
92
 
92
93
  # redirect to the edit screen
@@ -102,9 +103,9 @@ module Kilt
102
103
 
103
104
  # Call Kilt's update method
104
105
  if Kilt.delete(slug)
105
- flash[:notice] = "#{type.capitalize} successfully deleted"
106
+ flash[:notice] = "#{Kilt::Formatting.singular_name_of(type)} successfully deleted"
106
107
  else
107
- flash[:error] = "Couldn't delete #{type.capitalize}"
108
+ flash[:error] = "Couldn't delete #{Kilt::Formatting.singular_name_of(type)}"
108
109
  end
109
110
 
110
111
  # redirect to the list screen
@@ -137,6 +138,13 @@ module Kilt
137
138
  true
138
139
  end
139
140
  end
141
+
142
+ def show_default_creds_warning
143
+ @show_default_creds_warning = Kilt.config.auth && Kilt.config.auth.username && Kilt.config.auth.password &&
144
+ Kilt.config.default_auth && Kilt.config.default_auth.username && Kilt.config.default_auth.password &&
145
+ Kilt.config.auth.username == Kilt.config.default_auth.username &&
146
+ Kilt.config.auth.password == Kilt.config.default_auth.password
147
+ end
140
148
 
141
149
  end
142
150
  end
@@ -0,0 +1,6 @@
1
+ <% Kilt.all_used_fields.each do |field| %>
2
+ <% begin %>
3
+ <%= render partial: "kilt/form/#{field}_#{type}" %>
4
+ <% rescue %>
5
+ <% end %>
6
+ <% end %>
@@ -6,11 +6,15 @@
6
6
  plural = Kilt::Formatting.plural_name_of @type
7
7
  %>
8
8
 
9
- <h2><%= @object['name'] %> <small><%= singular %></small></h2>
10
-
11
9
  <div class="page-actions">
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? %>
10
+ <h2><%= @object['name'] || "New #{singular}" %>
11
+ <% if @object['name'] %>
12
+ <small>Type: <%= singular %></small>
13
+ <% end %>
14
+ </h2>
15
+
16
+ <%= link_to "← Back to #{plural}", list_path(@type), :class => 'button back newline' %>
17
+ <%= link_to "New #{singular}", new_object_path(@type), :class => 'button back newline' if !@object.empty? %>
14
18
  </div>
15
19
 
16
20
  <% if flash[:error] -%>
@@ -33,7 +37,7 @@
33
37
  <% end %>
34
38
 
35
39
  <div class="form-input actions">
36
- <input type="submit" class="submit save" value="Save">
40
+ <input type="submit" class="submit button save" value="Save">
37
41
  </div>
38
42
 
39
43
  <% end%>
@@ -1,6 +1,4 @@
1
1
  <div class="wr">
2
- <h2>Dashboard</h2>
3
-
4
2
  <ul class="object-list">
5
3
  <% @types.each do |type, _| %>
6
4
  <% name = Kilt::Formatting.plural_name_of(type) %>
@@ -1,3 +1,4 @@
1
+
1
2
  <div class="wr">
2
3
 
3
4
  <%
@@ -5,9 +6,8 @@
5
6
  plural = Kilt::Formatting.plural_name_of @type
6
7
  %>
7
8
 
8
- <h2><%= plural %></h2>
9
-
10
9
  <div class="page-actions">
10
+ <h3><%= plural %></h3>
11
11
  <%= link_to "New #{singular}", new_object_path(@type.singularize), :class => 'button' %>
12
12
  </div>
13
13
 
@@ -56,7 +56,7 @@
56
56
  </td>
57
57
  <td class="actions">
58
58
  <%= link_to 'Edit', edit_object_path(@type.pluralize, object['slug']), :class => 'button edit' %>
59
- <%= link_to 'Delete', delete_object_path(@type.pluralize, object['slug']), :class => 'button delete', :method => 'delete', :data => {:confirm => "Are you sure you want to delete this #{@type.capitalize}?" } %>
59
+ <%= link_to 'Delete', delete_object_path(@type.pluralize, object['slug']), :class => 'button delete', :method => 'delete', :data => {:confirm => "Are you sure you want to delete this #{Kilt::Formatting.singular_name_of(@type)}?" } %>
60
60
  </td>
61
61
  </tr>
62
62
  <% end %>
@@ -5,7 +5,7 @@
5
5
  <meta charset="utf-8">
6
6
  <title><%= Kilt.config.name %></title>
7
7
 
8
- <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,800,300" rel="stylesheet" type="text/css">
8
+ <link href='http://fonts.googleapis.com/css?family=Oswald:400,700,300' rel='stylesheet' type='text/css'>
9
9
  <%= stylesheet_link_tag "kilt/application", :media => "all" %>
10
10
 
11
11
  <%= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/codemirror.min.js" %>
@@ -15,15 +15,26 @@
15
15
  <%= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/mode/htmlmixed/htmlmixed.min.js" %>
16
16
 
17
17
  <%= javascript_include_tag "kilt/application" %>
18
+
18
19
  <%= csrf_meta_tags %>
20
+
21
+ <%= render partial: 'kilt/kilt/field_setup', locals: { type: 'head' } %>
19
22
  </head>
20
23
  <body>
21
24
 
22
25
  <%= render :partial => 'layouts/kilt/cms/menu' %>
23
26
 
24
27
  <section class="body">
28
+ <%= render :partial => 'layouts/kilt/cms/default_creds_warning' %>
25
29
  <%= yield %>
26
30
  </section>
27
31
 
32
+ <footer>
33
+ <div class="icon">
34
+ <%= link_to image_tag('kilt/logo.png'), 'http://github.com/kilt-cms/kilt-cms', :target => '_blank' %>
35
+ </div>
36
+ </footer>
37
+
38
+ <%= render partial: 'kilt/kilt/field_setup', locals: { type: 'foot' } %>
28
39
  </body>
29
40
  </html>
@@ -0,0 +1,4 @@
1
+ <% return unless @show_default_creds_warning %>
2
+ <div class="wr">
3
+ <h4 style="text-align:center;color:red">You are still using the default username/password.<br />We strongly recommend that you change it in your config/kilt/creds.yml file.</h4>
4
+ </div>
@@ -1,12 +1,6 @@
1
1
  <header class="hd">
2
2
  <div class="wr">
3
3
  <h6><a href="<%= kilt_engine.root_path %>"><%= Kilt.config.name %></a></h6>
4
- <a class="button small dashboard" href="<%= kilt_engine.root_path %>">Dashboard</a>
5
- <% Kilt.types.each do |type| %>
6
- <%
7
- plural = Kilt::Formatting.plural_name_of type
8
- %>
9
- <%= link_to plural, list_path(type.pluralize), class: "button small dashboard" %>
10
- <% end %>
4
+ <a class="button dashboard home" href="<%= kilt_engine.root_path %>">Admin Home</a>
11
5
  </div>
12
6
  </header>
@@ -22,7 +22,6 @@ module Kilt
22
22
 
23
23
  def add_the_credential_file_examples
24
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
25
  end
27
26
 
28
27
  def add_the_database_migration_file
@@ -12,5 +12,9 @@ s3:
12
12
  secret: <S3 secret>
13
13
  bucket: <S3 bucket>
14
14
  auth:
15
- username: <Username>
16
- password: <Password>
15
+ username: admin
16
+ password: changeme
17
+ default_auth:
18
+ username: admin
19
+ password: changeme
20
+ note: "Feel free to remove default_auth when you change your username/password"
@@ -1,9 +1,6 @@
1
1
  require "kilt/base"
2
2
  require_relative "kilt_object"
3
-
4
- # Include the Rethink shortcut module, which will among other things instantiate a new
5
- # Rethink object (as "r") if needed
6
- include RethinkDB::Shortcuts
3
+ require_relative "kilt_view_model"
7
4
 
8
5
  module Kilt
9
6
 
@@ -41,7 +38,7 @@ module Kilt
41
38
  object['created_at'] = object['updated_at'] = Time.now
42
39
  object['unique_id'] = "#{(Time.now.to_f * 1000).to_i}"
43
40
  object['type'] = object.instance_eval { @type }
44
- object['slug'] = slug_for object
41
+ object['slug'] = Slugger.slug_for object
45
42
 
46
43
  Utils.database.create object
47
44
  end
@@ -51,7 +48,7 @@ module Kilt
51
48
  # Example: Kilt.update(object)
52
49
  def self.update(slug, object)
53
50
  object['updated_at'] = Time.now
54
- object['slug'] = slug_for object
51
+ object['slug'] = Slugger.slug_for object
55
52
 
56
53
  Utils.database.update object
57
54
  end
@@ -81,25 +78,20 @@ module Kilt
81
78
  Kilt::ObjectCollection.new results
82
79
  end
83
80
 
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']}"
93
- end
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
-
81
+ # Get every field type used
82
+ # Returns: Array of strings
83
+ # Example: Kilt.all_used_fields
84
+ def self.all_used_fields
85
+ used_field_types = Kilt.config[:objects].map do |object|
86
+ object.map do |config|
87
+ begin
88
+ config[:fields].map { |_, v| v }
89
+ rescue
90
+ nil
91
+ end
92
+ end
93
+ end.flatten
94
+ used_field_types.select { |x| x }.group_by { |x| x }.map { |x| x[0] }
102
95
  end
103
96
 
104
97
  end
105
-
@@ -6,8 +6,10 @@ require "kilt/object_collection"
6
6
 
7
7
  require 'kilt/upload'
8
8
 
9
- require "kilt/db/rethink_db"
10
9
  require "kilt/db/active_record"
11
10
  require "kilt/utils"
12
11
  require "kilt/form"
13
12
  require "kilt/formatting"
13
+ require "kilt/slugger"
14
+ require "kilt/upload/s3"
15
+ require "kilt/upload/local"
@@ -1,5 +1,4 @@
1
1
  require 'rubygems'
2
- require 'rethinkdb'
3
2
  require 'rails_config'
4
3
  require 'jquery-rails'
5
4
  require 'jquery-ui-rails'
@@ -14,4 +13,4 @@ module Kilt
14
13
  config.generators.test_framework :rspec
15
14
 
16
15
  end
17
- end
16
+ end
@@ -43,7 +43,7 @@ module Kilt
43
43
  def the_value_for(key, field_type, params)
44
44
  if params["#{key}-hidden"] == 'clear' && !params[key]
45
45
  ''
46
- elsif ['file', 'image'].include? field_type
46
+ elsif Kilt::Upload.uploadable_fields.include? field_type
47
47
  Kilt::Upload.send field_type, params[key]
48
48
  else
49
49
  params[key]
@@ -0,0 +1,55 @@
1
+ module Kilt
2
+
3
+ module Slugger
4
+
5
+ def self.slug_for object
6
+ slug = possibly_duplicate_slug_for object
7
+ slug_is_unique_for?(slug, object) ? slug
8
+ : make_slug_unique(slug)
9
+ end
10
+
11
+ class << self
12
+
13
+ def slug_is_unique_for? slug, object
14
+ result = Utils.database.find(slug)
15
+ return true if result.nil?
16
+
17
+ "#{result['unique_id']}" == "#{object['unique_id']}"
18
+ end
19
+
20
+ def make_slug_unique slug
21
+ "#{slug}-#{(Time.now.to_f * 1000).to_i}"
22
+ end
23
+
24
+ def possibly_duplicate_slug_for object
25
+ if object['slug'].to_s.strip == ''
26
+ if prefix = prefix_for(object)
27
+ "#{prefix}-#{slugified_value_for(object)}"
28
+ else
29
+ slugified_value_for(object)
30
+ end
31
+ else
32
+ "#{object['slug']}"
33
+ end
34
+ end
35
+
36
+ def slugified_value_for object
37
+ Utils.slugify(object['name'])
38
+ end
39
+
40
+ def prefix_for object
41
+ return nil unless prefix = lookup_the_suggested_prefix_for(object)
42
+ slug = slugified_value_for object
43
+ slug.starts_with?(prefix) && slug != prefix ? nil
44
+ : prefix
45
+ end
46
+
47
+ def lookup_the_suggested_prefix_for object
48
+ Kilt.send(object['type'].to_sym)['slug_prefix']
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -1,54 +1,26 @@
1
1
  module Kilt
2
- class Upload
3
-
4
- def self.file(file_reference)
5
- self.do('file', file_reference)
6
- end
7
-
8
- def self.image(file_reference)
9
- self.do('image', file_reference)
2
+ module Upload
3
+
4
+ def self.uploadable_fields
5
+ types = ['file', 'image'] + Kilt.config.uploadable_fields.to_s.split(',').map { |x| x.strip }
6
+ types.group_by { |x| x }.map { |x| x[0] }
10
7
  end
11
8
 
12
9
  def self.do(type, file_reference)
13
- if Kilt.config.storage.strategy == 'local'
14
- self.handle_local_upload(type, file_reference)
15
- elsif Kilt.config.storage.strategy == 's3'
16
- self.handle_s3_upload(type, file_reference)
17
- end
18
- end
19
-
20
- private
21
-
22
- def self.handle_local_upload(type, file_reference)
23
- Kilt::Utils.ensure_local_storage_dir_exists
24
- if file_reference
25
- File.open(Rails.root.join('public', 'uploads', type, file_reference.original_filename), 'wb') do |file|
26
- file.write(file_reference.read)
27
- end
28
- file_reference.original_filename
29
- else
30
- ''
31
- end
10
+ uploader = begin
11
+ strategy = Kilt.config.storage.strategy.to_s
12
+ "Kilt::Upload::#{strategy.classify}".constantize
13
+ rescue
14
+ nil
15
+ end
16
+ uploader.upload(type, file_reference) if uploader
32
17
  end
33
-
34
- def self.handle_s3_upload(type, file_reference)
35
- Kilt::Utils.ensure_s3_bucket_exists
36
- if file_reference
37
- begin
38
- s3 = AWS::S3.new(
39
- :access_key_id => Kilt.config.s3.key,
40
- :secret_access_key => Kilt.config.s3.secret)
41
- bucket = s3.buckets[Kilt.config.s3.bucket]
42
- new_file = bucket.objects["#{type}/#{file_reference.original_filename}"]
43
- new_file.write(Pathname.new(file_reference.tempfile), :acl => :public_read)
44
- file_reference.original_filename
45
- rescue
46
- ''
47
- end
48
- else
49
- ''
18
+
19
+ class << self
20
+ def method_missing(meth, *args, &blk)
21
+ self.do meth.to_s, args[0]
50
22
  end
51
23
  end
52
-
24
+
53
25
  end
54
- end
26
+ end
@@ -0,0 +1,17 @@
1
+ module Kilt
2
+ module Upload
3
+ module Local
4
+ def self.upload type, file_reference
5
+ Kilt::Utils.ensure_local_storage_dir_exists
6
+ if file_reference
7
+ File.open(Rails.root.join('public', 'uploads', type, file_reference.original_filename), 'wb') do |file|
8
+ file.write(file_reference.read)
9
+ end
10
+ file_reference.original_filename
11
+ else
12
+ ''
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end