rich_cms 2.1.7 → 3.0.0

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 (179) hide show
  1. data/{CHANGELOG → CHANGELOG.rdoc} +24 -0
  2. data/README.textile +49 -33
  3. data/Rakefile +92 -10
  4. data/VERSION +1 -1
  5. data/app/controllers/rich/cms_controller.rb +10 -39
  6. data/app/controllers/rich/cms_sessions_controller.rb +31 -0
  7. data/app/views/rich/cms/dock/_menu.html.erb +10 -8
  8. data/app/views/rich/cms/dock/_panel.html.erb +1 -1
  9. data/app/views/rich/cms/dock/panel/edit/_rails2.html.erb +5 -3
  10. data/app/views/rich/cms/dock/panel/edit/_rails3.html.erb +4 -2
  11. data/app/views/rich/cms/dock/panel/login/_rails2.html.erb +18 -12
  12. data/app/views/rich/cms/dock/panel/login/_rails3.html.erb +18 -12
  13. data/app/views/rich_cms.html.erb +1 -1
  14. data/assets/jzip/jquery/cleditor.js +1132 -1132
  15. data/assets/jzip/jquery/extensions/browser_detect.js +1 -2
  16. data/assets/jzip/native/extensions.js +41 -0
  17. data/assets/jzip/rich/cms/editor.js +41 -7
  18. data/assets/jzip/rich_cms.jz +2 -1
  19. data/assets/sass/rich_cms/_panel.sass +11 -1
  20. data/config/routes.rb +12 -11
  21. data/lib/generators/rich/cms_admin/cms_admin_generator.rb +82 -0
  22. data/lib/generators/rich/{authlogic_user/templates → cms_admin/templates/authlogic}/migration.rb +0 -0
  23. data/lib/generators/rich/{authlogic_user/templates → cms_admin/templates/authlogic}/model.rb +0 -0
  24. data/lib/generators/rich/{authlogic_user/templates → cms_admin/templates/authlogic}/session.rb +0 -0
  25. data/lib/rich/cms/actionpack/action_controller/base.rb +3 -44
  26. data/lib/rich/cms/actionpack/action_view/base.rb +32 -10
  27. data/lib/rich/cms/actionpack.rb +1 -2
  28. data/lib/rich/cms/auth.rb +110 -0
  29. data/lib/rich/cms/content/group.rb +1 -2
  30. data/lib/rich/cms/content/item.rb +2 -3
  31. data/lib/rich/cms/core/string/html_safe.rb +1 -2
  32. data/lib/rich/cms/core/string.rb +1 -2
  33. data/lib/rich/cms/engine.rb +23 -51
  34. data/lib/rich/cms/rails/engine.rb +1 -2
  35. data/lib/rich/cms/version.rb +11 -0
  36. data/lib/rich_cms.rb +2 -2
  37. data/rails_generators/rich_cms_admin/lib/devise/route_devise.rb +32 -0
  38. data/rails_generators/rich_cms_admin/rich_cms_admin_generator.rb +113 -0
  39. data/rails_generators/{rich_authlogic_user/templates → rich_cms_admin/templates/authlogic}/migration.rb +0 -0
  40. data/rails_generators/{rich_authlogic_user/templates → rich_cms_admin/templates/authlogic}/model.rb +0 -0
  41. data/rails_generators/{rich_authlogic_user/templates → rich_cms_admin/templates/authlogic}/session.rb +0 -0
  42. data/rails_generators/{rich_authlogic_user → rich_cms_admin}/templates/config.rb +0 -0
  43. data/rails_generators/rich_cms_admin/templates/devise/README +23 -0
  44. data/rails_generators/rich_cms_admin/templates/devise/devise.rb +105 -0
  45. data/rails_generators/rich_cms_admin/templates/devise/en.yml +35 -0
  46. data/rails_generators/rich_cms_admin/templates/devise/migration.rb +23 -0
  47. data/rails_generators/rich_cms_admin/templates/devise/model.rb +9 -0
  48. data/rails_generators/rich_cms_content/rich_cms_content_generator.rb +18 -12
  49. data/rich_cms.gemspec +295 -105
  50. data/test/integrator.rb +89 -0
  51. data/test/rails-2/dummy/.bundle/config +2 -0
  52. data/test/rails-2/dummy/Gemfile +15 -0
  53. data/test/rails-2/dummy/Gemfile.lock +97 -0
  54. data/test/rails-2/dummy/Rakefile +10 -0
  55. data/test/rails-2/dummy/app/controllers/application_controller.rb +10 -0
  56. data/test/rails-2/dummy/app/helpers/application_helper.rb +3 -0
  57. data/test/rails-2/dummy/config/boot.rb +124 -0
  58. data/test/rails-2/dummy/config/database.yml +23 -0
  59. data/test/rails-2/dummy/config/environment.rb +41 -0
  60. data/test/rails-2/dummy/config/environments/development.rb +17 -0
  61. data/test/rails-2/dummy/config/environments/production.rb +28 -0
  62. data/test/rails-2/dummy/config/environments/test.rb +28 -0
  63. data/test/rails-2/dummy/config/initializers/backtrace_silencers.rb +7 -0
  64. data/test/rails-2/dummy/config/initializers/cookie_verification_secret.rb +7 -0
  65. data/test/rails-2/dummy/config/initializers/devise.rb +105 -0
  66. data/test/rails-2/dummy/config/initializers/enrichments.rb +5 -0
  67. data/test/rails-2/dummy/config/initializers/inflections.rb +10 -0
  68. data/test/rails-2/dummy/config/initializers/mime_types.rb +5 -0
  69. data/test/rails-2/dummy/config/initializers/new_rails_defaults.rb +21 -0
  70. data/test/rails-2/dummy/config/initializers/session_store.rb +15 -0
  71. data/test/rails-2/dummy/config/locales/en.yml +5 -0
  72. data/test/rails-2/dummy/config/preinitializer.rb +20 -0
  73. data/test/rails-2/dummy/config/routes.rb +44 -0
  74. data/test/rails-2/dummy/db/schema.rb +49 -0
  75. data/test/rails-2/dummy/db/seeds.rb +10 -0
  76. data/test/rails-2/dummy/public/404.html +30 -0
  77. data/test/rails-2/dummy/public/422.html +30 -0
  78. data/test/rails-2/dummy/public/500.html +30 -0
  79. data/test/rails-2/dummy/public/favicon.ico +0 -0
  80. data/test/rails-2/dummy/public/images/rails.png +0 -0
  81. data/test/rails-2/dummy/public/images/rich/cms/cleditor/buttons.gif +0 -0
  82. data/test/rails-2/dummy/public/images/rich/cms/cleditor/toolbar.gif +0 -0
  83. data/test/rails-2/dummy/public/javascripts/jquery/core.js +158 -0
  84. data/test/rails-2/dummy/public/javascripts/jquery/ui/rich_cms/core.js +1207 -0
  85. data/test/rails-2/dummy/public/javascripts/jquery/ui/rich_cms/draggable.js +798 -0
  86. data/test/rails-2/dummy/public/javascripts/jquery/ui/rich_cms/mouse.js +950 -0
  87. data/test/rails-2/dummy/public/javascripts/jquery/ui/rich_cms/widget.js +1188 -0
  88. data/test/rails-2/dummy/public/javascripts/rich_cms.js +1746 -0
  89. data/test/rails-2/dummy/public/robots.txt +5 -0
  90. data/test/rails-2/dummy/script/about +4 -0
  91. data/test/rails-2/dummy/script/console +3 -0
  92. data/test/rails-2/dummy/script/dbconsole +3 -0
  93. data/test/rails-2/dummy/script/destroy +3 -0
  94. data/test/rails-2/dummy/script/generate +3 -0
  95. data/test/rails-2/dummy/script/performance/benchmarker +3 -0
  96. data/test/rails-2/dummy/script/performance/profiler +3 -0
  97. data/test/rails-2/dummy/script/plugin +3 -0
  98. data/test/rails-2/dummy/script/runner +3 -0
  99. data/test/rails-2/dummy/script/server +3 -0
  100. data/test/rails-2/dummy/test/fixtures/authlogic_users.yml +6 -0
  101. data/test/rails-2/dummy/test/fixtures/devise_users.yml +5 -0
  102. data/test/rails-2/pending.rb +88 -0
  103. data/test/rails-2/test_helper.rb +13 -0
  104. data/test/rails-3/dummy/.bundle/config +2 -0
  105. data/test/rails-3/dummy/Gemfile +15 -0
  106. data/test/rails-3/dummy/Gemfile.lock +139 -0
  107. data/test/rails-3/dummy/Rakefile +7 -0
  108. data/test/rails-3/dummy/app/controllers/application_controller.rb +3 -0
  109. data/test/rails-3/dummy/app/helpers/application_helper.rb +2 -0
  110. data/test/rails-3/dummy/config/application.rb +42 -0
  111. data/test/rails-3/dummy/config/boot.rb +13 -0
  112. data/test/rails-3/dummy/config/database.yml +23 -0
  113. data/test/rails-3/dummy/config/environment.rb +5 -0
  114. data/test/rails-3/dummy/config/environments/development.rb +26 -0
  115. data/test/rails-3/dummy/config/environments/production.rb +49 -0
  116. data/test/rails-3/dummy/config/environments/test.rb +35 -0
  117. data/test/rails-3/dummy/config/initializers/backtrace_silencers.rb +7 -0
  118. data/test/rails-3/dummy/config/initializers/devise.rb +142 -0
  119. data/test/rails-3/dummy/config/initializers/enrichments.rb +5 -0
  120. data/test/rails-3/dummy/config/initializers/inflections.rb +10 -0
  121. data/test/rails-3/dummy/config/initializers/mime_types.rb +5 -0
  122. data/test/rails-3/dummy/config/initializers/secret_token.rb +7 -0
  123. data/test/rails-3/dummy/config/initializers/session_store.rb +8 -0
  124. data/test/rails-3/dummy/config/locales/en.yml +5 -0
  125. data/test/rails-3/dummy/config/routes.rb +59 -0
  126. data/test/rails-3/dummy/config.ru +4 -0
  127. data/test/rails-3/dummy/db/schema.rb +49 -0
  128. data/test/rails-3/dummy/db/seeds.rb +10 -0
  129. data/test/rails-3/dummy/public/404.html +26 -0
  130. data/test/rails-3/dummy/public/422.html +26 -0
  131. data/test/rails-3/dummy/public/500.html +26 -0
  132. data/test/rails-3/dummy/public/favicon.ico +0 -0
  133. data/test/rails-3/dummy/public/images/rich/cms/cleditor/buttons.gif +0 -0
  134. data/test/rails-3/dummy/public/images/rich/cms/cleditor/toolbar.gif +0 -0
  135. data/test/rails-3/dummy/public/javascripts/jquery/core.js +158 -0
  136. data/test/rails-3/dummy/public/javascripts/jquery/ui/rich_cms/core.js +1207 -0
  137. data/test/rails-3/dummy/public/javascripts/jquery/ui/rich_cms/draggable.js +798 -0
  138. data/test/rails-3/dummy/public/javascripts/jquery/ui/rich_cms/mouse.js +950 -0
  139. data/test/rails-3/dummy/public/javascripts/jquery/ui/rich_cms/widget.js +1188 -0
  140. data/test/rails-3/dummy/public/javascripts/rich_cms.js +1746 -0
  141. data/test/rails-3/dummy/script/rails +6 -0
  142. data/test/rails-3/dummy/test/fixtures/authlogic_users.yml +6 -0
  143. data/test/rails-3/dummy/test/fixtures/devise_users.yml +5 -0
  144. data/test/rails-3/test_helper.rb +17 -0
  145. data/test/shared/dummy/db/schema.rb +49 -0
  146. data/test/shared/dummy/db/seeds.rb +10 -0
  147. data/test/shared/dummy/fixtures/authlogic_users.yml +6 -0
  148. data/test/shared/dummy/models/authlogic_user.rb +8 -0
  149. data/test/shared/dummy/models/authlogic_user_session.rb +10 -0
  150. data/test/shared/dummy/models/cms_content.rb +2 -0
  151. data/test/shared/dummy/models/devise_user.rb +3 -0
  152. data/test/shared/dummy/stylesheets/app.css +100 -0
  153. data/test/shared/dummy/stylesheets/rich_cms.css +159 -0
  154. data/test/shared/dummy/views/application/index.html.erb +13 -0
  155. data/test/shared/dummy/views/layouts/application.html.erb +12 -0
  156. data/test/shared/support/action_controller/integration.rb +55 -0
  157. data/test/shared/support/action_controller/test_case.rb +28 -0
  158. data/test/shared/support/capybara/setup.rb +14 -0
  159. data/test/shared/support/test_helper.rb +1 -0
  160. data/test/shared/tests/actionpack/action_controller/base_test.rb +14 -0
  161. data/test/shared/tests/actionpack/action_view/base_test.rb +19 -0
  162. data/test/shared/tests/activesupport/active_support/dependencies_test.rb +15 -0
  163. data/test/shared/tests/app/integration/authenticated/authlogic.rb +88 -0
  164. data/test/shared/tests/app/integration/authenticated/devise_test.rb +89 -0
  165. data/test/shared/tests/app/integration/non_authenticated.rb +63 -0
  166. data/test/shared/tests/app/routing_test.rb +31 -0
  167. data/test/shared/tests/auth_test.rb +11 -0
  168. data/test/shared/tests/content/group.rb +10 -0
  169. data/test/shared/tests/content/item.rb +10 -0
  170. data/test/shared/tests/core/string/html_safe.rb +15 -0
  171. data/test/shared/tests/dummy_app.rb +228 -0
  172. data/test/shared/tests/engine_test.rb +19 -0
  173. data/test/shared/tests/rails/engine_test.rb +13 -0
  174. data/test/shared/tests/readme_test.rb +13 -0
  175. metadata +231 -63
  176. data/.gitignore +0 -2
  177. data/lib/generators/rich/authlogic_user/authlogic_user_generator.rb +0 -64
  178. data/rails_generators/rich_authlogic_user/rich_authlogic_user_generator.rb +0 -64
  179. data/test/test_helper.rb +0 -6
