cmsable 0.0.9 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +106 -0
- data/app/assets/javascripts/cmsable/cmsable.js +31 -14
- data/app/helpers/cmsable/cmsable_helper.rb +48 -28
- data/lib/cmsable.rb +5 -8
- data/lib/cmsable/engine.rb +2 -1
- data/lib/cmsable/version.rb +1 -1
- metadata +3 -3
- data/README.rdoc +0 -57
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDExMzlmMDNmOTdmODBjNGYyM2NjNzBhMjgxZjliMGYxODY0MWMxMQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZDhiZmQwYzNlZjgwODU2NjI5OWRiZjI0NTljMzQ5YWViMzFmMWJjNw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjM2YmY0MDRjZmYwMTBlYmQwNTBlY2M1NzdhN2I1OTQ0NDk2YjkzY2IwNmVm
|
10
|
+
ZGEzMjgwYjcyMzlkNTgzNzU3NDkwNTgxN2M0MmEzMjAyNDIzMzRlYTk4N2Ni
|
11
|
+
ZjZiNWNlOTBmNzRmZmIwYWFiZDcxOTZhMzkzMDZhZmVhOWViMGU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OTQ3Y2Q1ZjQ4Yzc1NmIxZDdjMDM0MmY1NzBiYTdmMzY5MWQyZDRmNTVmNDkw
|
14
|
+
Y2Y2ZDczZDhiYjZiYzljMjExNDk1YmMxZTVlNmNlN2I1NmRkNTczY2IxZTli
|
15
|
+
YzdkZmEzMGRjYmUxYjBhZWUzNWIwNjA3N2E2ZTI0ZDJlOTUzYzM=
|
data/README.md
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
# Cmsable
|
2
|
+
---------
|
3
|
+
|
4
|
+
Add inline editable content to pages.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add to your Gemfile
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'cmsable'
|
12
|
+
```
|
13
|
+
|
14
|
+
Get Dependencies
|
15
|
+
|
16
|
+
bundle install
|
17
|
+
|
18
|
+
Add to your routes
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
mount Cmsable::Engine => '/cmsable'
|
22
|
+
```
|
23
|
+
|
24
|
+
Install and run the migrations if you want to use the built in model
|
25
|
+
|
26
|
+
rake cmsable:install:migrations
|
27
|
+
rake db:migrate
|
28
|
+
|
29
|
+
Cmsable uses CanCan so make sure this is set up in your necessary controller(s)
|
30
|
+
If your users aren't called users then you'll get something like:
|
31
|
+
|
32
|
+
undefined local variable or method `current_user' for ...
|
33
|
+
|
34
|
+
You need to define the current_ability, e.g.
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
def current_ability
|
38
|
+
@current_ability ||= AccountAbility.new(current_account)
|
39
|
+
end
|
40
|
+
```
|
41
|
+
(From https://github.com/ryanb/cancan/wiki/changing-defaults)
|
42
|
+
|
43
|
+
## Usage
|
44
|
+
|
45
|
+
Add to your layout:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
<%= cmsable_assets %>
|
49
|
+
```
|
50
|
+
|
51
|
+
### To use the built in model
|
52
|
+
In your view files
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
<%= cmsable 'identifier' %>
|
56
|
+
```
|
57
|
+
|
58
|
+
Identifier can be any string or symbol, for example `'Homepage Intro'` or `:something`
|
59
|
+
|
60
|
+
For plain text areas pass `plain: true` as an option.
|
61
|
+
This way you can put content in any tag you want without worrying about users
|
62
|
+
messing up the markup.
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
<span><%= cmsable :identifier, plain: true %></span>
|
66
|
+
```
|
67
|
+
|
68
|
+
The problem with the above is that in edit mode you'll end up with invalid HTML:
|
69
|
+
|
70
|
+
```html
|
71
|
+
<span><div contenteditable>Content</div></span>
|
72
|
+
```
|
73
|
+
|
74
|
+
To avoid this you can override the tag used in edit mode:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
<%= cmsable :identifier, plain: true, tag: 'span' %>
|
78
|
+
```
|
79
|
+
Resulting in:
|
80
|
+
```html
|
81
|
+
<span contenteditable>Content</span>
|
82
|
+
```
|
83
|
+
|
84
|
+
### To use your own models
|
85
|
+
Add to your model:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
cmsable :body => :column_to_use_for_content
|
89
|
+
```
|
90
|
+
|
91
|
+
Then in your views:
|
92
|
+
```ruby
|
93
|
+
<%= cmsable @model_instance %>
|
94
|
+
```
|
95
|
+
|
96
|
+
## TODO
|
97
|
+
- Handle saving errors
|
98
|
+
- Remove CanCan dependancy
|
99
|
+
- Decouple ckeditor
|
100
|
+
- Support different editors
|
101
|
+
- Setup config initializer for added customizability
|
102
|
+
- Add file mode
|
103
|
+
- Add image mode
|
104
|
+
- Add video mode (youtube/vimeo/etc)
|
105
|
+
- Add support for langs/i18n
|
106
|
+
- Fix highlight so empty areas are still visible
|
@@ -8,7 +8,9 @@ $(function() {
|
|
8
8
|
$('#cmsable_control a').toggleClass('cmsable_on');
|
9
9
|
if ($(this).hasClass('cmsable_on')) {
|
10
10
|
$('.cmsable_editor').addClass('cmsable_reveal').attr('contenteditable', true);
|
11
|
-
|
11
|
+
$('.cmsable_rich').each(function(idx, ele) {
|
12
|
+
CKEDITOR.inline(ele);
|
13
|
+
});
|
12
14
|
}else{
|
13
15
|
$('.cmsable_editor').removeClass('cmsable_reveal').attr('contenteditable', false);
|
14
16
|
$.each(CKEDITOR.instances, function(index, instance) {
|
@@ -20,29 +22,44 @@ $(function() {
|
|
20
22
|
$(document).on('click', '.cmsable_save.cmsable_on', function() {
|
21
23
|
$('#cmsable_control').addClass('processing');
|
22
24
|
var that = this,
|
23
|
-
|
24
|
-
|
25
|
+
token = that.getAttribute('data-token');
|
26
|
+
|
27
|
+
var cmsables = [];
|
28
|
+
|
29
|
+
// Submit plain text fields
|
30
|
+
$('.cmsable_plain').each(function(idx, ele) {
|
31
|
+
$ele = $(ele);
|
32
|
+
cmsables.push({
|
33
|
+
id: ele.id.replace(/\D/g, ''),
|
34
|
+
model: $ele.data('model'),
|
35
|
+
body: $ele.text()
|
36
|
+
});
|
37
|
+
});
|
38
|
+
|
39
|
+
// Submit CKEditor fields
|
25
40
|
$.each(CKEDITOR.instances, function(index, instance) {
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
41
|
+
cmsables.push({
|
42
|
+
id: instance.name.replace(/\D/g, ''),
|
43
|
+
model: instance.element.$.getAttribute('data-model'),
|
44
|
+
body: instance.getData()
|
45
|
+
});
|
46
|
+
});
|
47
|
+
|
48
|
+
$.each(cmsables, function(idx, cmsable) {
|
49
|
+
$.post('/cmsable/' + cmsable.id, {
|
32
50
|
_method: 'put',
|
33
|
-
model: model,
|
51
|
+
model: cmsable.model,
|
34
52
|
authenticity_token: token,
|
35
53
|
content: {
|
36
|
-
body: body
|
54
|
+
body: cmsable.body
|
37
55
|
}
|
38
56
|
}, function(data) {
|
39
|
-
|
40
|
-
if (updated === instances) {
|
57
|
+
if (idx == cmsables.length - 1) {
|
41
58
|
$('#cmsable_control').removeClass('processing');
|
42
59
|
}
|
43
60
|
});
|
44
61
|
});
|
62
|
+
|
45
63
|
$('.cmsable_edit').click();
|
46
64
|
});
|
47
|
-
|
48
65
|
});
|
@@ -1,32 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
module Cmsable
|
3
|
+
# Cmsable view helpers
|
2
4
|
module CmsableHelper
|
3
|
-
|
4
5
|
def cmsable_assets
|
5
6
|
javascript_include_tag('cmsable/application') +
|
6
7
|
stylesheet_link_tag('cmsable/application')
|
7
8
|
end
|
8
9
|
|
9
|
-
|
10
|
+
TYPES = [
|
11
|
+
:rich, # CKEditor (default)
|
12
|
+
:plain # Nothing fancy
|
13
|
+
]
|
14
|
+
|
15
|
+
DEFAULTS = {
|
16
|
+
readonly: false, # Can edit by default
|
17
|
+
type: :rich, # Use rich text editor by default
|
18
|
+
plantext: false, # No text editor
|
19
|
+
tag: nil # What tag to use for contenteditable
|
20
|
+
}
|
10
21
|
|
22
|
+
def cmsable(name_or_model, options = {})
|
11
23
|
model = get_model name_or_model
|
12
24
|
|
13
|
-
options =
|
14
|
-
|
15
|
-
|
25
|
+
options = DEFAULTS.merge options
|
26
|
+
|
27
|
+
# Fail on unknow types
|
28
|
+
typefail options[:type] unless TYPES.include? options[:type]
|
16
29
|
|
17
|
-
# Skip checking permission
|
30
|
+
# Skip checking permission if set to readonly or
|
18
31
|
# explicit authorisation is passed
|
19
|
-
|
20
|
-
|
21
|
-
end
|
32
|
+
readonly = options.include?(:authorised) || options[:readonly]
|
33
|
+
options[:authorised] = authorised?(model) unless readonly
|
22
34
|
|
23
|
-
|
35
|
+
content = model.send(model.cmsable_body).html_safe
|
36
|
+
editable = options[:authorised] && !options[:readonly]
|
24
37
|
|
38
|
+
editable ? show_cmsable(content, model, options) : uncmsable(content, options[:tag])
|
25
39
|
end
|
26
40
|
|
27
|
-
|
41
|
+
private
|
42
|
+
|
43
|
+
def type_fail(type)
|
44
|
+
fail "Unknown cmsable type: #{type}." + "Must be one of #{TYPES * ', '}"
|
45
|
+
end
|
28
46
|
|
29
|
-
def get_model
|
47
|
+
def get_model(name_or_model)
|
30
48
|
if name_or_model.class < ActiveRecord::Base
|
31
49
|
name_or_model
|
32
50
|
else
|
@@ -34,31 +52,33 @@ module Cmsable
|
|
34
52
|
end
|
35
53
|
end
|
36
54
|
|
37
|
-
def
|
38
|
-
control =
|
39
|
-
|
40
|
-
|
55
|
+
def show_cmsable(content, model, options)
|
56
|
+
control = unless @cmsable_control_rendered
|
57
|
+
render template: 'cmsable/cmsable/control'
|
58
|
+
end
|
41
59
|
@cmsable_control_rendered = true
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
60
|
+
id = "cmsable_edit_#{model.class.to_s.parameterize}_#{model.id}"
|
61
|
+
content_tag((options[:tag] || :div), content,
|
62
|
+
class: "cmsable_editor cmsable_#{options[:type]}",
|
63
|
+
id: id,
|
64
|
+
'data-model' => model.class,
|
65
|
+
) + (control || '')
|
66
|
+
end
|
67
|
+
|
68
|
+
def uncmsable(content, tag)
|
69
|
+
if tag
|
70
|
+
content_tag tag, content
|
49
71
|
else
|
50
72
|
content
|
51
73
|
end
|
52
74
|
end
|
53
75
|
|
54
|
-
def authorised?
|
55
|
-
authorised = false
|
76
|
+
def authorised?(model)
|
56
77
|
if Cmsable.const_defined? :CanCan
|
57
|
-
|
78
|
+
can? :update, model
|
58
79
|
else
|
59
|
-
|
80
|
+
Cmsable.authorised
|
60
81
|
end
|
61
82
|
end
|
62
|
-
|
63
83
|
end
|
64
84
|
end
|
data/lib/cmsable.rb
CHANGED
@@ -1,24 +1,21 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'cmsable/engine'
|
2
3
|
|
3
4
|
module Cmsable
|
4
|
-
|
5
5
|
mattr_accessor :authorised
|
6
6
|
|
7
|
+
# Add cmsable method to ActiveRecord classes
|
7
8
|
module ClassMethods
|
8
|
-
def cmsable
|
9
|
-
|
9
|
+
def cmsable(options = {})
|
10
10
|
cattr_accessor :cmsable_body
|
11
11
|
|
12
12
|
options = {
|
13
|
-
:
|
13
|
+
body: :body
|
14
14
|
}.merge options
|
15
15
|
|
16
16
|
self.cmsable_body = options[:body]
|
17
|
-
|
18
17
|
end
|
19
18
|
end
|
20
|
-
|
21
19
|
end
|
22
20
|
|
23
|
-
# Add cmsable method to ActiveRecord classes
|
24
21
|
ActiveRecord::Base.send :extend, Cmsable::ClassMethods
|
data/lib/cmsable/engine.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
module Cmsable
|
3
|
+
# This makes the consuming app load our helpers
|
2
4
|
class Engine < ::Rails::Engine
|
3
5
|
isolate_namespace Cmsable
|
4
|
-
# This makes the consuming app load our helpers
|
5
6
|
initializer 'cmsable.action_controller' do |app|
|
6
7
|
ActiveSupport.on_load :action_controller do
|
7
8
|
helper Cmsable::CmsableHelper
|
data/lib/cmsable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cmsable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Butler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -75,7 +75,7 @@ extensions: []
|
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
77
|
- MIT-LICENSE
|
78
|
-
- README.
|
78
|
+
- README.md
|
79
79
|
- Rakefile
|
80
80
|
- app/assets/images/cmsable/ajax-loader.gif
|
81
81
|
- app/assets/images/cmsable/construction.png
|
data/README.rdoc
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
# Cmsable
|
2
|
-
|
3
|
-
Add inline editable content to pages.
|
4
|
-
|
5
|
-
Installation:
|
6
|
-
|
7
|
-
Add to your Gemfile
|
8
|
-
gem 'cmsable'
|
9
|
-
|
10
|
-
Get Dependencies
|
11
|
-
bundle install
|
12
|
-
|
13
|
-
Add to your routes
|
14
|
-
mount Cmsable::Engine => '/cmsable'
|
15
|
-
|
16
|
-
Install and run the migrations if you want to use the built in model
|
17
|
-
rake cmsable:install:migrations
|
18
|
-
rake db:migrate
|
19
|
-
|
20
|
-
Cmsable uses CanCan so make sure this is setup in your necessary controller(s)
|
21
|
-
If your users aren't called users then you'll get something like:
|
22
|
-
undefined local variable or method `current_user' for ...
|
23
|
-
|
24
|
-
You need to define the current_ability, e.g.
|
25
|
-
def current_ability
|
26
|
-
@current_ability ||= AccountAbility.new(current_account)
|
27
|
-
end
|
28
|
-
From https://github.com/ryanb/cancan/wiki/changing-defaults
|
29
|
-
|
30
|
-
Usage:
|
31
|
-
|
32
|
-
In your layout
|
33
|
-
<%= cmsable_assets %>
|
34
|
-
|
35
|
-
To use the built in model
|
36
|
-
In your view files
|
37
|
-
<%= cmsable 'identifier' %>
|
38
|
-
|
39
|
-
Identifier can be anything, for example 'Homepage Intro' or something
|
40
|
-
|
41
|
-
To use existing models
|
42
|
-
Add to your model
|
43
|
-
cmsable :body => :column_to_use_for_content
|
44
|
-
Then in your views
|
45
|
-
<%= cmsable @model_instance %>
|
46
|
-
|
47
|
-
## TODO
|
48
|
-
- Handle saving errors
|
49
|
-
- Remove CanCan dependancy
|
50
|
-
- Decouple ckeditor
|
51
|
-
- Support different editors
|
52
|
-
- Setup config initializer for added customizability
|
53
|
-
- Add plain text mode
|
54
|
-
- Add file mode
|
55
|
-
- Add image mode
|
56
|
-
- Add video mode (youtube/vimeo/etc)
|
57
|
-
- Fix highlight so empty areas are still visible
|