editable_content 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/app/controllers/contents_controller.rb +52 -0
- data/app/models/ec_content.rb +2 -0
- data/app/views/contents/edit.html.erb +9 -0
- data/app/views/layouts/contents.html.erb +11 -0
- data/lib/editable_content/application_helpers.rb +88 -0
- data/lib/editable_content/controller_helper.rb +177 -0
- data/lib/editable_content/engine.rb +7 -0
- data/lib/editable_content.rb +9 -0
- data/lib/generators/editable_content_generator.rb +33 -0
- data/test/helper.rb +10 -0
- data/test/test_editable_content.rb +7 -0
- metadata +126 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 wmerrell
|
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,17 @@
|
|
1
|
+
= editable_content
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 wmerrell. See LICENSE for details.
|
@@ -0,0 +1,52 @@
|
|
1
|
+
class ContentsController < ApplicationController
|
2
|
+
|
3
|
+
# GET /contents/edit
|
4
|
+
def edit
|
5
|
+
if $editable_content_authorization
|
6
|
+
if request.xhr?
|
7
|
+
logger.debug("[Content.Edit] name = #{params[:p_name]}, controller = #{params[:p_controller]}, action = #{params[:p_action]}")
|
8
|
+
@content = EcContent.first( :conditions => { :name => params[:p_name], :controller => params[:p_controller], :action => params[:p_action]} )
|
9
|
+
val = {:id => @content.id, :content => @content.body}.to_json
|
10
|
+
logger.debug("[Content.Edit] return json = #{val.inspect}")
|
11
|
+
render :json => val
|
12
|
+
else
|
13
|
+
flash[:error] = 'This action expects an AJAX call.'
|
14
|
+
redirect_to root_url + "?nonajax"
|
15
|
+
end
|
16
|
+
|
17
|
+
else
|
18
|
+
flash[:error] = 'You are not authorized to perform that action.'
|
19
|
+
redirect_to root_url + "?unauthorized"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# POST /contents/update
|
24
|
+
def update
|
25
|
+
if $editable_content_authorization
|
26
|
+
|
27
|
+
if request.xhr?
|
28
|
+
@content = EcContent.find(params[:p_id])
|
29
|
+
new_content = params[:p_content]
|
30
|
+
logger.debug("[Content.Update] @content.id = #{@content.id}, new_content = #{new_content.inspect}")
|
31
|
+
if @content.update_attributes(:body=>new_content)
|
32
|
+
render :text => getInnerContent(@content.name, @content.controller, @content.action)
|
33
|
+
else
|
34
|
+
render :text => "fail", :status => 500
|
35
|
+
end
|
36
|
+
else
|
37
|
+
flash[:error] = 'This action expects an AJAX call.'
|
38
|
+
redirect_to root_url
|
39
|
+
end
|
40
|
+
else
|
41
|
+
flash[:error] = 'You are not authorized to perform that action.'
|
42
|
+
redirect_to root_url
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def help
|
47
|
+
unless $editable_content_authorization
|
48
|
+
flash[:error] = 'You are not authorized to perform that action.'
|
49
|
+
redirect_to root_url
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<div id="edit_frame">
|
2
|
+
<% form_for(@content) do |f| %>
|
3
|
+
<%= f.text_area :body %>
|
4
|
+
<div>
|
5
|
+
<%= link_to "Help", help_contents_path, {:style=>"float: right; margin: 5px 0 0 0;", :popup => ['Textile Help', 'scrollbars=1,height=400,width=800'] } %>
|
6
|
+
<p style="text-align: center;"><%= submit_tag %></p>
|
7
|
+
</div>
|
8
|
+
<% end %>
|
9
|
+
</div>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
7
|
+
<title>Editor</title>
|
8
|
+
<%= stylesheet_link_tag 'editor' %>
|
9
|
+
</head>
|
10
|
+
<body><%= yield %></body>
|
11
|
+
</html>
|
@@ -0,0 +1,88 @@
|
|
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
|
@@ -0,0 +1,177 @@
|
|
1
|
+
module EditableContent
|
2
|
+
module ActionControllerExtensions
|
3
|
+
module ControllerFunctions
|
4
|
+
|
5
|
+
def getContent(name="")
|
6
|
+
text = "<div id=\"ec_edit_frame_#{name}\">" + getInnerContent(name, controller_name(), action_name()) + "</div>"
|
7
|
+
if $editable_content_authorization
|
8
|
+
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
|
9
|
+
end
|
10
|
+
text.html_safe
|
11
|
+
end
|
12
|
+
|
13
|
+
def processContent(content)
|
14
|
+
if content
|
15
|
+
text = parseContent(content.gsub(/'/, "'"))
|
16
|
+
else
|
17
|
+
text = "<div class=\"error\">No Content.</div>".html_safe
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def getInnerContent(name, controller, action)
|
24
|
+
content = EcContent.first( :conditions => { :name => name, :controller => controller, :action => action} )
|
25
|
+
if !content
|
26
|
+
text = "<div class=\"error\">No Content for #{controller}:#{action}.#{name}.</div>"
|
27
|
+
content = EcContent.new({ :name => name, :controller => controller, :action => action, :body => text })
|
28
|
+
content.save
|
29
|
+
else
|
30
|
+
if content.body.blank?
|
31
|
+
text = "<div class=\"error\">Content.body for #{controller}:#{action}.#{name} is blank.</div>"
|
32
|
+
else
|
33
|
+
text = parseContent(content.body.gsub(/'/, "'"))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
text.html_safe
|
37
|
+
end
|
38
|
+
|
39
|
+
def parseContent(content)
|
40
|
+
parser = Radius::Parser.new($editable_content_radius_context, :tag_prefix => 'r')
|
41
|
+
text = RedCloth.new(parser.parse(content)).to_html.html_safe
|
42
|
+
end
|
43
|
+
|
44
|
+
# Define tags on a context that will be available to a template:
|
45
|
+
$editable_content_radius_context = Radius::Context.new do |c|
|
46
|
+
|
47
|
+
c.define_tag 'repeat' do |tag|
|
48
|
+
number = (tag.attr['times'] || '1').to_i
|
49
|
+
result = ''
|
50
|
+
number.times { result << tag.expand }
|
51
|
+
result
|
52
|
+
end
|
53
|
+
|
54
|
+
c.define_tag 'hello' do |tag|
|
55
|
+
"Hello #{tag.attr['name'] || 'World'}!"
|
56
|
+
end
|
57
|
+
|
58
|
+
c.define_tag 'lorem' do |tag|
|
59
|
+
word_count = (tag.attr['wordcount'] || '20').to_i
|
60
|
+
# ===== words
|
61
|
+
words =<<EOS
|
62
|
+
lorem ipsum dolor sit amet consectetuer adipiscing elit integer in mi a mauris ornare sagittis
|
63
|
+
suspendisse potenti suspendisse dapibus dignissim dolor nam sapien tellus tempus et tempus ac
|
64
|
+
tincidunt in arcu duis dictum proin magna nulla pellentesque non commodo et iaculis sit amet
|
65
|
+
mi mauris condimentum massa ut metus donec viverra sapien mattis rutrum tristique lacus eros
|
66
|
+
semper tellus et molestie nisi sapien eu massa vestibulum ante ipsum primis in faucibus orci
|
67
|
+
luctus et ultrices posuere cubilia curae; fusce erat tortor mollis ut accumsan ut lacinia
|
68
|
+
gravida libero curabitur massa felis accumsan feugiat convallis sit amet porta vel neque duis
|
69
|
+
et ligula non elit ultricies rutrum suspendisse tempor quisque posuere malesuada velit sed
|
70
|
+
pellentesque mi a purus integer imperdiet orci a eleifend mollis velit nulla iaculis arcu eu
|
71
|
+
rutrum magna quam sed elit nullam egestas integer interdum purus nec mauris vestibulum ac mi in
|
72
|
+
nunc suscipit dapibus duis consectetuer ipsum et pharetra sollicitudin metus turpis facilisis
|
73
|
+
magna vitae dictum ligula nulla nec mi nunc ante urna gravida sit amet congue et accumsan
|
74
|
+
vitae magna praesent luctus nullam in velit praesent est curabitur turpis class aptent taciti
|
75
|
+
sociosqu ad litora torquent per conubia nostra per inceptos hymenaeos cras consectetuer nibh in
|
76
|
+
lacinia ornare turpis sem tempor massa sagittis feugiat mauris nibh non tellus phasellus mi
|
77
|
+
fusce enim mauris ultrices turpis eu adipiscing viverra justo libero ullamcorper massa id
|
78
|
+
ultrices velit est quis tortor quisque condimentum lacus volutpat nonummy accumsan est nunc
|
79
|
+
imperdiet magna vulputate aliquet nisi risus at est aliquam imperdiet gravida tortor praesent
|
80
|
+
interdum accumsan ante vivamus est ligula consequat sed pulvinar eu consequat vitae eros nulla
|
81
|
+
elit nunc congue eget scelerisque a tempor ac nisi morbi facilisis pellentesque habitant morbi
|
82
|
+
tristique senectus et netus et malesuada fames ac turpis egestas in hac habitasse platea dictumst
|
83
|
+
suspendisse vel lorem ut ligula tempor consequat quisque consectetuer nisl eget elit proin quis
|
84
|
+
mauris ac orci accumsan suscipit sed ipsum sed vel libero nec elit feugiat blandit vestibulum
|
85
|
+
purus nulla accumsan et volutpat at pellentesque vel urna suspendisse nonummy aliquam pulvinar
|
86
|
+
libero donec vulputate orci ornare bibendum condimentum lorem elit dignissim sapien ut aliquam
|
87
|
+
nibh augue in turpis phasellus ac eros praesent luctus lorem a mollis lacinia leo turpis commodo
|
88
|
+
sem in lacinia mi quam et quam curabitur a libero vel tellus mattis imperdiet in congue neque ut
|
89
|
+
scelerisque bibendum libero lacus ullamcorper sapien quis aliquet massa velit vel orci fusce in
|
90
|
+
nulla quis est cursus gravida in nibh lorem ipsum dolor sit amet consectetuer adipiscing elit
|
91
|
+
integer fermentum pretium massa morbi feugiat iaculis nunc aenean aliquam pretium orci cum sociis
|
92
|
+
natoque penatibus et magnis dis parturient montes nascetur ridiculus mus vivamus quis tellus vel
|
93
|
+
quam varius bibendum fusce est metus feugiat at porttitor et cursus quis pede nam ut augue
|
94
|
+
nulla posuere phasellus at dolor a enim cursus vestibulum duis id nisi duis semper tellus ac
|
95
|
+
nulla vestibulum scelerisque lobortis dolor aenean a felis aliquam erat volutpat donec a magna
|
96
|
+
vitae pede sagittis lacinia cras vestibulum diam ut arcu mauris a nunc duis sollicitudin erat sit
|
97
|
+
amet turpis proin at libero eu diam lobortis fermentum nunc lorem turpis imperdiet id gravida
|
98
|
+
eget aliquet sed purus ut vehicula laoreet ante mauris eu nunc sed sit amet elit nec ipsum
|
99
|
+
aliquam egestas donec non nibh cras sodales pretium massa praesent hendrerit est et risus
|
100
|
+
vivamus eget pede curabitur tristique scelerisque dui nullam ullamcorper vivamus venenatis velit
|
101
|
+
eget enim nunc eu nunc eget felis malesuada fermentum quisque magna mauris ligula felis luctus
|
102
|
+
a aliquet nec vulputate eget magna quisque placerat diam sed arcu praesent sollicitudin
|
103
|
+
aliquam non sapien quisque id augue class aptent taciti sociosqu ad litora torquent per conubia
|
104
|
+
nostra per inceptos hymenaeos etiam lacus lectus mollis quis mattis nec commodo facilisis
|
105
|
+
nibh sed sodales sapien ac ante duis eget lectus in nibh lacinia auctor fusce interdum lectus non
|
106
|
+
dui integer accumsan quisque quam curabitur scelerisque imperdiet nisl suspendisse potenti nam
|
107
|
+
massa leo iaculis sed accumsan id ultrices nec velit suspendisse potenti mauris bibendum
|
108
|
+
turpis ac viverra sollicitudin metus massa interdum orci non imperdiet orci ante at ipsum etiam
|
109
|
+
eget magna mauris at tortor eu lectus tempor tincidunt phasellus justo purus pharetra ut
|
110
|
+
ultricies nec consequat vel nisi fusce vitae velit at libero sollicitudin sodales aenean mi
|
111
|
+
libero ultrices id suscipit vitae dapibus eu metus aenean vestibulum nibh ac massa vivamus
|
112
|
+
vestibulum libero vitae purus in hac habitasse platea dictumst curabitur blandit nunc non arcu ut
|
113
|
+
nec nibh morbi quis leo vel magna commodo rhoncus donec congue leo eu lacus pellentesque at erat
|
114
|
+
id mi consequat congue praesent a nisl ut diam interdum molestie fusce suscipit rhoncus sem donec
|
115
|
+
pretium aliquam molestie vivamus et justo at augue aliquet dapibus pellentesque felis morbi
|
116
|
+
semper in venenatis imperdiet neque donec auctor molestie augue nulla id arcu sit amet dui
|
117
|
+
lacinia convallis proin tincidunt proin a ante nunc imperdiet augue nullam sit amet arcu
|
118
|
+
quisque laoreet viverra felis lorem ipsum dolor sit amet consectetuer adipiscing elit in hac
|
119
|
+
habitasse platea dictumst pellentesque habitant morbi tristique senectus et netus et malesuada
|
120
|
+
fames ac turpis egestas class aptent taciti sociosqu ad litora torquent per conubia nostra per
|
121
|
+
inceptos hymenaeos nullam nibh sapien volutpat ut placerat quis ornare at lorem class aptent
|
122
|
+
taciti sociosqu ad litora torquent per conubia nostra per inceptos hymenaeos morbi dictum massa id
|
123
|
+
libero ut neque phasellus tincidunt nibh ut tincidunt lacinia lacus nulla aliquam mi a interdum
|
124
|
+
dui augue non pede duis nunc magna vulputate a porta at tincidunt a nulla praesent facilisis
|
125
|
+
suspendisse sodales feugiat purus cras et justo a mauris mollis imperdiet morbi erat mi ultrices
|
126
|
+
eget aliquam elementum iaculis id velit in scelerisque enim sit amet turpis sed aliquam odio
|
127
|
+
nonummy ullamcorper mollis lacus nibh tempor dolor sit amet varius sem neque ac dui nunc et est
|
128
|
+
eu massa eleifend mollis mauris aliquet orci quis tellus ut mattis praesent mollis consectetuer
|
129
|
+
quam nulla nulla nunc accumsan nunc sit amet scelerisque porttitor nibh pede lacinia justo
|
130
|
+
tristique mattis purus eros non velit aenean sagittis commodo erat aliquam id lacus morbi
|
131
|
+
vulputate vestibulum elit
|
132
|
+
EOS
|
133
|
+
words.gsub!(/\n/,' ')
|
134
|
+
words.gsub!(/ */,' ')
|
135
|
+
words.strip!
|
136
|
+
words = words.split(/ /)
|
137
|
+
|
138
|
+
lorem = ""
|
139
|
+
|
140
|
+
# ===== total
|
141
|
+
twn = 0
|
142
|
+
twc = word_count
|
143
|
+
while twn < twc
|
144
|
+
|
145
|
+
# ===== paragraph
|
146
|
+
pwn = 0
|
147
|
+
pwc = rand(100)+50
|
148
|
+
while pwn < pwc and twn < twc do
|
149
|
+
|
150
|
+
# ===== sentence
|
151
|
+
swn = 0
|
152
|
+
swc = rand(10)+3
|
153
|
+
while swn < swc and pwn < pwc and twn < twc do
|
154
|
+
word = words[rand(words.length)]
|
155
|
+
if swn == 0
|
156
|
+
lorem << "#{word.capitalize} "
|
157
|
+
else
|
158
|
+
lorem << "#{word} "
|
159
|
+
end
|
160
|
+
twn +=1
|
161
|
+
pwn +=1
|
162
|
+
swn +=1
|
163
|
+
end
|
164
|
+
lorem << ". "
|
165
|
+
end
|
166
|
+
lorem << "\n\n"
|
167
|
+
end
|
168
|
+
lorem = lorem.gsub!(/ \./,'.')
|
169
|
+
end # end of lorem
|
170
|
+
|
171
|
+
end # end of $context
|
172
|
+
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
ActionController::Base.send :include, EditableContent::ActionControllerExtensions::ControllerFunctions
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'radius'
|
3
|
+
require 'redcloth'
|
4
|
+
require 'editable_content/engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
|
5
|
+
require 'editable_content/controller_helper'
|
6
|
+
require 'editable_content/application_helpers'
|
7
|
+
|
8
|
+
module EditableContent
|
9
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
class EditableContentGenerator < Rails::Generators::Base
|
5
|
+
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
|
8
|
+
MIGRATIONS_FILE = File.join(File.dirname(__FILE__), "..", "..", "generators", "editable_content", "templates", "create_ec_contents.rb")
|
9
|
+
|
10
|
+
class_option :"skip-migration", :type => :boolean, :desc => "Don't generate a migration for the EcContent table"
|
11
|
+
class_option :"skip-routes", :type => :boolean, :desc => "Don't generate the routes for Editable Contents"
|
12
|
+
|
13
|
+
def install_routes(*args)
|
14
|
+
unless options["skip-routes"]
|
15
|
+
route "get '/contents/edit', :as => :edit_content"
|
16
|
+
route "post '/contents/update', :as => :update_content"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def copy_files(*args)
|
21
|
+
migration_template MIGRATIONS_FILE, "db/migrate/create_ec_contents.rb" unless options["skip-migration"]
|
22
|
+
end
|
23
|
+
|
24
|
+
# Taken from ActiveRecord's migration generator
|
25
|
+
def self.next_migration_number(dirname) #:nodoc:
|
26
|
+
if ActiveRecord::Base.timestamped_migrations
|
27
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
28
|
+
else
|
29
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: editable_content
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Will Merrell
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-11-13 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: RedCloth
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 49
|
30
|
+
segments:
|
31
|
+
- 4
|
32
|
+
- 2
|
33
|
+
- 3
|
34
|
+
version: 4.2.3
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: radius
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 5
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 6
|
49
|
+
- 1
|
50
|
+
version: 0.6.1
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: thoughtbot-shoulda
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
type: :development
|
66
|
+
version_requirements: *id003
|
67
|
+
description: Creates a new class, Editable_Content, which manages content which can be saved in a database and edited by a user.
|
68
|
+
email: will@morelandsolutions.com
|
69
|
+
executables: []
|
70
|
+
|
71
|
+
extensions: []
|
72
|
+
|
73
|
+
extra_rdoc_files:
|
74
|
+
- LICENSE
|
75
|
+
- README.rdoc
|
76
|
+
files:
|
77
|
+
- app/controllers/contents_controller.rb
|
78
|
+
- app/models/ec_content.rb
|
79
|
+
- app/views/contents/edit.html.erb
|
80
|
+
- app/views/layouts/contents.html.erb
|
81
|
+
- lib/editable_content.rb
|
82
|
+
- lib/editable_content/application_helpers.rb
|
83
|
+
- lib/editable_content/controller_helper.rb
|
84
|
+
- lib/editable_content/engine.rb
|
85
|
+
- lib/generators/editable_content_generator.rb
|
86
|
+
- LICENSE
|
87
|
+
- README.rdoc
|
88
|
+
- test/helper.rb
|
89
|
+
- test/test_editable_content.rb
|
90
|
+
has_rdoc: true
|
91
|
+
homepage: http://github.com/wmerrell/editable_content
|
92
|
+
licenses: []
|
93
|
+
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options:
|
96
|
+
- --charset=UTF-8
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
hash: 3
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
version: "0"
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
hash: 3
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
version: "0"
|
117
|
+
requirements: []
|
118
|
+
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 1.3.7
|
121
|
+
signing_key:
|
122
|
+
specification_version: 3
|
123
|
+
summary: Manages User Editable Content.
|
124
|
+
test_files:
|
125
|
+
- test/helper.rb
|
126
|
+
- test/test_editable_content.rb
|