rails_page_comment 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +45 -0
- data/Rakefile +34 -0
- data/app/assets/javascripts/rails_page_comment/application.js +13 -0
- data/app/assets/javascripts/rails_page_comment/page_comments.js +2 -0
- data/app/assets/stylesheets/rails_page_comment/application.css +15 -0
- data/app/assets/stylesheets/rails_page_comment/page_comments.css +4 -0
- data/app/assets/stylesheets/scaffold.css +56 -0
- data/app/controllers/rails_page_comment/application_controller.rb +4 -0
- data/app/controllers/rails_page_comment/page_comments_controller.rb +62 -0
- data/app/helpers/rails_page_comment/application_helper.rb +4 -0
- data/app/helpers/rails_page_comment/page_comments_helper.rb +4 -0
- data/app/models/rails_page_comment/page_comment.rb +4 -0
- data/app/views/layouts/rails_page_comment/application.html.erb +14 -0
- data/app/views/rails_page_comment/page_comments/_form.html.erb +13 -0
- data/app/views/rails_page_comment/page_comments/edit.html.erb +1 -0
- data/app/views/rails_page_comment/page_comments/edit.js.erb +1 -0
- data/app/views/rails_page_comment/page_comments/index.html.erb +27 -0
- data/app/views/rails_page_comment/page_comments/new.html.erb +1 -0
- data/app/views/rails_page_comment/page_comments/show.html.erb +14 -0
- data/config/routes.rb +5 -0
- data/db/migrate/20141105030748_create_rails_page_comment_page_comments.rb +10 -0
- data/lib/generators/rails_page_comment/install_generator.rb +51 -0
- data/lib/generators/rails_page_comment/templates/active_record/migration.rb +16 -0
- data/lib/generators/rails_page_comment/templates/active_record/rails_page_comment/page_comment.rb +3 -0
- data/lib/generators/rails_page_comment/templates/rails_page_comment.rb +7 -0
- data/lib/rails_page_comment/controller_additions.rb +34 -0
- data/lib/rails_page_comment/controller_resource.rb +52 -0
- data/lib/rails_page_comment/engine.rb +10 -0
- data/lib/rails_page_comment/version.rb +3 -0
- data/lib/rails_page_comment.rb +20 -0
- data/lib/tasks/rails_page_comment_tasks.rake +4 -0
- data/test/controllers/rails_page_comment/page_comments_controller_test.rb +51 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -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/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -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 +82 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/assets.rb +8 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/log/development.log +0 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/fixtures/rails_page_comment/page_comments.yml +9 -0
- data/test/helpers/rails_page_comment/page_comments_helper_test.rb +6 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/models/rails_page_comment/page_comment_test.rb +9 -0
- data/test/rails_page_comment_test.rb +7 -0
- data/test/test_helper.rb +15 -0
- metadata +172 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4aa94be8d319a8caa4d8f6c65637473b0c5cc601
|
4
|
+
data.tar.gz: 97f909835fa5786c4b6a5013130f5fa9a29c5765
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 567e00422086e310d9114ded43d4b4f1e2bfb45b02916aa6accf13bf4de5d34945cc870fd5f7fb5e42a110e1aa01c48c08e66d7fa8e549c1c506b76e3dcb3d69
|
7
|
+
data.tar.gz: 012955440e9107f065a3082071c2ba36055411ec3ee904f8b881d3e9b7a77b67dec9cc9af5333beb8e94b0f230ef412f5918a3159c90f8b66ae4f465af4d381a
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 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,45 @@
|
|
1
|
+
# Rails Page Comment
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
Write comment on the page.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
For basic usage just include ckeditor gem:
|
12
|
+
|
13
|
+
```
|
14
|
+
gem 'rails_page_comment'
|
15
|
+
```
|
16
|
+
|
17
|
+
|
18
|
+
### How generate config files
|
19
|
+
|
20
|
+
|
21
|
+
```
|
22
|
+
rails generate rails_page_comment:install
|
23
|
+
```
|
24
|
+
|
25
|
+
|
26
|
+
To use set it show on the page or not, add this to an initializer.
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
# in config/initializers/rails_page_comment.rb
|
30
|
+
|
31
|
+
Ckeditor.setup do |config|
|
32
|
+
config.show_on_page = true/false
|
33
|
+
end
|
34
|
+
```
|
35
|
+
##Usage
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
class ApplicationController < ActionController::Base
|
39
|
+
|
40
|
+
page_comment_resource
|
41
|
+
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
This project rocks and uses MIT-LICENSE.
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'RailsPageComment'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.libs << 'test'
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
30
|
+
t.verbose = false
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
task default: :test
|
@@ -0,0 +1,13 @@
|
|
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
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
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 bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,56 @@
|
|
1
|
+
body { background-color: #fff; color: #333; }
|
2
|
+
|
3
|
+
body, p, ol, ul, td {
|
4
|
+
font-family: verdana, arial, helvetica, sans-serif;
|
5
|
+
font-size: 13px;
|
6
|
+
line-height: 18px;
|
7
|
+
}
|
8
|
+
|
9
|
+
pre {
|
10
|
+
background-color: #eee;
|
11
|
+
padding: 10px;
|
12
|
+
font-size: 11px;
|
13
|
+
}
|
14
|
+
|
15
|
+
a { color: #000; }
|
16
|
+
a:visited { color: #666; }
|
17
|
+
a:hover { color: #fff; background-color:#000; }
|
18
|
+
|
19
|
+
div.field, div.actions {
|
20
|
+
margin-bottom: 10px;
|
21
|
+
}
|
22
|
+
|
23
|
+
#notice {
|
24
|
+
color: green;
|
25
|
+
}
|
26
|
+
|
27
|
+
.field_with_errors {
|
28
|
+
padding: 2px;
|
29
|
+
background-color: red;
|
30
|
+
display: table;
|
31
|
+
}
|
32
|
+
|
33
|
+
#error_explanation {
|
34
|
+
width: 450px;
|
35
|
+
border: 2px solid red;
|
36
|
+
padding: 7px;
|
37
|
+
padding-bottom: 0;
|
38
|
+
margin-bottom: 20px;
|
39
|
+
background-color: #f0f0f0;
|
40
|
+
}
|
41
|
+
|
42
|
+
#error_explanation h2 {
|
43
|
+
text-align: left;
|
44
|
+
font-weight: bold;
|
45
|
+
padding: 5px 5px 5px 15px;
|
46
|
+
font-size: 12px;
|
47
|
+
margin: -7px;
|
48
|
+
margin-bottom: 0px;
|
49
|
+
background-color: #c00;
|
50
|
+
color: #fff;
|
51
|
+
}
|
52
|
+
|
53
|
+
#error_explanation ul li {
|
54
|
+
font-size: 12px;
|
55
|
+
list-style: square;
|
56
|
+
}
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require_dependency "rails_page_comment/application_controller"
|
2
|
+
|
3
|
+
module RailsPageComment
|
4
|
+
class PageCommentsController < ApplicationController
|
5
|
+
before_action :set_page_comment, only: [:show, :edit, :update, :destroy]
|
6
|
+
|
7
|
+
# GET /page_comments
|
8
|
+
def index
|
9
|
+
@page_comments = PageComment.all
|
10
|
+
end
|
11
|
+
|
12
|
+
# GET /page_comments/1
|
13
|
+
def show
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /page_comments/new
|
17
|
+
def new
|
18
|
+
@page_comment = PageComment.new
|
19
|
+
end
|
20
|
+
|
21
|
+
# GET /page_comments/1/edit
|
22
|
+
def edit
|
23
|
+
end
|
24
|
+
|
25
|
+
# POST /page_comments
|
26
|
+
def create
|
27
|
+
@page_comment = PageComment.new(create_page_comment_params)
|
28
|
+
if @page_comment.save
|
29
|
+
render :edit
|
30
|
+
else
|
31
|
+
render :nothing => true
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# PATCH/PUT /page_comments/1
|
36
|
+
def update
|
37
|
+
if @page_comment.update(update_page_comment_params)
|
38
|
+
render :edit
|
39
|
+
else
|
40
|
+
render :edit
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
private
|
46
|
+
# Use callbacks to share common setup or constraints between actions.
|
47
|
+
def set_page_comment
|
48
|
+
@page_comment = PageComment.find(params[:id])
|
49
|
+
end
|
50
|
+
|
51
|
+
# Only allow a trusted parameter "white list" through.
|
52
|
+
def create_page_comment_params
|
53
|
+
params.require(:page_comment).permit(:content, :page_uri)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Only allow a trusted parameter "white list" through.
|
57
|
+
def update_page_comment_params
|
58
|
+
params.require(:page_comment).permit(:content)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>RailsPageComment</title>
|
5
|
+
<%= stylesheet_link_tag "rails_page_comment/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "rails_page_comment/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<div style="text-align: center" id="page_comment">
|
2
|
+
<h1>本画面/機能の詳細仕様説明:</h1><br/>
|
3
|
+
<%= form_for(@page_comment, :remote => true) do |f| %>
|
4
|
+
<%= hidden_field_tag :authenticity_token, @_csrf_token%>
|
5
|
+
<div class="field">
|
6
|
+
<%= f.hidden_field :page_uri%>
|
7
|
+
<%= f.text_area :content, cols: 90, rows: 20%>
|
8
|
+
</div>
|
9
|
+
<div class="actions">
|
10
|
+
<%= f.submit "保存"%>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
</div>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render 'form' %>
|
@@ -0,0 +1 @@
|
|
1
|
+
$('#page_comment').html("<%= j render :partial => 'form'%>");alert('保存しました。');
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<h1>Listing page_comments</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<thead>
|
5
|
+
<tr>
|
6
|
+
<th>Requst uri</th>
|
7
|
+
<th>Content</th>
|
8
|
+
<th colspan="3"></th>
|
9
|
+
</tr>
|
10
|
+
</thead>
|
11
|
+
|
12
|
+
<tbody>
|
13
|
+
<% @page_comments.each do |page_comment| %>
|
14
|
+
<tr>
|
15
|
+
<td><%= page_comment.requst_uri %></td>
|
16
|
+
<td><%= page_comment.content %></td>
|
17
|
+
<td><%= link_to 'Show', page_comment %></td>
|
18
|
+
<td><%= link_to 'Edit', edit_page_comment_path(page_comment) %></td>
|
19
|
+
<td><%= link_to 'Destroy', page_comment, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
20
|
+
</tr>
|
21
|
+
<% end %>
|
22
|
+
</tbody>
|
23
|
+
</table>
|
24
|
+
|
25
|
+
<br>
|
26
|
+
|
27
|
+
<%= link_to 'New Page comment', new_page_comment_path %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render :partial => '/form' %>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<p id="notice"><%= notice %></p>
|
2
|
+
|
3
|
+
<p>
|
4
|
+
<strong>Requst uri:</strong>
|
5
|
+
<%= @page_comment.requst_uri %>
|
6
|
+
</p>
|
7
|
+
|
8
|
+
<p>
|
9
|
+
<strong>Content:</strong>
|
10
|
+
<%= @page_comment.content %>
|
11
|
+
</p>
|
12
|
+
|
13
|
+
<%= link_to 'Edit', edit_page_comment_path(@page_comment) %> |
|
14
|
+
<%= link_to 'Back', page_comments_path %>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
module RailsPageComment
|
5
|
+
module Generators
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
7
|
+
include Rails::Generators::Migration
|
8
|
+
|
9
|
+
desc "Generates migration for Page Comment (RailsPageComment) models"
|
10
|
+
|
11
|
+
def self.source_root
|
12
|
+
@source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.next_migration_number(dirname)
|
16
|
+
Time.now.strftime("%Y%m%d%H%M%S")
|
17
|
+
end
|
18
|
+
|
19
|
+
# copy configuration
|
20
|
+
def copy_initializer
|
21
|
+
template "rails_page_comment.rb", "config/initializers/rails_page_comment.rb"
|
22
|
+
end
|
23
|
+
|
24
|
+
def mount_engine
|
25
|
+
route "mount RailsPageComment::Engine => '/rails_page_comment'"
|
26
|
+
end
|
27
|
+
|
28
|
+
# def create_models
|
29
|
+
# [:page_comment].each do |filename|
|
30
|
+
# template "#{generator_dir}/rails_page_comment/#{filename}.rb",
|
31
|
+
# File.join('app/models', rails_page_comment_dir, "#{filename}.rb")
|
32
|
+
# end
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
def create_migrations
|
36
|
+
migration_template "#{generator_dir}/migration.rb", File.join('db/migrate', "create_rails_page_comment_page_comments.rb")
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
|
41
|
+
def rails_page_comment_dir
|
42
|
+
'rails_page_comment'
|
43
|
+
end
|
44
|
+
|
45
|
+
def generator_dir
|
46
|
+
@generator_dir ||= 'active_record'
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateRailsPageCommentPageComments < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :rails_page_comment_page_comments do |t|
|
4
|
+
t.string :page_uri, :null => false
|
5
|
+
|
6
|
+
t.text :content
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
|
10
|
+
add_index "rails_page_comment_page_comments", ["page_uri"], :name => "idx_rails_page_comment_page_comments_page_uri"
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
drop_table :rails_page_comment_page_comments
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module RailsPageComment
|
2
|
+
|
3
|
+
# This module is automatically included into all controllers.
|
4
|
+
module ControllerAdditions
|
5
|
+
module ClassMethods
|
6
|
+
# Sets up a before filter which loads and authorizes the current resource. This performs both
|
7
|
+
#
|
8
|
+
# class BooksController < ApplicationController
|
9
|
+
# page_comment_resource
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
def page_comment_resource(*args)
|
13
|
+
page_comment_resource_class.add_after_filter(self, :page_comment_resource, *args)
|
14
|
+
end
|
15
|
+
|
16
|
+
def page_comment_resource_class
|
17
|
+
ControllerResource
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.included(base)
|
24
|
+
base.extend ClassMethods
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
if defined? ActionController::Base
|
31
|
+
ActionController::Base.class_eval do
|
32
|
+
include RailsPageComment::ControllerAdditions
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module RailsPageComment
|
2
|
+
# Handle the load and authorization controller logic so we don't clutter up all controllers with non-interface methods.
|
3
|
+
# This class is used internally, so you do not need to call methods directly on it.
|
4
|
+
class ControllerResource # :nodoc:
|
5
|
+
|
6
|
+
ActionView::Base.send(:include, RailsPageComment::Engine.routes.url_helpers) # brings ActionDispatch::Routing::UrlFor
|
7
|
+
ActionView::Base.send(:include, ActionView::Helpers::TagHelper)
|
8
|
+
ActionView::Base.send(:include, ActiveSupport::Configurable)
|
9
|
+
ActionView::Base.send(:include, ActionController::RequestForgeryProtection)
|
10
|
+
|
11
|
+
def self.add_after_filter(controller_class, method, *args)
|
12
|
+
if RailsPageComment.show_on_page
|
13
|
+
options = args.extract_options!
|
14
|
+
resource_name = args.first
|
15
|
+
before_filter_method = options.delete(:prepend) ? :prepend_after_filter : :after_filter
|
16
|
+
controller_class.send(before_filter_method, options.slice(:only, :except, :if, :unless)) do |controller|
|
17
|
+
controller.class.page_comment_resource_class.new(controller, resource_name, options.except(:only, :except, :if, :unless)).send(method)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(controller, *args)
|
23
|
+
@controller = controller
|
24
|
+
@params = controller.params
|
25
|
+
@options = args.extract_options!
|
26
|
+
@name = args.first
|
27
|
+
end
|
28
|
+
|
29
|
+
def page_comment_resource
|
30
|
+
if !@controller.request.xhr?
|
31
|
+
page_controller = RailsPageComment::PageCommentsController.new
|
32
|
+
page_controller.request = @controller.request
|
33
|
+
av = ActionView::Base.new(File.join(Gem.loaded_specs['rails_page_comment'].full_gem_path, 'app', 'views', 'rails_page_comment', 'page_comments'), {}, )
|
34
|
+
page_uri = [@controller.params[:controller], @controller.params[:action]].join("/")
|
35
|
+
page_comment = RailsPageComment::PageComment.find_by(:page_uri => page_uri) || RailsPageComment::PageComment.new(:page_uri => page_uri)
|
36
|
+
av.assign({
|
37
|
+
:page_comment => page_comment,
|
38
|
+
:_csrf_token => @controller.session[:_csrf_token]
|
39
|
+
})
|
40
|
+
if page_comment.new_record?
|
41
|
+
html = av.render(:template => "new")
|
42
|
+
else
|
43
|
+
html = av.render(:template => "edit")
|
44
|
+
end
|
45
|
+
|
46
|
+
@controller.response.body = @controller.response.body.gsub('</body>',"#{html}</body>")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "rails_page_comment/version"
|
2
|
+
require 'rails_page_comment/engine'
|
3
|
+
require 'rails_page_comment/controller_resource'
|
4
|
+
require 'rails_page_comment/controller_additions'
|
5
|
+
|
6
|
+
module RailsPageComment
|
7
|
+
# Your code goes here...
|
8
|
+
mattr_accessor :show_on_page
|
9
|
+
@@show_on_page = true
|
10
|
+
|
11
|
+
module Helpers
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
def self.setup
|
17
|
+
yield self
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module RailsPageComment
|
4
|
+
class PageCommentsControllerTest < ActionController::TestCase
|
5
|
+
setup do
|
6
|
+
@page_comment = page_comments(:one)
|
7
|
+
end
|
8
|
+
|
9
|
+
test "should get index" do
|
10
|
+
get :index
|
11
|
+
assert_response :success
|
12
|
+
assert_not_nil assigns(:page_comments)
|
13
|
+
end
|
14
|
+
|
15
|
+
test "should get new" do
|
16
|
+
get :new
|
17
|
+
assert_response :success
|
18
|
+
end
|
19
|
+
|
20
|
+
test "should create page_comment" do
|
21
|
+
assert_difference('PageComment.count') do
|
22
|
+
post :create, page_comment: { content: @page_comment.content, requst_uri: @page_comment.requst_uri }
|
23
|
+
end
|
24
|
+
|
25
|
+
assert_redirected_to page_comment_path(assigns(:page_comment))
|
26
|
+
end
|
27
|
+
|
28
|
+
test "should show page_comment" do
|
29
|
+
get :show, id: @page_comment
|
30
|
+
assert_response :success
|
31
|
+
end
|
32
|
+
|
33
|
+
test "should get edit" do
|
34
|
+
get :edit, id: @page_comment
|
35
|
+
assert_response :success
|
36
|
+
end
|
37
|
+
|
38
|
+
test "should update page_comment" do
|
39
|
+
patch :update, id: @page_comment, page_comment: { content: @page_comment.content, requst_uri: @page_comment.requst_uri }
|
40
|
+
assert_redirected_to page_comment_path(assigns(:page_comment))
|
41
|
+
end
|
42
|
+
|
43
|
+
test "should destroy page_comment" do
|
44
|
+
assert_difference('PageComment.count', -1) do
|
45
|
+
delete :destroy, id: @page_comment
|
46
|
+
end
|
47
|
+
|
48
|
+
assert_redirected_to page_comments_path
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|