cmsable 0.0.2
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.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +56 -0
- data/Rakefile +40 -0
- data/app/assets/images/cmsable/ajax-loader.gif +0 -0
- data/app/assets/images/cmsable/construction.png +0 -0
- data/app/assets/javascripts/cmsable/application.js +14 -0
- data/app/assets/javascripts/cmsable/cmsable.js +48 -0
- data/app/assets/stylesheets/cmsable/application.css +13 -0
- data/app/assets/stylesheets/cmsable/cmsable.css +74 -0
- data/app/controllers/cmsable/cmsable_controller.rb +12 -0
- data/app/helpers/cmsable/application_helper.rb +4 -0
- data/app/helpers/cmsable/cmsable_helper.rb +56 -0
- data/app/models/cmsable/content.rb +29 -0
- data/app/views/cmsable/cmsable/control.html.erb +5 -0
- data/config/routes.rb +4 -0
- data/db/migrate/20130308053818_create_cmsable_contents.rb +10 -0
- data/lib/cmsable/engine.rb +11 -0
- data/lib/cmsable/version.rb +3 -0
- data/lib/cmsable.rb +24 -0
- data/lib/tasks/cmsable_tasks.rake +4 -0
- data/test/cmsable_test.rb +7 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/functional/cmsable/cmsable_controller_test.rb +11 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/test_helper.rb +15 -0
- data/test/unit/helpers/cmsable/cmsable_helper_test.rb +6 -0
- metadata +196 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 YOURNAME
|
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.rdoc
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
= Cmsable
|
2
|
+
|
3
|
+
This project rocks and uses MIT-LICENSE.
|
4
|
+
|
5
|
+
Installation:
|
6
|
+
|
7
|
+
Add to your Gemfile
|
8
|
+
gem 'cmsable'
|
9
|
+
|
10
|
+
Make sure you're using ckeditor 4
|
11
|
+
bundle install
|
12
|
+
If that doesn't work
|
13
|
+
bundle update ckeditor
|
14
|
+
|
15
|
+
Add to your routes
|
16
|
+
mount Cmsable::Engine => '/cmsable'
|
17
|
+
|
18
|
+
Install and run the migrations if you want to use the built in model
|
19
|
+
rake cmsable:install:migrations
|
20
|
+
rake dm:migrate
|
21
|
+
|
22
|
+
Cmsable uses CanCan so make sure this is setup in your necessary controller(s)
|
23
|
+
If your users aren't called users then you'll get something like:
|
24
|
+
undefined local variable or method `current_user' for ...
|
25
|
+
|
26
|
+
You need to define the current_ability, e.g.
|
27
|
+
def current_ability
|
28
|
+
@current_ability ||= AccountAbility.new(current_account)
|
29
|
+
end
|
30
|
+
From https://github.com/ryanb/cancan/wiki/changing-defaults
|
31
|
+
|
32
|
+
Usage:
|
33
|
+
|
34
|
+
In your layout
|
35
|
+
<%= cmsable_assets %>
|
36
|
+
|
37
|
+
To use the built in model
|
38
|
+
In your view files
|
39
|
+
<%= cmsable 'identifier' %>
|
40
|
+
|
41
|
+
Identifier can be anything, for example 'Homepage Intro' or something
|
42
|
+
|
43
|
+
To use existing models
|
44
|
+
Add to your model
|
45
|
+
cmsable :body => :column_to_use_for_content
|
46
|
+
Then in your views
|
47
|
+
<%= cmsable @model_instance %>
|
48
|
+
|
49
|
+
TODO
|
50
|
+
Complete gemspec
|
51
|
+
Handle save fails
|
52
|
+
Rename to Messable
|
53
|
+
Allow to fallback to built in auth if no CanCan
|
54
|
+
Add other auth library support?
|
55
|
+
Setup config initializer for added customizability
|
56
|
+
Create some tests, I guess
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'Cmsable'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
24
|
+
load 'rails/tasks/engine.rake'
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
Bundler::GemHelper.install_tasks
|
29
|
+
|
30
|
+
require 'rake/testtask'
|
31
|
+
|
32
|
+
Rake::TestTask.new(:test) do |t|
|
33
|
+
t.libs << 'lib'
|
34
|
+
t.libs << 'test'
|
35
|
+
t.pattern = 'test/**/*_test.rb'
|
36
|
+
t.verbose = false
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
task :default => :test
|
Binary file
|
Binary file
|
@@ -0,0 +1,14 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require ckeditor/init
|
14
|
+
//= require_tree .
|
@@ -0,0 +1,48 @@
|
|
1
|
+
// Place all the behaviors and hooks related to the matching controller here.
|
2
|
+
// All this logic will automatically be available in application.js.
|
3
|
+
$(function() {
|
4
|
+
|
5
|
+
CKEDITOR.disableAutoInline = true;
|
6
|
+
|
7
|
+
$('.cmsable_edit').on('click', function() {
|
8
|
+
$('#cmsable_control a').toggleClass('cmsable_on');
|
9
|
+
if ($(this).hasClass('cmsable_on')) {
|
10
|
+
$('.cmsable_editor').addClass('reveal').attr('contenteditable', true);
|
11
|
+
CKEDITOR.inlineAll();
|
12
|
+
}else{
|
13
|
+
$('.cmsable_editor').removeClass('reveal').attr('contenteditable', false);
|
14
|
+
$.each(CKEDITOR.instances, function(index, instance) {
|
15
|
+
instance.destroy();
|
16
|
+
});
|
17
|
+
}
|
18
|
+
});
|
19
|
+
|
20
|
+
$(document).on('click', '.cmsable_save.cmsable_on', function() {
|
21
|
+
$('#cmsable_control').addClass('processing');
|
22
|
+
var that = this,
|
23
|
+
updated = 0,
|
24
|
+
instances = 0;
|
25
|
+
$.each(CKEDITOR.instances, function(index, instance) {
|
26
|
+
instances++;
|
27
|
+
var id = instance.name.replace(/\D/g, ''),
|
28
|
+
model = instance.element.$.getAttribute('data-model'),
|
29
|
+
token = that.getAttribute('data-token'),
|
30
|
+
body = instance.getData();
|
31
|
+
$.post('/cmsable/' + id, {
|
32
|
+
_method: 'put',
|
33
|
+
model: model,
|
34
|
+
authenticity_token: token,
|
35
|
+
content: {
|
36
|
+
body: body
|
37
|
+
}
|
38
|
+
}, function(data) {
|
39
|
+
updated++;
|
40
|
+
if (updated === instances) {
|
41
|
+
$('#cmsable_control').removeClass('processing');
|
42
|
+
}
|
43
|
+
});
|
44
|
+
});
|
45
|
+
$('.cmsable_edit').click();
|
46
|
+
});
|
47
|
+
|
48
|
+
});
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,74 @@
|
|
1
|
+
/*
|
2
|
+
Place all the styles related to the matching controller here.
|
3
|
+
They will automatically be included in application.css.
|
4
|
+
*/
|
5
|
+
.cmsable_editor.reveal {
|
6
|
+
background:url(/assets/cmsable/construction.png); /* http://www.patternsky.com/textures/hazard-stripes-texture/ */
|
7
|
+
}
|
8
|
+
|
9
|
+
#cmsable_control {
|
10
|
+
position:fixed;
|
11
|
+
left:80%;
|
12
|
+
top:-10px;
|
13
|
+
border-radius:0 0 5px 5px;
|
14
|
+
box-shadow:2px 2px 15px #454545;
|
15
|
+
background:#999;
|
16
|
+
-webkit-transition:All 0.5s ease; -moz-transition:All 0.5s ease; -o-transition:All 0.5s ease;
|
17
|
+
z-index:9999;
|
18
|
+
}
|
19
|
+
|
20
|
+
#cmsable_control a {
|
21
|
+
float:left;
|
22
|
+
display:block;
|
23
|
+
background:#454545;
|
24
|
+
padding:20px 10px 10px;
|
25
|
+
font-size:10px;
|
26
|
+
font-family:sans;
|
27
|
+
color:white;
|
28
|
+
cursor:pointer;
|
29
|
+
box-shadow:inset 0 0 10px #999;
|
30
|
+
z-index:1;
|
31
|
+
position:relative;
|
32
|
+
}
|
33
|
+
|
34
|
+
#cmsable_control a:hover {
|
35
|
+
background:#666;
|
36
|
+
}
|
37
|
+
|
38
|
+
#cmsable_control a.cmsable_edit {
|
39
|
+
border-radius:0 0 0 5px;
|
40
|
+
}
|
41
|
+
|
42
|
+
#cmsable_control a.cmsable_save {
|
43
|
+
border-radius:0 0 5px 0;
|
44
|
+
background:#858585;
|
45
|
+
color:#bbb;
|
46
|
+
cursor:default;
|
47
|
+
}
|
48
|
+
|
49
|
+
#cmsable_control a.cmsable_save.cmsable_on {
|
50
|
+
background:rgb(70, 121, 185);
|
51
|
+
color:white;
|
52
|
+
cursor:pointer;
|
53
|
+
}
|
54
|
+
|
55
|
+
#cmsable_control a.cmsable_edit.cmsable_on {
|
56
|
+
background:rgb(94, 182, 94);
|
57
|
+
}
|
58
|
+
|
59
|
+
#cmsable_control .cmsable_processing {
|
60
|
+
background:url(/assets/cmsable/ajax-loader.gif) no-repeat center 15px;
|
61
|
+
padding:10px;
|
62
|
+
width:16px;
|
63
|
+
height:16px;
|
64
|
+
display:block;
|
65
|
+
float:left;
|
66
|
+
text-indent:-9999px;
|
67
|
+
overflow:hidden;
|
68
|
+
margin-left:-40px;
|
69
|
+
-webkit-transition:All 0.5s ease; -moz-transition:All 0.5s ease; -o-transition:All 0.5s ease;
|
70
|
+
}
|
71
|
+
|
72
|
+
#cmsable_control.processing .cmsable_processing {
|
73
|
+
margin-left:0;
|
74
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Cmsable
|
2
|
+
class CmsableController < ApplicationController
|
3
|
+
def update
|
4
|
+
model = params[:model].constantize
|
5
|
+
|
6
|
+
render :text => false and return if cannot? :update, model
|
7
|
+
|
8
|
+
attribute = model.cmsable_body
|
9
|
+
render :text => model.find(params[:id]).update_attribute(attribute, params[:content][:body])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Cmsable
|
2
|
+
module CmsableHelper
|
3
|
+
|
4
|
+
def cmsable_assets
|
5
|
+
javascript_include_tag('cmsable/application') +
|
6
|
+
stylesheet_link_tag('cmsable/application')
|
7
|
+
end
|
8
|
+
|
9
|
+
def cmsable name_or_model, options = {}
|
10
|
+
|
11
|
+
model = get_model name_or_model
|
12
|
+
|
13
|
+
options = {
|
14
|
+
authorised:authorised?(model)
|
15
|
+
}.merge options
|
16
|
+
|
17
|
+
content_or_editable_content model, options[:authorised]
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def get_model name_or_model
|
24
|
+
if name_or_model.class < ActiveRecord::Base
|
25
|
+
name_or_model
|
26
|
+
else
|
27
|
+
Content.get(name_or_model)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def content_or_editable_content model, authorised
|
32
|
+
control = render :template => 'cmsable/cmsable/control' unless @cmsable_control_rendered
|
33
|
+
@cmsable_control_rendered = true
|
34
|
+
content = model.send(model.cmsable_body).html_safe
|
35
|
+
if authorised
|
36
|
+
content_tag(:div, content, {
|
37
|
+
class: :cmsable_editor,
|
38
|
+
id: "cmsable_edit_#{model.class.to_s.parameterize}_#{model.id}",
|
39
|
+
:'data-model' => model.class,
|
40
|
+
}) + (control or '')
|
41
|
+
else
|
42
|
+
content
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def authorised? model
|
47
|
+
authorised = false
|
48
|
+
if Cmsable.const_defined? :CanCan
|
49
|
+
authorised = can? :update, model
|
50
|
+
else
|
51
|
+
authorised = Cmsable.authorised
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Cmsable
|
2
|
+
class Content < ActiveRecord::Base
|
3
|
+
# Extensions
|
4
|
+
cmsable
|
5
|
+
|
6
|
+
# Attribute accessibility
|
7
|
+
attr_accessible :body, :name
|
8
|
+
|
9
|
+
# Validations
|
10
|
+
validates :name, :presence => true
|
11
|
+
|
12
|
+
# Virtual Attributes
|
13
|
+
|
14
|
+
# Callbacks
|
15
|
+
|
16
|
+
# Instance Methods
|
17
|
+
|
18
|
+
# Class Methods
|
19
|
+
def self.set name, body
|
20
|
+
find_by_name(name).update_attribute :body, body
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.get name
|
24
|
+
find_or_create_by_name name, :body => "Awaiting Content"
|
25
|
+
end
|
26
|
+
|
27
|
+
# Scopes
|
28
|
+
end
|
29
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
module Cmsable
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace Cmsable
|
4
|
+
# This makes the consuming app load our helpers
|
5
|
+
initializer 'cmsable.action_controller' do |app|
|
6
|
+
ActiveSupport.on_load :action_controller do
|
7
|
+
helper Cmsable::CmsableHelper
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/cmsable.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "cmsable/engine"
|
2
|
+
|
3
|
+
module Cmsable
|
4
|
+
|
5
|
+
mattr_accessor :authorised
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def cmsable options = {}
|
9
|
+
|
10
|
+
cattr_accessor :cmsable_body
|
11
|
+
|
12
|
+
options = {
|
13
|
+
:body => :body
|
14
|
+
}.merge options
|
15
|
+
|
16
|
+
self.cmsable_body = options[:body]
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
# Add cmsable method to ActiveRecord classes
|
24
|
+
ActiveRecord::Base.send :extend, Cmsable::ClassMethods
|