rich_cms 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/CHANGELOG +5 -0
- data/MIT-LICENSE +20 -0
- data/README.textile +158 -0
- data/Rakefile +43 -0
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/lib/app/controllers/rich/cms_controller.rb +56 -0
- data/lib/app/views/rich/cms/_bar.html.erb +4 -0
- data/lib/app/views/rich/cms/_config.html.erb +5 -0
- data/lib/app/views/rich/cms/bar/_menu.html.erb +16 -0
- data/lib/app/views/rich/cms/bar/_panel.html.erb +3 -0
- data/lib/app/views/rich/cms/bar/panel/_edit.html.erb +10 -0
- data/lib/app/views/rich/cms/bar/panel/_login.html.erb +11 -0
- data/lib/app/views/rich_cms.html.erb +5 -0
- data/lib/assets/jzip/jquery/core.js +168 -0
- data/lib/assets/jzip/jquery/extensions/ajaxify.js +26 -0
- data/lib/assets/jzip/jquery/extensions/modules.js +12 -0
- data/lib/assets/jzip/jquery/extensions/object.js +17 -0
- data/lib/assets/jzip/rich/cms/editor.js +118 -0
- data/lib/assets/jzip/rich/cms/login.js +12 -0
- data/lib/assets/jzip/rich/cms.js +2 -0
- data/lib/assets/jzip/rich.js +28 -0
- data/lib/assets/jzip/rich_cms.jz +10 -0
- data/lib/assets/sass/_bar.sass +45 -0
- data/lib/assets/sass/_editables.sass +6 -0
- data/lib/assets/sass/_mixins.sass +52 -0
- data/lib/assets/sass/rich_cms.sass +4 -0
- data/lib/config/routes.rb +17 -0
- data/lib/rich/cms/actionpack/action_controller/base.rb +61 -0
- data/lib/rich/cms/actionpack/action_view/base.rb +15 -0
- data/lib/rich/cms/actionpack.rb +3 -0
- data/lib/rich/cms/content/group.rb +63 -0
- data/lib/rich/cms/content/item.rb +70 -0
- data/lib/rich/cms/engine.rb +76 -0
- data/lib/rich_cms.rb +7 -0
- data/rails/init.rb +1 -0
- data/rich_cms.gemspec +92 -0
- data/tasks/rich_cms_tasks.rake +4 -0
- data/test/engine_test.rb +15 -0
- data/test/test_helper.rb +3 -0
- data/uninstall.rb +1 -0
- metadata +151 -0
data/.gitignore
ADDED
data/CHANGELOG
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Paul Engel
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
|
2
|
+
h1. Rich-CMS
|
3
|
+
|
4
|
+
A Rails gem (and also plugin) for a pluggable CMS frontend
|
5
|
+
|
6
|
+
h2. Introduction
|
7
|
+
|
8
|
+
Rich-CMS is a module of E9s ("http://github.com/archan937/e9s":http://github.com/archan937/e9s) which provides a frontend for your CMS content.
|
9
|
+
|
10
|
+
h2. Installation
|
11
|
+
|
12
|
+
h3. Using Rich-CMS as gem
|
13
|
+
|
14
|
+
Install the Rich-CMS gem:
|
15
|
+
|
16
|
+
<pre>
|
17
|
+
sudo gem install rich_cms
|
18
|
+
</pre>
|
19
|
+
|
20
|
+
Add rich_cms in @environment.rb@ as a gem dependency:
|
21
|
+
|
22
|
+
<pre>
|
23
|
+
config.gem "rich_cms"
|
24
|
+
</pre>
|
25
|
+
|
26
|
+
h3. Using Rich-CMS as plugin
|
27
|
+
|
28
|
+
Install the Rich-CMS plugin:
|
29
|
+
|
30
|
+
<pre>
|
31
|
+
./script/plugin install git://github.com/archan937/rich_cms.git
|
32
|
+
</pre>
|
33
|
+
|
34
|
+
h2. Usage
|
35
|
+
|
36
|
+
h3. Specify the authentication mechanism
|
37
|
+
|
38
|
+
Provide the mechanism as a symbol (e.g. @:authlogic@) and the authenticated class along with the attribute used to identify the instance in a hash.
|
39
|
+
|
40
|
+
<pre>
|
41
|
+
Rich::Cms::Engine.authenticate(:authlogic, {:class_name => "Betty::User", :identifier => :name})
|
42
|
+
</pre>
|
43
|
+
|
44
|
+
Unfortunately, only AuthLogic ("http://github.com/binarylogic/authlogic":http://github.com/binarylogic/authlogic) is supported, but we are working hard on making Rich-CMS compatible with other mechanisms.
|
45
|
+
|
46
|
+
h3. Register CMS content
|
47
|
+
|
48
|
+
Every type of content is identified with its correspending CSS selector (used by the jQuery based Javascript module of Rich-CMS). You will have to provide some specifications:
|
49
|
+
|
50
|
+
* @:class_name@ - The class of the CMS content model which contain the data
|
51
|
+
|
52
|
+
The following specifications are optional as Rich-Cms uses defaults:
|
53
|
+
|
54
|
+
* @:key@ (default: @:key@) - The key used for identification of content. You can also provide an array for a combined key (e.g. @[:key, :locale]@)
|
55
|
+
* @:value@ (default: @:value@) - The attribute which stores the value of the content instance.
|
56
|
+
* @:tag@ (default: @:span@) - The tag used for content items.
|
57
|
+
* @:add@ (default: @[]@) - An array of the content item attributes included within the HTML attributes.
|
58
|
+
* @:before_edit@ (default: @nil@) - Javascript function called before showing the edit form of a content item
|
59
|
+
* @:after_update@ (default: @Rich.Cms.Editor.afterUpdate@) - Javascript function called after update a content item
|
60
|
+
|
61
|
+
<pre>
|
62
|
+
Rich::Cms::Engine.register(".betty_cms_content", {:class_name => "Betty::Cms::StaticContent"})
|
63
|
+
Rich::Cms::Engine.register(".i18n" , {:class_name => "Translation", :key => [:key, :locale], :before_edit => "Rich.I18n.beforeEdit", :after_update => "Rich.I18n.afterUpdate"})
|
64
|
+
</pre>
|
65
|
+
|
66
|
+
h3. Render CMS content in your views
|
67
|
+
|
68
|
+
Rich-CMS requires a rendered DOM element provided with meta data of the content instance. Fortunately, you can call a method provided by Rich-CMS. Just specify the identifier of the content type and the key of the CMS content instance in question:
|
69
|
+
|
70
|
+
<pre>
|
71
|
+
>> key = "test_content"
|
72
|
+
=> "test_content"
|
73
|
+
>> Rich::Cms::Engine.to_content_tag(".betty_cms_content", key)
|
74
|
+
=> "<div class='betty_cms_content' data-key='test_content' data-value='Hello world!'>Hello world!</div>"
|
75
|
+
</pre>
|
76
|
+
|
77
|
+
h3. Rich-CMS in your browser
|
78
|
+
|
79
|
+
Open "http://localhost:3000/cms":http://localhost:3000/cms, log in and start managing CMS content.
|
80
|
+
|
81
|
+
h2. Customizing the after update implementation
|
82
|
+
|
83
|
+
The @update@ action response of @Rich::CmsController@ is provided with "JSON":http://www.json.org data regarding the updated content item. The response will be passed to the @after_update@ Javascript function. Its default JSON data:
|
84
|
+
|
85
|
+
<pre>
|
86
|
+
{"__selector__": ".betty_cms_content", "__identifier__": {"key": "test_paragraph"}, "value": "Hello world!"}
|
87
|
+
</pre>
|
88
|
+
|
89
|
+
*Note*: @__selector__@ and @__identifier__@ are *always* provided in the JSON data.
|
90
|
+
|
91
|
+
When specifying a custom after update Javascript function, you probably want to acquire more information than provided in the default JSON data. You can customize this by defining the @to_rich_cms_response@ method in the CMS content model class:
|
92
|
+
|
93
|
+
<pre>
|
94
|
+
class Translation < ActiveRecord::Base
|
95
|
+
|
96
|
+
def to_rich_cms_response(params)
|
97
|
+
{:value => value, :translations => Hash[*params[:derivative_keys].split(";").uniq.collect{|x| [x, x.t]}.flatten]}
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
</pre>
|
102
|
+
|
103
|
+
The JSON data provided will be look like:
|
104
|
+
|
105
|
+
<pre>
|
106
|
+
{"__selector__": ".i18n", "__identifier__": {"locale": "nl", "key": "word.user"}, "value": "gebruiker", "translations": {"users": "gebruikers"}}
|
107
|
+
</pre>
|
108
|
+
|
109
|
+
h2. Contact me
|
110
|
+
|
111
|
+
For support, remarks and requests please mail me at "paul.engel@holder.nl":mailto:paul.engel@holder.nl.
|
112
|
+
|
113
|
+
h2. Credit
|
114
|
+
|
115
|
+
This Rails gem / plugin depends on:
|
116
|
+
|
117
|
+
jQuery<br>
|
118
|
+
"http://jquery.com":http://jquery.com
|
119
|
+
|
120
|
+
Jzip<br>
|
121
|
+
"http://github.com/archan937/jzip":http://github.com/archan937/jzip
|
122
|
+
|
123
|
+
SASS<br>
|
124
|
+
"http://sass-lang.com":http://sass-lang.com
|
125
|
+
|
126
|
+
Formtastic<br>
|
127
|
+
"http://github.com/justinfrench/formtastic":http://github.com/justinfrench/formtastic
|
128
|
+
|
129
|
+
SeatHolder (optional)<br>
|
130
|
+
"http://github.com/archan937/seat_holder":http://github.com/archan937/seat_holder
|
131
|
+
|
132
|
+
h2. ToDo's
|
133
|
+
|
134
|
+
* Complete README.textile (provide documentation about optional features)
|
135
|
+
* Integrate Rich-CMS in the E9s demo application ("http://github.com/archan937/e9s-demo":http://github.com/archan937/e9s-demo)
|
136
|
+
* Provide compatibility with other authentication mechanisms other than AuthLogic
|
137
|
+
|
138
|
+
h2. E9s
|
139
|
+
|
140
|
+
E9s - "http://github.com/archan937/e9s":http://github.com/archan937/e9s
|
141
|
+
|
142
|
+
h3. E9s modules
|
143
|
+
|
144
|
+
* Rich-CMS - "http://github.com/archan937/rich_cms":http://github.com/archan937/rich_cms
|
145
|
+
* Rich-i18n - "http://github.com/archan937/rich_i18n":http://github.com/archan937/rich_i18n
|
146
|
+
* Rich-pluralization - "http://github.com/archan937/rich_pluralization":http://github.com/archan937/rich_pluralization
|
147
|
+
|
148
|
+
h2. License
|
149
|
+
|
150
|
+
Copyright (c) 2010 Paul Engel, released under the MIT license
|
151
|
+
|
152
|
+
"http://holder.nl":http://holder.nl - "http://codehero.es":http://codehero.es - "http://gettopup.com":http://gettopup.com - "http://twitter.com/archan937":http://twitter.com/archan937 - "paul.engel@holder.nl":mailto:paul.engel@holder.nl
|
153
|
+
|
154
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
155
|
+
|
156
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
157
|
+
|
158
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require "rake"
|
2
|
+
require "rake/testtask"
|
3
|
+
require "rake/rdoctask"
|
4
|
+
|
5
|
+
begin
|
6
|
+
require "jeweler"
|
7
|
+
Jeweler::Tasks.new do |gemspec|
|
8
|
+
gemspec.name = "rich_cms"
|
9
|
+
gemspec.summary = "Enrichments (e9s) module for a pluggable CMS frontend"
|
10
|
+
gemspec.description = "Rich-CMS is a module of E9s (http://github.com/archan937/e9s) which provides a frontend for your CMS content. You can use this gem to manage CMS content or translations (in an internationalized application). The installation and setup process is very easily done. You will have to register content at the Rich-CMS engine and also you will have to specify the authentication mechanism. Both are one-liners."
|
11
|
+
gemspec.email = "paul.engel@holder.nl"
|
12
|
+
gemspec.homepage = "http://github.com/archan937/rich_cms"
|
13
|
+
gemspec.author = "Paul Engel"
|
14
|
+
|
15
|
+
gemspec.add_dependency "jzip"
|
16
|
+
gemspec.add_dependency "haml", ">= 3"
|
17
|
+
gemspec.add_dependency "formtastic"
|
18
|
+
end
|
19
|
+
Jeweler::GemcutterTasks.new
|
20
|
+
rescue LoadError
|
21
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "Default: run unit tests."
|
25
|
+
task :default => :test
|
26
|
+
|
27
|
+
desc "Test the rich_cms plugin."
|
28
|
+
Rake::TestTask.new(:test) do |t|
|
29
|
+
t.libs << "lib"
|
30
|
+
t.libs << "test"
|
31
|
+
t.pattern = "test/**/*_test.rb"
|
32
|
+
t.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "Generate documentation for the rich_cms plugin."
|
36
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
37
|
+
rdoc.rdoc_dir = "rdoc"
|
38
|
+
rdoc.title = "Rich-CMS"
|
39
|
+
rdoc.options << "--line-numbers" << "--inline-source"
|
40
|
+
rdoc.rdoc_files.include "README"
|
41
|
+
rdoc.rdoc_files.include "MIT-LICENSE"
|
42
|
+
rdoc.rdoc_files.include "lib/**/*.rb"
|
43
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "rails", "init")
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
@@ -0,0 +1,56 @@
|
|
1
|
+
|
2
|
+
module Rich
|
3
|
+
class CmsController < ::ApplicationController
|
4
|
+
|
5
|
+
before_filter :require_current_rich_cms_admin, :except => [:show, :hide, :login]
|
6
|
+
|
7
|
+
def show
|
8
|
+
display_bar(true)
|
9
|
+
end
|
10
|
+
|
11
|
+
def hide
|
12
|
+
display_bar(false)
|
13
|
+
end
|
14
|
+
|
15
|
+
def login
|
16
|
+
case rich_cms_auth.logic
|
17
|
+
when :authlogic
|
18
|
+
@current_rich_cms_admin_session = rich_cms_authenticated_class.new params[key = rich_cms_authenticated_class.name.underscore.gsub("/", "_")]
|
19
|
+
authenticated = @current_rich_cms_admin_session.save
|
20
|
+
|
21
|
+
if request.xhr?
|
22
|
+
render :update do |page|
|
23
|
+
if authenticated
|
24
|
+
page.reload
|
25
|
+
else
|
26
|
+
page["##{key}_#{rich_cms_authentication_inputs.first}"].focus
|
27
|
+
end
|
28
|
+
end
|
29
|
+
else
|
30
|
+
redirect_to request.referrer
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def logout
|
36
|
+
case rich_cms_auth.logic
|
37
|
+
when :authlogic
|
38
|
+
(@current_rich_cms_admin_session ||= rich_cms_authenticated_class.find).destroy
|
39
|
+
end
|
40
|
+
hide
|
41
|
+
end
|
42
|
+
|
43
|
+
def update
|
44
|
+
render :json => Cms::Content::Item.new(params[:content_item]).save
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def display_bar(display)
|
50
|
+
(session[:rich_cms] ||= {})[:display] = display
|
51
|
+
redirect_to request.referrer
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<div class="menu">
|
2
|
+
<% if current_rich_cms_admin %>
|
3
|
+
<%= link "Mark copy", :class => "mark" %>
|
4
|
+
<% end %>
|
5
|
+
|
6
|
+
<% unless current_rich_cms_admin %>
|
7
|
+
<%= link "Login" %>
|
8
|
+
<% else %>
|
9
|
+
<div class="admin">
|
10
|
+
Logged in as <strong><%= current_rich_cms_admin_name %></strong>
|
11
|
+
|
12
|
+
<%= link_to "Hide" , rich_cms_hide_path %>
|
13
|
+
<%= link_to "Logout", rich_cms_logout_path %>
|
14
|
+
</div>
|
15
|
+
<% end %>
|
16
|
+
</div>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<div class="edit" style="display: none">
|
2
|
+
<% form_tag rich_cms_update_path, :name => "rich_cms_content", :class => "ajaxify" do %>
|
3
|
+
<fieldset class="inputs">
|
4
|
+
<label></label>
|
5
|
+
</fieldset>
|
6
|
+
<fieldset class="buttons">
|
7
|
+
<%= submit_tag "Save" %> <%= link "Close" %>
|
8
|
+
</fieldset>
|
9
|
+
<% end %>
|
10
|
+
</div>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<div class="login" style="display: none">
|
2
|
+
<% semantic_form_for rich_cms_authenticated_class.new, :url => rich_cms_login_path, :html => {:class => "ajaxify"} do |form| %>
|
3
|
+
|
4
|
+
<%= form.inputs *rich_cms_authentication_inputs %>
|
5
|
+
|
6
|
+
<% form.buttons do %>
|
7
|
+
<%= form.submit "Login" %>
|
8
|
+
<% end %>
|
9
|
+
|
10
|
+
<% end %>
|
11
|
+
</div>
|