editable_content 0.4.0 → 0.5.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.
- data/LICENSE +1 -1
- data/README.rdoc +136 -3
- data/lib/editable_content.rb +7 -3
- data/lib/editable_content/controller_helper.rb +131 -84
- data/lib/editable_content/view_helpers.rb +138 -0
- data/lib/generators/editable_content_generator.rb +2 -2
- data/test/helper.rb +2 -0
- metadata +5 -5
- data/lib/editable_content/application_helpers.rb +0 -88
data/LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -1,9 +1,142 @@
|
|
1
1
|
= editable_content
|
2
2
|
|
3
|
-
|
3
|
+
This plugin manages sections of a page that can be edited by users. I use it to
|
4
|
+
manage various boilerplate sections that need to be changed occasionally such as
|
5
|
+
welcome messages, contact form instructions, and things like that.
|
6
|
+
|
7
|
+
The editing fuctionality uses Textile markup and is extended to uses Radius tags
|
8
|
+
to embed function calls that are evaluated and expanded at run time. This allow
|
9
|
+
you to include any custom functionality that you care to write.
|
10
|
+
|
11
|
+
== Requirements
|
12
|
+
|
13
|
+
This gem is for Rails 3 and above only. While I developed most of these
|
14
|
+
techniques under Rails 2, that version was too complicated to release.
|
15
|
+
|
16
|
+
This gem requires the JQuery javascript library and the JQuery UI library. This
|
17
|
+
gem assumes that these files are already included in your page, and does not
|
18
|
+
add them.
|
19
|
+
|
20
|
+
This gem uses the MarkItUp javascript editor library (http://markitup.jaysalvat.com/home/)
|
21
|
+
to create the popup editor. You will need that code in your /public/javascript/
|
22
|
+
directory in order for this to work. The stylesheets and javascript for this
|
23
|
+
will be added automatically on the pages that use an editor.
|
24
|
+
|
25
|
+
This gem also requires the Radius and Redcloth gems.
|
26
|
+
|
27
|
+
== Installation
|
28
|
+
|
29
|
+
Install the gem:
|
30
|
+
|
31
|
+
gem install editable_content
|
32
|
+
|
33
|
+
Add it to your Gemfile:
|
34
|
+
|
35
|
+
gem "editable_content"
|
36
|
+
|
37
|
+
This gem inserts stylesheets and javascript into the generated page to create a
|
38
|
+
popup editor to edit the section of the page. To allow this, your page must have
|
39
|
+
hooks to support adding the required code. Add the following lines to the <head>
|
40
|
+
section of the layout file used to genrate the page that will have the editable
|
41
|
+
field.
|
42
|
+
|
43
|
+
<%= yield :stylesheet_list %>
|
44
|
+
<%= yield :javascript_list %>
|
45
|
+
<script type="text/javascript">
|
46
|
+
<%= yield :javascript_data %>
|
47
|
+
</script>
|
48
|
+
|
49
|
+
In addition make sure the layout file includes jquery.js, jquery-ui.js and a
|
50
|
+
UI theme css file.
|
51
|
+
|
52
|
+
|
53
|
+
== Basic Usage
|
54
|
+
|
55
|
+
Use getContent to create a variable that holds the current content. In this
|
56
|
+
example +"maintext"+ is the name of the field, and +@maintext_content+ is the variable
|
57
|
+
that holds the content. Put the following line in the controller for your action:
|
58
|
+
|
59
|
+
@maintext_content = getContent("maintext")
|
60
|
+
|
61
|
+
Next put the following lines in the view file for your action:
|
62
|
+
|
63
|
+
<%= insert_editable_content -%> # include once only
|
64
|
+
<%= create_content_editor("maintext") -%> # include once for each field
|
65
|
+
|
66
|
+
Finally display the content somewhere in your view file:
|
67
|
+
|
68
|
+
<%= @maintext_content %>
|
69
|
+
|
70
|
+
You may use as many editable fields on a page as you wish, as long as each has a
|
71
|
+
unique name for the field and variable. These name can be any valid rails
|
72
|
+
variable name that you want.
|
73
|
+
|
74
|
+
|
75
|
+
== Security
|
76
|
+
|
77
|
+
It will usually be desirable to restrict who can edit a field. You will almost
|
78
|
+
never want the general public to be able to edit most of your fields. It is
|
79
|
+
assumed that you will have some sort of user authentication, but that is beyond
|
80
|
+
the scope of this gem. This uses a global variable to control access. If the
|
81
|
+
variable is true, the current user can edit all fields. If it is false then the
|
82
|
+
current user cannot edit any field, they are display only.
|
83
|
+
|
84
|
+
The way to use this is to set the variable during the page generation process.
|
85
|
+
The easiest way to do this is with a before filter that determines whether the
|
86
|
+
current user has permission to edit or not. I use this code in my
|
87
|
+
application_controller.rb:
|
88
|
+
|
89
|
+
before_filter proc{ setEditableAuthorization(current_user.is?( :editor )) }
|
90
|
+
|
91
|
+
You can use any code that evaluates to true or false as the parameter to
|
92
|
+
+setEditableAuthorization+.
|
93
|
+
|
94
|
+
|
95
|
+
== Additional Functionality
|
96
|
+
|
97
|
+
This gem includes a function called +processContent+ that allows you to use the
|
98
|
+
Textile/Radius engine to expand any text and return it as formated HTML. With
|
99
|
+
this you can use any textarea or textfield to enter text that will be rendered
|
100
|
+
as HTML.
|
101
|
+
|
102
|
+
== Extending Custom Funtionality
|
103
|
+
|
104
|
+
The Radius context used to evaluate Radius tags is exposed via a global variable
|
105
|
+
called +$editable_content_radius_context+. To use this create a model file as
|
106
|
+
follows, and include it in your application_controller.rb file.
|
107
|
+
|
108
|
+
module ExtendContent
|
109
|
+
|
110
|
+
$editable_content_radius_context.with do |c|
|
111
|
+
|
112
|
+
c.define_tag 'test' do |tag|
|
113
|
+
number = (tag.attr['times'] || '1').to_i
|
114
|
+
result = ''
|
115
|
+
number.times { result << 'test ' }
|
116
|
+
result
|
117
|
+
end
|
118
|
+
|
119
|
+
c.define_tag 'user' do |tag|
|
120
|
+
if (!tag.attr['email'].blank?) || (!tag.attr['id'].blank?)
|
121
|
+
if !tag.attr['email'].blank?
|
122
|
+
item = User.where(:email=>tag.attr['email']).email
|
123
|
+
elsif !tag.attr['id'].blank?
|
124
|
+
item = User.find(tag.attr['id']).email
|
125
|
+
end
|
126
|
+
else
|
127
|
+
item = "unknown"
|
128
|
+
end
|
129
|
+
item
|
130
|
+
end
|
131
|
+
|
132
|
+
end # end of context
|
133
|
+
|
134
|
+
end # end of module
|
135
|
+
|
136
|
+
|
4
137
|
|
5
138
|
== Note on Patches/Pull Requests
|
6
|
-
|
139
|
+
|
7
140
|
* Fork the project.
|
8
141
|
* Make your feature addition or bug fix.
|
9
142
|
* Add tests for it. This is important so I don't break it in a
|
@@ -14,4 +147,4 @@ Description goes here.
|
|
14
147
|
|
15
148
|
== Copyright
|
16
149
|
|
17
|
-
Copyright (c) 2010
|
150
|
+
Copyright (c) 2010 Will Merrell. See LICENSE for details.
|
data/lib/editable_content.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
-
require 'rails'
|
1
|
+
require 'rails' if defined?(Rails) && Rails::VERSION::MAJOR == 3
|
2
|
+
require 'action_controller'
|
3
|
+
require 'action_view'
|
4
|
+
|
2
5
|
require 'radius'
|
3
6
|
require 'redcloth'
|
4
|
-
|
7
|
+
|
8
|
+
require 'editable_content/engine'
|
5
9
|
require 'editable_content/controller_helper'
|
6
|
-
require 'editable_content/
|
10
|
+
require 'editable_content/view_helpers'
|
7
11
|
|
8
12
|
module EditableContent
|
9
13
|
end
|
@@ -1,64 +1,112 @@
|
|
1
1
|
module EditableContent
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
2
|
+
module ControllerFunctions
|
3
|
+
|
4
|
+
#
|
5
|
+
# This function retrieves the editable content from the database.
|
6
|
+
# If +setEditableAuthorization+ is set to true then a button
|
7
|
+
# to launch the editor is prepended to the content.
|
8
|
+
#
|
9
|
+
# Each editable field needs will need one editor and they are created with
|
10
|
+
# the +create_content_editor+ function in the view file.
|
11
|
+
#
|
12
|
+
# === Parameters:
|
13
|
+
# *name* This is the name of the field. This is the same name that will be
|
14
|
+
# passed into the +create_content_editor+ function.
|
15
|
+
#
|
16
|
+
# === Usage:
|
17
|
+
# def index
|
18
|
+
# @content = getContent("maintext")
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
def getContent(name="")
|
22
|
+
text = "<div id=\"ec_edit_frame_#{name}\">" + getInnerContent(name, controller_name(), action_name()) + "</div>"
|
23
|
+
if $editable_content_authorization
|
24
|
+
text = "<img id=\"ec_edit_button_#{name}\" class=\"edit_icon\" width=\"16\" height=\"16\" src=\"/images/pencil.png\" title=\"Edit this Content\" alt=\"Edit this Content Button\" />" + text
|
11
25
|
end
|
26
|
+
text.html_safe
|
27
|
+
end
|
12
28
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
29
|
+
#
|
30
|
+
# This function formats the supplied content using the same processor that
|
31
|
+
# editable content uses.
|
32
|
+
#
|
33
|
+
# === Parameters:
|
34
|
+
# *content* The text to be converted. This expects a textile formated string
|
35
|
+
# and returns html formated text suitable for display.
|
36
|
+
#
|
37
|
+
# === Usage:
|
38
|
+
# def index
|
39
|
+
# @content = processContent("This is *textile* _text_.")
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
def processContent(content=nil)
|
43
|
+
if content
|
44
|
+
text = parseContent(content.gsub(/'/, "'"))
|
45
|
+
else
|
46
|
+
text = "<div class=\"error\">No Content.</div>".html_safe
|
19
47
|
end
|
48
|
+
end
|
20
49
|
|
21
|
-
|
50
|
+
# This is used to set up the permissions for the editable content system.
|
51
|
+
# This allows you to control who can edit a editable content field.
|
52
|
+
#
|
53
|
+
# === Parameters:
|
54
|
+
# *permission* A boolean value. If +true+ the editor is created and enabled,
|
55
|
+
# if +false+ the editor is not created.
|
56
|
+
#
|
57
|
+
# === Usage:
|
58
|
+
# The easiest way to use the permissions system is to use a +before_filter+
|
59
|
+
# in the application_controller, like this:
|
60
|
+
#
|
61
|
+
# before_filter proc{ setEditableAuthorization(current_user.is?( :editor )) }
|
62
|
+
#
|
63
|
+
# In this example, if the current user is an editor then they can edit fields.
|
64
|
+
#
|
65
|
+
def setEditableAuthorization(permission = false)
|
66
|
+
$editable_content_authorization = permission
|
67
|
+
end
|
22
68
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
69
|
+
private
|
70
|
+
|
71
|
+
def getInnerContent(name, controller, action)
|
72
|
+
content = EcContent.first( :conditions => { :name => name, :controller => controller, :action => action} )
|
73
|
+
if !content
|
74
|
+
text = "<div class=\"error\">No Content for #{controller}:#{action}.#{name}.</div>"
|
75
|
+
content = EcContent.new({ :name => name, :controller => controller, :action => action, :body => text })
|
76
|
+
content.save
|
77
|
+
else
|
78
|
+
if content.body.blank?
|
79
|
+
text = "<div class=\"error\">Content.body for #{controller}:#{action}.#{name} is blank.</div>"
|
29
80
|
else
|
30
|
-
|
31
|
-
text = "<div class=\"error\">Content.body for #{controller}:#{action}.#{name} is blank.</div>"
|
32
|
-
else
|
33
|
-
text = parseContent(content.body.gsub(/'/, "'"))
|
34
|
-
end
|
81
|
+
text = parseContent(content.body.gsub(/'/, "'"))
|
35
82
|
end
|
36
|
-
text.html_safe
|
37
83
|
end
|
84
|
+
text.html_safe
|
85
|
+
end
|
38
86
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
87
|
+
def parseContent(content)
|
88
|
+
parser = Radius::Parser.new($editable_content_radius_context, :tag_prefix => 'r')
|
89
|
+
text = RedCloth.new(parser.parse(content)).to_html.html_safe
|
90
|
+
end
|
43
91
|
|
44
|
-
|
45
|
-
|
92
|
+
# Define tags on a context that will be available to a template:
|
93
|
+
$editable_content_radius_context = Radius::Context.new do |c|
|
46
94
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
95
|
+
c.define_tag 'repeat' do |tag|
|
96
|
+
number = (tag.attr['times'] || '1').to_i
|
97
|
+
result = ''
|
98
|
+
number.times { result << tag.expand }
|
99
|
+
result
|
100
|
+
end
|
53
101
|
|
54
|
-
|
55
|
-
|
56
|
-
|
102
|
+
c.define_tag 'hello' do |tag|
|
103
|
+
"Hello #{tag.attr['name'] || 'World'}!"
|
104
|
+
end
|
57
105
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
106
|
+
c.define_tag 'lorem' do |tag|
|
107
|
+
word_count = (tag.attr['wordcount'] || '20').to_i
|
108
|
+
# ===== words
|
109
|
+
words =<<EOS
|
62
110
|
lorem ipsum dolor sit amet consectetuer adipiscing elit integer in mi a mauris ornare sagittis
|
63
111
|
suspendisse potenti suspendisse dapibus dignissim dolor nam sapien tellus tempus et tempus ac
|
64
112
|
tincidunt in arcu duis dictum proin magna nulla pellentesque non commodo et iaculis sit amet
|
@@ -130,48 +178,47 @@ quam nulla nulla nunc accumsan nunc sit amet scelerisque porttitor nibh pede
|
|
130
178
|
tristique mattis purus eros non velit aenean sagittis commodo erat aliquam id lacus morbi
|
131
179
|
vulputate vestibulum elit
|
132
180
|
EOS
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
end
|
160
|
-
twn +=1
|
161
|
-
pwn +=1
|
162
|
-
swn +=1
|
181
|
+
words.gsub!(/\n/,' ')
|
182
|
+
words.gsub!(/ */,' ')
|
183
|
+
words.strip!
|
184
|
+
words = words.split(/ /)
|
185
|
+
|
186
|
+
lorem = ""
|
187
|
+
|
188
|
+
# ===== total
|
189
|
+
twn = 0
|
190
|
+
twc = word_count
|
191
|
+
while twn < twc
|
192
|
+
|
193
|
+
# ===== paragraph
|
194
|
+
pwn = 0
|
195
|
+
pwc = rand(100)+50
|
196
|
+
while pwn < pwc and twn < twc do
|
197
|
+
|
198
|
+
# ===== sentence
|
199
|
+
swn = 0
|
200
|
+
swc = rand(10)+3
|
201
|
+
while swn < swc and pwn < pwc and twn < twc do
|
202
|
+
word = words[rand(words.length)]
|
203
|
+
if swn == 0
|
204
|
+
lorem << "#{word.capitalize} "
|
205
|
+
else
|
206
|
+
lorem << "#{word} "
|
163
207
|
end
|
164
|
-
|
208
|
+
twn +=1
|
209
|
+
pwn +=1
|
210
|
+
swn +=1
|
165
211
|
end
|
166
|
-
lorem << "
|
212
|
+
lorem << ". "
|
167
213
|
end
|
168
|
-
lorem
|
169
|
-
end
|
214
|
+
lorem << "\n\n"
|
215
|
+
end
|
216
|
+
lorem = lorem.gsub!(/ \./,'.')
|
217
|
+
end # end of lorem
|
170
218
|
|
171
|
-
|
219
|
+
end # end of $context
|
172
220
|
|
173
|
-
end
|
174
221
|
end
|
175
222
|
end
|
176
223
|
|
177
|
-
ActionController::Base.send :include, EditableContent::
|
224
|
+
ActionController::Base.send :include, EditableContent::ControllerFunctions
|
@@ -0,0 +1,138 @@
|
|
1
|
+
module EditableContent
|
2
|
+
module ViewHelpers
|
3
|
+
|
4
|
+
#
|
5
|
+
# This function inserts the code needed for editing editable content
|
6
|
+
# into the head section of the page.
|
7
|
+
#
|
8
|
+
# Each editable field needs will need one editor and they are created with
|
9
|
+
# the +create_content_editor+ function
|
10
|
+
#
|
11
|
+
# === Note
|
12
|
+
# This function creates an unobtursive javascript event handler that
|
13
|
+
# launches the editor. It uses +content_for+ to save the code in
|
14
|
+
# the following variables: +stylesheet_list+, +javascript_list+,
|
15
|
+
# and +javascript_data+. It assumes that you will have the following
|
16
|
+
# in your head section.
|
17
|
+
#
|
18
|
+
# <%= yield :stylesheet_list %>
|
19
|
+
# <%= yield :javascript_list %>
|
20
|
+
# <script type="text/javascript">
|
21
|
+
# <%= yield :javascript_data %>
|
22
|
+
# </script>
|
23
|
+
#
|
24
|
+
# === Usage
|
25
|
+
# <%= insert_editable_content -%>
|
26
|
+
# <%= create_content_editor("maintext") -%>
|
27
|
+
# <%= create_content_editor("contacttext") -%>
|
28
|
+
#
|
29
|
+
def insert_editable_content()
|
30
|
+
if $editable_content_authorization
|
31
|
+
content_for(:stylesheet_list) { stylesheet_link_tag "markitup/skins/simple/style.css" }
|
32
|
+
content_for(:stylesheet_list) { stylesheet_link_tag "markitup/sets/textile/style.css" }
|
33
|
+
content_for(:javascript_list) { javascript_include_tag "markitup/jquery.markitup.js" }
|
34
|
+
content_for(:javascript_list) { javascript_include_tag "markitup/sets/textile/set.js" }
|
35
|
+
content_for(:javascript_data) { <<-SCRIPTDATA
|
36
|
+
|
37
|
+
var content_id = 0;
|
38
|
+
var content_name = "";
|
39
|
+
|
40
|
+
function openEditor(name, controller, action) {
|
41
|
+
content_name = name;
|
42
|
+
$.get("/contents/edit",
|
43
|
+
{p_name:name, p_controller:controller, p_action:action},
|
44
|
+
jQuery.proxy(this, function(data) {
|
45
|
+
content_id = data.id;
|
46
|
+
$("#ec_edit_textarea").val(data.content);
|
47
|
+
$("#ec_edit_dialog_form").dialog('open');
|
48
|
+
}));
|
49
|
+
}
|
50
|
+
|
51
|
+
$(function() {
|
52
|
+
// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
|
53
|
+
$("#ec_edit_dialog_form").dialog("destroy");
|
54
|
+
|
55
|
+
$("#ec_edit_textarea").markItUp(mySettings);
|
56
|
+
|
57
|
+
$("#ec_edit_dialog_form").dialog({
|
58
|
+
autoOpen: false,
|
59
|
+
height: 375,
|
60
|
+
width: 1000,
|
61
|
+
modal: true,
|
62
|
+
buttons: {
|
63
|
+
'Save': function() {
|
64
|
+
$.post("/contents/update",
|
65
|
+
{p_id:content_id, p_content:$("#ec_edit_textarea").val()},
|
66
|
+
jQuery.proxy(this, function(data) {
|
67
|
+
$("#ec_edit_frame_" + content_name).html(data);
|
68
|
+
})
|
69
|
+
);
|
70
|
+
$(this).dialog('close');
|
71
|
+
},
|
72
|
+
Cancel: function() {
|
73
|
+
$(this).dialog('close');
|
74
|
+
}
|
75
|
+
},
|
76
|
+
close: function() {
|
77
|
+
$("#ec_edit_textarea").html("");
|
78
|
+
}
|
79
|
+
});
|
80
|
+
});
|
81
|
+
SCRIPTDATA
|
82
|
+
}
|
83
|
+
|
84
|
+
editor_text = <<EDITOR_FORM
|
85
|
+
<div id="ec_edit_dialog_form" title="Edit Content" style="padding: 0; display: none;">
|
86
|
+
<form style="padding: 5px 0 0 0;" >
|
87
|
+
<textarea name="ec_edit_textarea" id="ec_edit_textarea" cols="80" style="width: 99.5%; height: 200px; min_height: 200px;" class="ui_widget_content ui_corner_all" ></textarea>
|
88
|
+
</form>
|
89
|
+
</div>
|
90
|
+
EDITOR_FORM
|
91
|
+
editor_text.html_safe
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
#
|
96
|
+
# This function inserts the code needed to create the editor for a field
|
97
|
+
# into the head section of the page.
|
98
|
+
# Each editable field needs one editor and this is the function that
|
99
|
+
# creates it.
|
100
|
+
#
|
101
|
+
# === Parameters
|
102
|
+
# *name* This is the name of the field. This is the same name that will be
|
103
|
+
# passed into the +getContent+ function
|
104
|
+
#
|
105
|
+
# === Note
|
106
|
+
# This function creates an unobtursive javascript event handler that
|
107
|
+
# launches the editor. It uses +content_for+ to save the code in
|
108
|
+
# the +javascript_data+ variable. It assumes that you will have the following
|
109
|
+
# in your head section.
|
110
|
+
#
|
111
|
+
# <script type="text/javascript">
|
112
|
+
# <%= yield :javascript_data %>
|
113
|
+
# </script>
|
114
|
+
#
|
115
|
+
# === Usage
|
116
|
+
# <%= insert_editable_content -%>
|
117
|
+
# <%= create_content_editor("maintext") -%>
|
118
|
+
# <%= create_content_editor("contacttext") -%>
|
119
|
+
#
|
120
|
+
#
|
121
|
+
def create_content_editor(name)
|
122
|
+
if $editable_content_authorization
|
123
|
+
content_for(:javascript_data) { <<-SCRIPTDATA
|
124
|
+
$(function() {
|
125
|
+
$("#ec_edit_button_#{name}").click( function(event) {
|
126
|
+
openEditor("#{name}", "#{controller_name()}", "#{action_name()}");
|
127
|
+
event.preventDefault();
|
128
|
+
});
|
129
|
+
});
|
130
|
+
SCRIPTDATA
|
131
|
+
}
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
ActionView::Base.send :include, EditableContent::ViewHelpers
|
@@ -10,14 +10,14 @@ class EditableContentGenerator < Rails::Generators::Base
|
|
10
10
|
class_option :"skip-migration", :type => :boolean, :desc => "Don't generate a migration for the EcContent table"
|
11
11
|
class_option :"skip-routes", :type => :boolean, :desc => "Don't generate the routes for Editable Contents"
|
12
12
|
|
13
|
-
def install_routes(*args)
|
13
|
+
def install_routes(*args) #:nodoc:
|
14
14
|
unless options["skip-routes"]
|
15
15
|
route "get '/contents/edit', :as => :edit_content"
|
16
16
|
route "post '/contents/update', :as => :update_content"
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
def copy_files(*args)
|
20
|
+
def copy_files(*args) #:nodoc:
|
21
21
|
migration_template MIGRATIONS_FILE, "db/migrate/create_ec_contents.rb" unless options["skip-migration"]
|
22
22
|
end
|
23
23
|
|
data/test/helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: editable_content
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 5
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Will Merrell
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-12-19 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -79,9 +79,9 @@ files:
|
|
79
79
|
- app/views/contents/edit.html.erb
|
80
80
|
- app/views/layouts/contents.html.erb
|
81
81
|
- lib/editable_content.rb
|
82
|
-
- lib/editable_content/application_helpers.rb
|
83
82
|
- lib/editable_content/controller_helper.rb
|
84
83
|
- lib/editable_content/engine.rb
|
84
|
+
- lib/editable_content/view_helpers.rb
|
85
85
|
- lib/generators/editable_content_generator.rb
|
86
86
|
- LICENSE
|
87
87
|
- README.rdoc
|
@@ -1,88 +0,0 @@
|
|
1
|
-
module EditableContent
|
2
|
-
module ActionControllerExtensions
|
3
|
-
module ApplicationHelpers
|
4
|
-
def insert_editable_content()
|
5
|
-
if $editable_content_authorization
|
6
|
-
content_for(:stylesheet_list) { stylesheet_link_tag "markitup/skins/simple/style.css" }
|
7
|
-
content_for(:stylesheet_list) { stylesheet_link_tag "markitup/sets/textile/style.css" }
|
8
|
-
content_for(:javascript_list) { javascript_include_tag "markitup/jquery.markitup.js" }
|
9
|
-
content_for(:javascript_list) { javascript_include_tag "markitup/sets/textile/set.js" }
|
10
|
-
content_for(:javascript_data) { <<-SCRIPTDATA
|
11
|
-
|
12
|
-
var content_id = 0;
|
13
|
-
var content_name = "";
|
14
|
-
|
15
|
-
function openEditor(name, controller, action) {
|
16
|
-
content_name = name;
|
17
|
-
$.get("/contents/edit",
|
18
|
-
{p_name:name, p_controller:controller, p_action:action},
|
19
|
-
jQuery.proxy(this, function(data) {
|
20
|
-
content_id = data.id;
|
21
|
-
$("#ec_edit_textarea").val(data.content);
|
22
|
-
$("#ec_edit_dialog_form").dialog('open');
|
23
|
-
}));
|
24
|
-
}
|
25
|
-
|
26
|
-
$(function() {
|
27
|
-
// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
|
28
|
-
$("#ec_edit_dialog_form").dialog("destroy");
|
29
|
-
|
30
|
-
$("#ec_edit_textarea").markItUp(mySettings);
|
31
|
-
|
32
|
-
$("#ec_edit_dialog_form").dialog({
|
33
|
-
autoOpen: false,
|
34
|
-
height: 375,
|
35
|
-
width: 1000,
|
36
|
-
modal: true,
|
37
|
-
buttons: {
|
38
|
-
'Save': function() {
|
39
|
-
$.post("/contents/update",
|
40
|
-
{p_id:content_id, p_content:$("#ec_edit_textarea").val()},
|
41
|
-
jQuery.proxy(this, function(data) {
|
42
|
-
$("#ec_edit_frame_" + content_name).html(data);
|
43
|
-
})
|
44
|
-
);
|
45
|
-
$(this).dialog('close');
|
46
|
-
},
|
47
|
-
Cancel: function() {
|
48
|
-
$(this).dialog('close');
|
49
|
-
}
|
50
|
-
},
|
51
|
-
close: function() {
|
52
|
-
$("#ec_edit_textarea").html("");
|
53
|
-
}
|
54
|
-
});
|
55
|
-
});
|
56
|
-
SCRIPTDATA
|
57
|
-
}
|
58
|
-
|
59
|
-
editor_text = <<EDITOR_FORM
|
60
|
-
<div id="ec_edit_dialog_form" title="Edit Content" style="padding: 0; display: none;">
|
61
|
-
<form style="padding: 5px 0 0 0;" >
|
62
|
-
<textarea name="ec_edit_textarea" id="ec_edit_textarea" cols="80" style="width: 99.5%; height: 200px; min_height: 200px;" class="ui_widget_content ui_corner_all" ></textarea>
|
63
|
-
</form>
|
64
|
-
</div>
|
65
|
-
EDITOR_FORM
|
66
|
-
editor_text.html_safe
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def create_content_editor(name)
|
71
|
-
if $editable_content_authorization
|
72
|
-
content_for(:javascript_data) { <<-SCRIPTDATA
|
73
|
-
$(function() {
|
74
|
-
$("#ec_edit_button_#{name}").click( function(event) {
|
75
|
-
openEditor("#{name}", "#{controller_name()}", "#{action_name()}");
|
76
|
-
event.preventDefault();
|
77
|
-
});
|
78
|
-
});
|
79
|
-
SCRIPTDATA
|
80
|
-
}
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
ActionView::Base.send :include, EditableContent::ActionControllerExtensions::ApplicationHelpers
|