laurynasl-sunflower-comments 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/app/controllers/comments.rb +27 -0
- data/app/views/comments/new.html.erb +15 -0
- data/lib/sunflower-comments/sql/dynamic.sql +18 -0
- data/lib/sunflower-comments/sql/trigger.sql +20 -0
- metadata +8 -5
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ AUTHOR = "Laurynas Liutkus"
|
|
9
9
|
EMAIL = "laurynasl@gmail.com"
|
10
10
|
HOMEPAGE = "http://github.com/laurynasl/sunflower-comments/"
|
11
11
|
SUMMARY = "Merb Slice that provides sequel + postgres + comments = comment anything (polymorphic, with database triggers)"
|
12
|
-
GEM_VERSION = "0.0.
|
12
|
+
GEM_VERSION = "0.0.2"
|
13
13
|
|
14
14
|
spec = Gem::Specification.new do |s|
|
15
15
|
s.rubyforge_project = 'merb'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class SunflowerComments::Comments < SunflowerComments::Application
|
2
|
+
|
3
|
+
def create
|
4
|
+
@comment = Comment.new(params[:comment])
|
5
|
+
@comment.ip_address = request.remote_ip
|
6
|
+
@comment.user_id = current_user.id if logged_in?
|
7
|
+
@comment.parent_id = params[:parent_id]
|
8
|
+
@comment.parent_table = params[:parent_table]
|
9
|
+
@comment.save
|
10
|
+
redirect resource(@comment.parent)
|
11
|
+
end
|
12
|
+
|
13
|
+
def new
|
14
|
+
@reply_to_comment = Comment[params[:reply_to_comment_id]]
|
15
|
+
@parent = SunflowerComments.classes_hash[params[:parent_table]][params[:parent_id]]
|
16
|
+
user_login = @reply_to_comment.user ? @reply_to_comment.user.login : 'Anonimas'
|
17
|
+
@comment = Comment.new(
|
18
|
+
:body => "<blockquote>\n<i><strong>#{h user_login}</strong> rašė:</i>\n\n\n#{@reply_to_comment.body}\n</blockquote>\n\n"
|
19
|
+
)
|
20
|
+
render
|
21
|
+
end
|
22
|
+
|
23
|
+
def report
|
24
|
+
Comment.filter(:id => params[:id]).update(:reported => (:reported + 1))
|
25
|
+
"Ačiū, kad pranešėte. Patikrinsime."
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<%= fixed_form_for(@comment, :action => url(:"sunflower_comments_#{@parent.class.name.underscore}_comments", :parent_id => @parent.id)) do %>
|
2
|
+
<label for="comment_body">Comment:</label>
|
3
|
+
<br />
|
4
|
+
<%= text_area :body, :style => 'width: 500px; height: 200px;' %>
|
5
|
+
<br />
|
6
|
+
<%= submit 'Komentuoti' %>
|
7
|
+
<% end =%>
|
8
|
+
|
9
|
+
<script type='text/javascript'>
|
10
|
+
//<![CDATA[
|
11
|
+
|
12
|
+
$('comment_body').focus();
|
13
|
+
|
14
|
+
//]]>
|
15
|
+
</script>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
CREATE OR REPLACE FUNCTION on_#{table}_delete_bc() RETURNS TRIGGER AS $$
|
3
|
+
DECLARE
|
4
|
+
c integer;
|
5
|
+
s varchar;
|
6
|
+
BEGIN
|
7
|
+
SELECT INTO c COUNT(*) FROM comments WHERE parent_table = '#{table}' AND parent_id = OLD.id;
|
8
|
+
IF c > 0
|
9
|
+
THEN
|
10
|
+
RAISE EXCEPTION 'There are comments referencing #{table}';
|
11
|
+
ELSE
|
12
|
+
RETURN OLD;
|
13
|
+
END IF;
|
14
|
+
END;
|
15
|
+
$$ LANGUAGE plpgsql;
|
16
|
+
|
17
|
+
CREATE TRIGGER #{table}_delete_bc_trigger BEFORE DELETE ON #{table}
|
18
|
+
FOR EACH ROW EXECUTE PROCEDURE on_#{table}_delete_bc();
|
@@ -0,0 +1,20 @@
|
|
1
|
+
-- creates triggers for comments table
|
2
|
+
|
3
|
+
CREATE OR REPLACE FUNCTION on_comments_insert() RETURNS TRIGGER AS $$
|
4
|
+
DECLARE
|
5
|
+
c integer;
|
6
|
+
s varchar;
|
7
|
+
BEGIN
|
8
|
+
s := 'SELECT id FROM ' || NEW.parent_table || ' WHERE id = ' || NEW.parent_id;
|
9
|
+
EXECUTE s INTO c;
|
10
|
+
IF c IS NOT NULL
|
11
|
+
THEN
|
12
|
+
RETURN NEW;
|
13
|
+
ELSE
|
14
|
+
RAISE EXCEPTION 'Comment must reference parent';
|
15
|
+
END IF;
|
16
|
+
END;
|
17
|
+
$$ LANGUAGE plpgsql;
|
18
|
+
|
19
|
+
CREATE TRIGGER comments_insert_trigger BEFORE INSERT OR UPDATE ON comments
|
20
|
+
FOR EACH ROW EXECUTE PROCEDURE on_comments_insert();
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: laurynasl-sunflower-comments
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Laurynas Liutkus
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-30 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -39,6 +39,9 @@ files:
|
|
39
39
|
- TODO
|
40
40
|
- lib/sunflower-comments.rb
|
41
41
|
- lib/sunflower-comments
|
42
|
+
- lib/sunflower-comments/sql
|
43
|
+
- lib/sunflower-comments/sql/trigger.sql
|
44
|
+
- lib/sunflower-comments/sql/dynamic.sql
|
42
45
|
- lib/sunflower-comments/slicetasks.rb
|
43
46
|
- lib/sunflower-comments/merbtasks.rb
|
44
47
|
- lib/sunflower-comments/spectasks.rb
|
@@ -47,12 +50,12 @@ files:
|
|
47
50
|
- spec/controllers
|
48
51
|
- spec/controllers/main_spec.rb
|
49
52
|
- app/views
|
50
|
-
- app/views/
|
51
|
-
- app/views/
|
53
|
+
- app/views/comments
|
54
|
+
- app/views/comments/new.html.erb
|
52
55
|
- app/views/layout
|
53
56
|
- app/views/layout/sunflower_comments.html.erb
|
54
57
|
- app/controllers
|
55
|
-
- app/controllers/
|
58
|
+
- app/controllers/comments.rb
|
56
59
|
- app/controllers/application.rb
|
57
60
|
- app/helpers
|
58
61
|
- app/helpers/application_helper.rb
|