@@ -1,8 +1,7 @@
1
-
2
1
  $.extend({
3
2
  ie: jQuery.browser.msie,
4
3
  ie6: jQuery.browser.msie && parseInt(jQuery.browser.version, 10) == 6,
5
4
  ie7: jQuery.browser.msie && parseInt(jQuery.browser.version, 10) == 7,
6
5
  ie8: jQuery.browser.msie && parseInt(jQuery.browser.version, 10) == 8,
7
6
  ff2: jQuery.browser.mozilla && parseFloat(jQuery.browser.version) < 1.9
8
- });
7
+ });
@@ -0,0 +1,41 @@
1
+ /* Implement indexOf ourselves as IE does not support it */
2
+ if (!Array.prototype.indexOf)
3
+ {
4
+ Array.prototype.indexOf = function(searchElement /*, fromIndex */)
5
+ {
6
+ "use strict";
7
+
8
+ if (this === void 0 || this === null)
9
+ throw new TypeError();
10
+
11
+ var t = Object(this);
12
+ var len = t.length >>> 0;
13
+ if (len === 0)
14
+ return -1;
15
+
16
+ var n = 0;
17
+ if (arguments.length > 0)
18
+ {
19
+ n = Number(arguments[1]);
20
+ if (n !== n)
21
+ n = 0;
22
+ else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0))
23
+ n = (n > 0 || -1) * Math.floor(Math.abs(n));
24
+ }
25
+
26
+ if (n >= len)
27
+ return -1;
28
+
29
+ var k = n >= 0
30
+ ? n
31
+ : Math.max(len - Math.abs(n), 0);
32
+
33
+ for (; k < len; k++)
34
+ {
35
+ if (k in t && t[k] === searchElement)
36
+ return k;
37
+ }
38
+ return -1;
39
+ };
40
+ }
41
+
@@ -11,6 +11,12 @@ Rich.Cms.Editor = (function() {
11
11
  };
12
12
 
13
13
  var bind = function() {
14
+ $("#rich_cms_panel .edit form fieldset.inputs div.keys a.toggler").live("click", function(event) {
15
+ event.preventDefault();
16
+ var toggler = $(event.target);
17
+ toggler.hide().closest(".keys").find("select[name=" + toggler.attr("data-name") + "]").show();
18
+ });
19
+
14
20
  $("#rich_cms_panel .edit a.close").bind("click", function(event) {
15
21
  event.preventDefault();
16
22
  RaccoonTip.close();
@@ -18,7 +24,7 @@ Rich.Cms.Editor = (function() {
18
24
 
19
25
  RaccoonTip.register("." + content_class + "." + mark_class, "#rich_cms_panel", {
20
26
  beforeShow: edit,
21
- canHide: function() { return !$("#cleditor_input").length },
27
+ canHide: function() { return !$("#cleditor_input").length; },
22
28
  afterHide: function(content) { content.hide(); }
23
29
  });
24
30
 
@@ -67,7 +73,7 @@ Rich.Cms.Editor = (function() {
67
73
 
68
74
  var edit = function() {
69
75
  var content_item = $(this).closest(".rich_cms_content");
70
- var label = $("#rich_cms_panel .edit form fieldset.inputs label");
76
+ var keys = $("#rich_cms_panel .edit form fieldset.inputs div.keys");
71
77
  var inputs = $("#rich_cms_panel .edit form fieldset.inputs");
72
78
 
73
79
  var attrs = content_item.get(0).attributes;
@@ -76,8 +82,7 @@ Rich.Cms.Editor = (function() {
76
82
  })[0];
77
83
  var specs = editable_content[selector];
78
84
 
79
- label.html("Editing:&nbsp; " + $.map(specs.keys, function(key) { return "<strong>" + content_item.attr(key) + "</strong>"; }).join(", "));
80
-
85
+ keys.find("select,a,span").remove();
81
86
  inputs.find(":input,div.cleditorMain").remove();
82
87
  inputs.append("<input name='content_item[__selector__]' type='hidden' value='" + selector + "'/>");
83
88
 
@@ -99,11 +104,40 @@ Rich.Cms.Editor = (function() {
99
104
  case "html":
100
105
  inputs.append("<textarea id='cleditor_input' name='" + name + "' style='width: 500px; height: 300px'>" + value + "</textarea>"); break;
101
106
  }
107
+ } else if (specs.keys.indexOf(attr) != -1) {
108
+ var available_keys = $.map(value.split(","), function(key) { return $.trim(key); });
109
+ var default_key = available_keys[0];
110
+
111
+ if (specs.keys.length > 1 && keys.find("select").length > 0) {
112
+ keys.append("<span>, <span>");
113
+ }
114
+
115
+ keys.append(available_keys.length == 1 ?
116
+ "<span>" + default_key + "<span>" :
117
+ "<a href='#' class='toggler' data-attr='" + attr + "' data-name='" + name + "'>" + default_key + "</a>");
118
+ keys.append("<select name='" + name + "' style='display: none'>" +
119
+ $.map(available_keys, function(key) { return "<option value='" + key + "'>" + key + "</option>"; }).join("") +
120
+ "</select>");
102
121
  } else {
103
122
  inputs.append("<input name='" + name + "' type='hidden' value='" + value + "'/>");
104
123
  }
105
124
  }
106
125
  });
126
+
127
+ $("#rich_cms_panel .edit form fieldset.inputs div.keys select").bind("blur", function(event) {
128
+ var select = $(event.target);
129
+ var toggler = select.hide().closest(".keys").find(".toggler[data-name=" + select.attr("name") + "]").html(select.val()).show();
130
+ var values = [select.val()];
131
+
132
+ $.map(select.find("option"), function(option) {
133
+ var value = $(option).val();
134
+ if (value != values[0]) {
135
+ values.push(value);
136
+ }
137
+ });
138
+
139
+ content_item.attr(toggler.attr("data-attr"), values.join(", "));
140
+ });
107
141
 
108
142
  if (specs.beforeEdit) {
109
143
  var identifier = $.map(specs.keys, function(key) { return "[" + key + "=" + content_item.attr(key) + "]"; }).join("");
@@ -114,10 +148,10 @@ Rich.Cms.Editor = (function() {
114
148
 
115
149
  setTimeout(function() {
116
150
  if ($("#cleditor_input").length) {
117
- $("#cleditor_input").cleditor({
151
+ $("#cleditor_input").data("cleditor", $("#cleditor_input").cleditor({
118
152
  width : 500,
119
153
  height: 300
120
- })[0].focus();
154
+ })[0].focus());
121
155
  }
122
156
  }, 250);
123
157
  };
@@ -125,7 +159,7 @@ Rich.Cms.Editor = (function() {
125
159
  var afterUpdate = function(form, response) {
126
160
  var selector = response["__selector__"];
127
161
  var specs = editable_content[selector];
128
- var identifier = $.map(specs.keys, function(key) { return "[" + key + "=" + response["__identifier__"][key.replace(/^data-/, "")] + "]"; }).join("");
162
+ var identifier = $.map(specs.keys, function(key) { return "[" + key + "^=" + response["__identifier__"][key.replace(/^data-/, "")] + "]"; }).join("");
129
163
 
130
164
  var defaultFunction = function(form, response, selector, specs, identifier) {
131
165
  $(identifier).html(response[specs.value.replace(/^data-/, "")]);
@@ -1,5 +1,6 @@
1
-
2
1
  var onRaccoonTipReady = function() {
2
+ //= require native/extensions
3
+
3
4
  //= require jquery/extensions/ajaxify
4
5
  //= require jquery/extensions/modules
5
6
  //= require jquery/extensions/object
@@ -20,9 +20,19 @@
20
20
  list-style: none
21
21
 
22
22
  .inputs
23
+
24
+ div.keys
25
+ min-height: 21px
26
+ label
27
+ +inline
28
+ a, span
29
+ font-size: 12px
30
+ font-weight: bold
31
+ select
32
+ margin-right: 4px
33
+
23
34
  label
24
35
  font-size: 12px
25
- +block
26
36
  abbr
27
37
  padding-left: 2px
28
38
  border: 0
data/config/routes.rb CHANGED
@@ -2,12 +2,14 @@ if Rails::VERSION::MAJOR >= 3
2
2
 
3
3
  Rails.application.routes.draw do
4
4
  scope :module => "rich" do
5
- %w(login logout update).each do |action|
5
+ match "/cms/" => "cms#display" , :as => "rich_cms" , :display => true
6
+ match "/cms/hide" => "cms#display" , :as => "rich_cms_hide", :display => false
7
+ %w(login logout).each do |action|
8
+ match "/cms/#{action}" => "cms_sessions##{action}", :as => "rich_cms_#{action}"
9
+ end
10
+ %w(position update).each do |action|
6
11
  match "/cms/#{action}" => "cms##{action}", :as => "rich_cms_#{action}"
7
12
  end
8
- match "/cms/" => "cms#display", :as => "rich_cms" , :display => true
9
- match "/cms/hide" => "cms#display", :as => "rich_cms_hide", :display => false
10
- match "/cms/position" => "cms#position"
11
13
  end
12
14
  end
13
15
 
@@ -21,15 +23,14 @@ else
21
23
 
22
24
  ActionController::Routing::Routes.draw do |map|
23
25
  map.namespace :rich, :path_prefix => "" do |rich|
24
-
25
- %w(login logout update).each do |action|
26
+ rich.cms "cms" , :controller => "cms", :action => "display", :display => true
27
+ rich.cms_hide "cms/hide", :controller => "cms", :action => "display", :display => false
28
+ %w(login logout).each do |action|
29
+ rich.send "cms_#{action}", "cms/#{action}", :controller => "cms_sessions", :action => action
30
+ end
31
+ %w(position update).each do |action|
26
32
  rich.send "cms_#{action}", "cms/#{action}", :controller => "cms", :action => action
27
33
  end
28
-
29
- rich.cms "cms" , :controller => "cms", :action => "display", :display => true
30
- rich.cms_hide "cms/hide" , :controller => "cms", :action => "display", :display => false
31
- rich.connect "cms/position", :controller => "cms", :action => "position"
32
-
33
34
  end
34
35
  end
35
36
 
@@ -0,0 +1,82 @@
1
+ require "generators/rich_cms"
2
+
3
+ module Rich
4
+ module Generators
5
+
6
+ class CmsAdminGenerator < ::RichCms::Generators::Base
7
+
8
+ include Rails::Generators::Migration
9
+ include RichCms::Generators::Migration
10
+
11
+ desc "Creates Devise / Authlogic model and configures your Rails application for Rich-CMS authentication."
12
+ argument :model_name, :type => :string , :default => "user"
13
+ class_option :bundle , :type => :string , :default => false, :aliases => "-b", :desc => "Add Devise or Authlogic to Gemfile and run 'bundle install'."
14
+ class_option :devise , :type => :boolean, :default => true , :aliases => "-d", :desc => "Use Devise as authentication logic (this is default)."
15
+ class_option :authlogic , :type => :boolean, :default => false, :aliases => "-a", :desc => "Use Authlogic as authentication logic."
16
+ class_option :migrate , :type => :boolean, :default => false, :aliases => "-m", :desc => "Run 'rake db:migrate' after generating model and migration."
17
+
18
+ def derive_authentication_logic
19
+ @logic = "Devise"
20
+ @logic = "Authlogic" if options[:authlogic]
21
+ end
22
+
23
+ def register_authentication
24
+ filename = "config/initializers/enrichments.rb"
25
+ line = "Rich::Cms::Auth.setup do |config|"
26
+
27
+ create_file filename unless File.exists?(filename)
28
+ return if File.open(filename).readlines.collect(&:strip).include? line.strip
29
+
30
+ File.open(filename, "a+") do |file|
31
+ file << "#{line}\n"
32
+ file << " config.logic = :#{@logic.underscore}\n"
33
+ file << " config.klass = \"#{model_class_name}\"\n"
34
+ file << "end"
35
+ end
36
+ end
37
+
38
+ def generate_authenticated_model
39
+ if options[:bundle]
40
+ gem @logic.underscore, {"devise" => "~> 1.1.5", "authlogic" => "~> 2.1.6"}[@logic.underscore]
41
+ run "bundle install"
42
+ end
43
+ send :"generate_#{@logic.underscore}_assets"
44
+ end
45
+
46
+ def migrate
47
+ rake "db:migrate" if options[:migrate]
48
+ end
49
+
50
+ protected
51
+
52
+ def generate_devise_assets
53
+ generate "devise:install"
54
+ generate "devise", model_class_name
55
+ end
56
+
57
+ def generate_authlogic_assets
58
+ template "authlogic/model.rb" , "app/models/#{model_file_name}.rb"
59
+ template "authlogic/session.rb" , "app/models/#{model_file_name}_session.rb"
60
+ migration_template "authlogic/migration.rb", "db/migrate/create_#{table_name}"
61
+ end
62
+
63
+ def model_file_name
64
+ model_name.underscore
65
+ end
66
+
67
+ def model_class_name
68
+ model_name.classify
69
+ end
70
+
71
+ def migration_class_name
72
+ migration_file_name.pluralize.camelize
73
+ end
74
+
75
+ def table_name
76
+ model_file_name.underscore.gsub("/", "_").pluralize
77
+ end
78
+
79
+ end
80
+
81
+ end
82
+ end
@@ -1,14 +1,13 @@
1
-
2
1
  module ActionController
3
2
  class Base
4
3
 
5
4
  around_filter :prepare_rich_cms
6
5
 
7
6
  def prepare_rich_cms
8
- ::Rich::Cms::Engine.current_controller = self
7
+ ::Rich::Cms::Auth.current_controller = self
9
8
  yield
10
9
  ensure
11
- ::Rich::Cms::Engine.current_controller = nil
10
+ ::Rich::Cms::Auth.current_controller = nil
12
11
  end
13
12
 
14
13
  view_path = File.expand_path "../../../../../../app/views", __FILE__
@@ -18,45 +17,5 @@ module ActionController
18
17
  self.view_paths << view_path
19
18
  end
20
19
 
21
- helper_method :current_rich_cms_admin, :current_rich_cms_admin_name, :rich_cms_authenticated_class, :rich_cms_authentication_inputs
22
-
23
- def require_current_rich_cms_admin
24
- unless current_rich_cms_admin
25
- redirect_to root_url
26
- return false
27
- end
28
- end
29
-
30
- def current_rich_cms_admin
31
- case rich_cms_auth.logic
32
- when :authlogic
33
- return @current_rich_cms_admin if defined?(@current_rich_cms_admin)
34
- @current_rich_cms_admin_session ||= rich_cms_authenticated_class.find
35
- @current_rich_cms_admin = @current_rich_cms_admin_session.try rich_cms_auth.specs[:class_name].demodulize.underscore
36
- end
37
- end
38
-
39
- def current_rich_cms_admin_name
40
- current_rich_cms_admin[rich_cms_auth.specs[:identifier]] if current_rich_cms_admin
41
- end
42
-
43
- def rich_cms_auth
44
- ::Rich::Cms::Engine.authentication
45
- end
46
-
47
- def rich_cms_authenticated_class
48
- case rich_cms_auth.logic
49
- when :authlogic
50
- "#{rich_cms_auth.specs[:class_name]}Session".constantize
51
- end
52
- end
53
-
54
- def rich_cms_authentication_inputs
55
- case rich_cms_auth.logic
56
- when :authlogic
57
- rich_cms_auth.specs[:inputs] || [:email, :password]
58
- end
59
- end
60
-
61
20
  end
62
- end
21
+ end
@@ -1,23 +1,45 @@
1
-
2
1
  module ActionView
3
2
  class Base
4
3
 
5
4
  def rich_cms
6
- render :file => File.expand_path("../../../../../../app/views/rich_cms.html.erb", __FILE__) if display_rich_cms?
5
+ render :file => File.expand_path("../../../../../../app/views/rich_cms.html.erb", __FILE__) if !!session[:rich_cms].try(:fetch, :display, nil)
6
+ end
7
+
8
+ # //////////////////////////////////
9
+ # // Rich::Cms::Auth related
10
+ # //////////////////////////////////
11
+
12
+ def rich_cms_login_required?
13
+ Rich::Cms::Auth.login_required?
14
+ end
15
+
16
+ def rich_cms_admin_class
17
+ Rich::Cms::Auth.klass
7
18
  end
8
19
 
9
- def display_rich_cms?
10
- !!session[:rich_cms].try(:fetch, :display, nil)
20
+ def rich_cms_admin_inputs
21
+ Rich::Cms::Auth.inputs
11
22
  end
12
23
 
13
- def link(name, options = nil)
14
- options = {:class => options || name.underscore} unless options.is_a?(Hash)
15
- link_to name, "#", options
24
+ def current_rich_cms_admin
25
+ Rich::Cms::Auth.admin
26
+ end
27
+
28
+ def current_rich_cms_admin_label
29
+ Rich::Cms::Auth.admin_label
30
+ end
31
+
32
+ # //////////////////////////////////
33
+ # // Rich::Cms::Engine related
34
+ # //////////////////////////////////
35
+
36
+ def rich_cms_editable_content_javascript_hash
37
+ "{#{Rich::Cms::Engine.editable_content.collect{|k, v| v.to_javascript_hash}.join ", "}}".html_safe
16
38
  end
17
39
 
18
- def rich_cms_tag(*args)
19
- Rich::Cms::Engine.to_content_tag *args
40
+ def rich_cms_tag(selector, identifiers, options = {})
41
+ Rich::Cms::Engine.editable_content[selector].fetch(identifiers).to_tag options
20
42
  end
21
43
 
22
44
  end
23
- end
45
+ end
@@ -1,3 +1,2 @@
1
-
2
1
  require File.join(File.dirname(__FILE__), "actionpack", "action_controller", "base.rb")
3
- require File.join(File.dirname(__FILE__), "actionpack", "action_view" , "base.rb")
2
+ require File.join(File.dirname(__FILE__), "actionpack", "action_view" , "base.rb")
@@ -0,0 +1,110 @@
1
+ module Rich
2
+ module Cms
3
+ module Auth
4
+ mattr_accessor :current_controller
5
+
6
+ extend self
7
+
8
+ delegate :logic, :klass, :klass_symbol, :inputs, :to => :specs
9
+
10
+ def setup
11
+ @specs = Specs.new
12
+ yield specs
13
+ end
14
+
15
+ def enabled?
16
+ !!specs.logic
17
+ end
18
+
19
+ def login_required?
20
+ enabled? && admin.nil?
21
+ end
22
+
23
+ def login
24
+ case specs.logic
25
+ when :authlogic
26
+ user_session = "#{klass.name}Session".constantize.new params[klass_symbol]
27
+ user_session.save
28
+ when :devise
29
+ case Devise::VERSION
30
+ when "1.0.8", "1.0.9"
31
+ warden.authenticate(:scope => klass_symbol)
32
+ when "1.1.5"
33
+ begin
34
+ sessions = Devise.mappings[klass_symbol].controllers[:sessions]
35
+ Devise.mappings[klass_symbol].controllers[:sessions] = "rich/cms_sessions"
36
+ warden.authenticate(:scope => klass_symbol)
37
+ ensure
38
+ Devise.mappings[klass_symbol].controllers[:sessions] = sessions
39
+ end
40
+ end
41
+ end if enabled?
42
+ !!admin
43
+ end
44
+
45
+ def logout
46
+ case specs.logic
47
+ when :authlogic
48
+ user_session = "#{klass.name}Session".constantize.find
49
+ user_session.try :destroy
50
+ when :devise
51
+ sign_out klass_symbol
52
+ end if enabled?
53
+ session[:rich_cms] = nil
54
+ end
55
+
56
+ def admin
57
+ case specs.logic
58
+ when :authlogic
59
+ user_session = "#{klass.name}Session".constantize.find
60
+ user_session.try klass_symbol
61
+ when :devise
62
+ current_controller.try :send, specs.current_admin_method if enabled? && specs.current_admin_method
63
+ end if enabled?
64
+ end
65
+
66
+ def admin_label
67
+ (admin.try(:send, specs.identifier) if enabled?) || "Rich-CMS"
68
+ end
69
+
70
+ private
71
+
72
+ delegate :sign_out, :warden, :params, :session, :to => :current_controller
73
+
74
+ def specs
75
+ @specs ||= Specs.new
76
+ end
77
+
78
+ class Specs
79
+ attr_accessor :logic, :klass, :inputs, :identifier, :current_admin_method
80
+
81
+ def klass
82
+ return unless [:devise, :authlogic].include? logic
83
+ case @klass.class.name
84
+ when "String"
85
+ @klass.constantize
86
+ when "Class"
87
+ @klass
88
+ end
89
+ end
90
+
91
+ def klass_symbol
92
+ klass.name.underscore.gsub("/", "_").to_sym if klass
93
+ end
94
+
95
+ def inputs
96
+ @inputs || [:email, :password] if klass
97
+ end
98
+
99
+ def identifier
100
+ @identifier || inputs.first if klass
101
+ end
102
+
103
+ def current_admin_method
104
+ @current_admin_method || :"current_#{klass_symbol}" if klass
105
+ end
106
+ end
107
+
108
+ end
109
+ end
110
+ end
@@ -1,4 +1,3 @@
1
-
2
1
  module Rich
3
2
  module Cms
4
3
  module Content
@@ -65,4 +64,4 @@ module Rich
65
64
 
66
65
  end
67
66
  end
68
- end
67
+ end
@@ -1,4 +1,3 @@
1
-
2
1
  module Rich
3
2
  module Cms
4
3
  module Content
@@ -49,7 +48,7 @@ module Rich
49
48
  default = @group.identifiers.size == 1 ? @object.send(@group.identifiers.first) : @object.attributes.values_at(*@group.identifiers).inspect
50
49
  value = @object.send(@group.value)
51
50
 
52
- if Engine.can_render_metadata?
51
+ unless Auth.login_required?
53
52
  default = "< #{default} >"
54
53
  keys = @group.keys << @group.value.to_s
55
54
  data = @object.attributes.reject{|k, v| !keys.include?(k.to_s)}
@@ -73,4 +72,4 @@ module Rich
73
72
 
74
73
  end
75
74
  end
76
- end
75
+ end
@@ -1,4 +1,3 @@
1
-
2
1
  module Rich
3
2
  module Cms
4
3
  module Core
@@ -15,4 +14,4 @@ module Rich
15
14
  end
16
15
  end
17
16
  end
18
- end
17
+ end
@@ -1,6 +1,5 @@
1
-
2
1
  require "rich/cms/core/string/html_safe"
3
2
 
4
3
  class String
5
4
  include Rich::Cms::Core::String::HtmlSafe
6
- end
5
+ end