spree_comments 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ *.swp
2
+ spec/test_app
data/Gemfile ADDED
@@ -0,0 +1,32 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'sqlite3-ruby', :require => 'sqlite3'
4
+
5
+ group :test do
6
+ gem 'rspec-rails', '= 2.4.1'
7
+ gem 'factory_girl_rails'
8
+ gem 'rcov'
9
+ gem 'shoulda'
10
+ gem 'faker'
11
+ if RUBY_VERSION < "1.9"
12
+ gem "ruby-debug"
13
+ else
14
+ gem "ruby-debug19"
15
+ end
16
+ end
17
+
18
+ group :cucumber do
19
+ gem 'cucumber-rails'
20
+ gem 'database_cleaner', '~> 0.5.2'
21
+ gem 'nokogiri'
22
+ gem 'capybara'
23
+ gem 'factory_girl_rails'
24
+ gem 'faker'
25
+ gem 'launchy'
26
+
27
+ if RUBY_VERSION < "1.9"
28
+ gem "ruby-debug"
29
+ else
30
+ gem "ruby-debug19"
31
+ end
32
+ end
@@ -0,0 +1,38 @@
1
+ # Spree Comments
2
+
3
+ Spree Comments is an extension for Spree to allow commenting on different models via the
4
+ admin ui and currently supports Orders & Shipments.
5
+
6
+ Spree Comments also supports optional comment Types which can be defined per comment-able
7
+ object (i.e. Order, Shipment, etc) via the admin Configuration tab.
8
+
9
+ This is based on a fork / rename of jderrett/spree-order-comments and is now an officially
10
+ supported extension.
11
+
12
+ Requirements:
13
+
14
+ * [acts\_as\_commentable](http://github.com/jackdempsey/acts_as_commentable) installed
15
+
16
+ Notes:
17
+
18
+ * Comments are read-only. You cannot edit or remove them from the Admin UI.
19
+
20
+ * Comment model and migration are included in the gem. You do NOT need to follow the
21
+ acts\_as\_commentable instructions for script/generate comment
22
+
23
+ ## Installation
24
+
25
+ 1. Add the following to your Gemfile
26
+ gem "spree_comments"
27
+ gem "acts_as_commentable"
28
+
29
+ 2. Run `bundle install`
30
+
31
+ 3. Copy over migrations via the rake task:
32
+ rake spree_comments:install
33
+
34
+ 4. Run the migrations: `rake db:migrate`
35
+
36
+ 5. Start your server: `script/rails s`
37
+
38
+
@@ -0,0 +1,69 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'rake'
4
+ require 'rake/testtask'
5
+
6
+ desc "Default Task"
7
+ task :default => [ :spec ]
8
+
9
+ gemfile = File.expand_path('../spec/test_app/Gemfile', __FILE__)
10
+ if File.exists?(gemfile) && %w(rcov spec cucumber).include?(ARGV.first.to_s)
11
+ require 'bundler'
12
+ ENV['BUNDLE_GEMFILE'] = gemfile
13
+ Bundler.setup
14
+
15
+ require 'rspec/core/rake_task'
16
+ RSpec::Core::RakeTask.new
17
+
18
+ require 'cucumber/rake/task'
19
+ Cucumber::Rake::Task.new do |t|
20
+ t.cucumber_opts = %w{--format pretty}
21
+ end
22
+
23
+ desc "Run specs with RCov"
24
+ RSpec::Core::RakeTask.new(:rcov) do |t|
25
+ t.rcov = true
26
+ t.rcov_opts = %w{ --exclude gems\/,spec\/,features\/}
27
+ t.verbose = true
28
+ end
29
+
30
+ end
31
+
32
+ desc "Regenerates a rails 3 app for testing"
33
+ task :test_app do
34
+ SPREE_PATH = ENV['SPREE_PATH']
35
+ raise "SPREE_PATH should be specified" unless SPREE_PATH
36
+ require File.join(SPREE_PATH, 'lib/generators/spree/test_app_generator')
37
+ class AuthTestAppGenerator < Spree::Generators::TestAppGenerator
38
+ def tweak_gemfile
39
+ append_file 'Gemfile' do
40
+ <<-gems
41
+ gem 'spree_core', :path => '#{File.join(SPREE_PATH, 'core')}'
42
+ gem 'spree_auth', :path => '#{File.join(SPREE_PATH, 'auth')}'
43
+ gem 'spree_comments', :path => '#{File.dirname(__FILE__)}'
44
+ gems
45
+ end
46
+ end
47
+
48
+ def install_gems
49
+ inside "test_app" do
50
+ run 'rake spree_core:install'
51
+ run 'rake spree_auth:install'
52
+ run 'rake spree_comments:install'
53
+ end
54
+ end
55
+
56
+ def migrate_db
57
+ run_migrations
58
+ end
59
+ end
60
+ AuthTestAppGenerator.start
61
+ end
62
+
63
+ namespace :test_app do
64
+ desc 'Rebuild test and cucumber databases'
65
+ task :rebuild_dbs do
66
+ system("cd spec/test_app && rake db:drop db:migrate RAILS_ENV=test && rake db:drop db:migrate RAILS_ENV=cucumber")
67
+ end
68
+ end
69
+
@@ -0,0 +1,7 @@
1
+ class Admin::CommentTypesController < Admin::BaseController
2
+ resource_controller
3
+
4
+ update.wants.html { redirect_to collection_url }
5
+ create.wants.html { redirect_to collection_url }
6
+ destroy.success.wants.js { render_js_for_destroy }
7
+ end
@@ -0,0 +1,9 @@
1
+ class Admin::CommentsController < Admin::BaseController
2
+ resource_controller
3
+
4
+ create.response do |wants|
5
+ # go to edit form after creating as new product
6
+ wants.html {redirect_to :back}
7
+ end
8
+
9
+ end
@@ -0,0 +1,16 @@
1
+ class Comment < ActiveRecord::Base
2
+ include ActsAsCommentable::Comment
3
+
4
+ belongs_to :commentable, :polymorphic => true
5
+ belongs_to :comment_type
6
+
7
+ default_scope :order => 'created_at ASC'
8
+
9
+ # NOTE: install the acts_as_votable plugin if you
10
+ # want user to vote on the quality of comments.
11
+ #acts_as_voteable
12
+
13
+ # NOTE: Comments belong to a user
14
+ belongs_to :user
15
+
16
+ end
@@ -0,0 +1,3 @@
1
+ class CommentType < ActiveRecord::Base
2
+ has_many :comments
3
+ end
@@ -0,0 +1,16 @@
1
+ <%- locals = {:f => f} -%>
2
+ <%= hook :admin_comment_type_form_fields, locals do %>
3
+ <%= f.field_container :name do %>
4
+ <%= f.label :name, t("name") %><br />
5
+ <%= f.text_field :name, :class => 'fullwidth title' %>
6
+ <%= error_message_on :comment_type, :name %>
7
+ <% end %>
8
+
9
+ <%= f.field_container :applies_to do %>
10
+ <%= f.label :applies_to, t("applies_to") %><br />
11
+ <%= f.text_field :applies_to, :value => f.object.nil? ? "Order" : f.object.applies_to, :class => 'fullwidth title' %>
12
+ <%= error_message_on :comment_type, :applies_to%>
13
+ <% end %>
14
+
15
+ <% end %>
16
+
@@ -0,0 +1,16 @@
1
+ <%= render :partial => 'admin/shared/configuration_menu' %>
2
+
3
+ <%= hook :admin_comment_type_edit_form_header do %>
4
+ <h1><%= t("editing_comment_type") %></h1>
5
+ <%= render "shared/error_messages", :target => @comment_type %>
6
+ <% end %>
7
+
8
+ <%= hook :admin_comment_type_edit_form do %>
9
+ <%= form_for(@comment_type, :url => object_url, :html => { :method => :put }) do |f| %>
10
+ <%= render :partial => "form", :locals => { :f => f } %>
11
+
12
+ <%= hook :admin_comment_type_edit_form_buttons do %>
13
+ <%= render :partial => "admin/shared/edit_resource_links" %>
14
+ <% end %>
15
+ <% end %>
16
+ <% end %>
@@ -0,0 +1,44 @@
1
+ <%= render :partial => 'admin/shared/configuration_menu' %>
2
+
3
+ <div class='toolbar'>
4
+ <ul class='actions'>
5
+ <li>
6
+ <%= button_link_to t("new_comment_type"), new_object_url, :icon => 'add' %>
7
+ </li>
8
+ </ul>
9
+ <br class='clear' />
10
+ </div>
11
+
12
+ <h1><%= t("comment_types") %></h1>
13
+
14
+ <table class="index">
15
+ <thead>
16
+ <tr>
17
+ <%= hook :admin_comment_types_index_headers do %>
18
+ <th><%= t("name") %></th>
19
+ <th><%= t("applies_to") %></th>
20
+ <% end %>
21
+ <th>
22
+ <% hook :admin_comment_types_index_header_actions %>
23
+ </th>
24
+ </tr>
25
+ </thead>
26
+ <tbody>
27
+ <% @comment_types.each do |comment_type| %>
28
+ <tr id="<%= dom_id comment_type %>">
29
+ <%- locals = {:comment_type => comment_type} -%>
30
+ <%= hook :admin_comment_types_index_rows, locals do %>
31
+ <td><%= comment_type.name %></td>
32
+ <td><%= comment_type.applies_to %></td>
33
+ <% end %>
34
+ <td width="140px">
35
+ <%= hook :admin_comment_types_index_row_actions, locals do %>
36
+ <%= link_to_edit comment_type %> &nbsp;
37
+ <%= link_to_delete comment_type %>
38
+ <% end %>
39
+ </td>
40
+ </tr>
41
+ <% end %>
42
+ </tbody>
43
+ </table>
44
+
@@ -0,0 +1,17 @@
1
+ <%= render :partial => 'admin/shared/configuration_menu' %>
2
+
3
+ <%= hook :admin_comment_type_new_form_header do %>
4
+ <h1><%= t("new_comment_type") %></h1>
5
+
6
+ <%= render "shared/error_messages", :target => @comment_type %>
7
+ <% end %>
8
+
9
+ <%= hook :admin_comment_type_new_form do %>
10
+ <%= form_for(:comment_type, :url => collection_url) do |f| %>
11
+ <%= render :partial => "form", :locals => { :f => f } %>
12
+
13
+ <%= hook :admin_comment_type_new_form_buttons do %>
14
+ <%= render :partial => "admin/shared/new_resource_links" %>
15
+ <% end %>
16
+ <% end %>
17
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <li <%= raw ' class="active"' if current == "Comments" %>>
2
+ <%= link_to t("comments"), comments_admin_order_url(@order) %>
3
+ </li>
@@ -0,0 +1,2 @@
1
+ <%= render "admin/shared/order_tabs", :current => "Comments" %>
2
+ <%= render "admin/shared/comments", :commentable => @order %>
@@ -0,0 +1,62 @@
1
+ <h1><%= "#{t("comments")} #{(t('for') + " " + comments_for unless (comments_for rescue nil).nil?)}"%></h1>
2
+
3
+ <table class="index">
4
+ <tr>
5
+ <th style="width:140px;"><%= "#{t('spree.date')}/#{t('spree.time')}" %></th>
6
+ <% unless @comment_types.empty? %>
7
+ <th><%= t("type") %></th>
8
+ <% end %>
9
+ <th><%= t("comment") %></th>
10
+ </tr>
11
+ <% commentable.comments.reverse.each_with_index do |comment, index| %>
12
+ <tr id="<%= dom_id(comment) %>">
13
+ <td><%= comment.created_at.to_formatted_s(:long) %></td>
14
+ <% unless @comment_types.empty? %>
15
+ <td><%= comment.comment_type.name if comment.comment_type %></td>
16
+ <% end %>
17
+ <td>
18
+ <div id="order-comment-header-<%= index %>" class="order-comment-header">
19
+ <strong><%= comment.user.email%> said:</strong>
20
+ </div>
21
+ <div id="order-comment-body-<%= index %>" class="order-comment-body">
22
+ <%= comment.comment %>
23
+ </div>
24
+ </td>
25
+ </tr>
26
+ <% end %>
27
+ </table>
28
+
29
+
30
+ <div class="order-add-comment">
31
+ <% form_for(:comment, :url => admin_comments_url) do |f| %>
32
+ <%= hidden_field_tag 'comment[commentable_id]', commentable.id %>
33
+ <%= hidden_field_tag 'comment[commentable_type]', commentable.class %>
34
+ <%= hidden_field_tag 'comment[user_id]', current_user.id %>
35
+
36
+ <table class="index">
37
+ <thead>
38
+ <th colspan="2"><%= t('add_comment') %></th>
39
+ </thead>
40
+ <tbody>
41
+ <% unless @comment_types.empty? %>
42
+ <tr>
43
+ <td><%= f.label :comment_type_id, t("type") %><br /></td>
44
+ <td><%= f.select :comment_type_id, @comment_types.map{|ct| [ct.name, ct.id]},{} ,:class => 'title' %></td>
45
+ </tr>
46
+ <% end %>
47
+ <tr>
48
+ <td style="width:140px;"><%= f.label :comment, t("comment") %></td>
49
+ <td><%= f.text_area :comment, {:style => 'height:150px;', :class => 'fullwidth'} %></td>
50
+ </tr>
51
+ <tr>
52
+ <td>&nbsp;</td>
53
+ <td> <%= button t('add_comment') %></td>
54
+ </tr>
55
+ </tbody>
56
+ </table>
57
+
58
+ <p class="form-buttons">
59
+
60
+ </p>
61
+ <% end %>
62
+ </div>
@@ -0,0 +1,4 @@
1
+ <li>
2
+ <%= button_link_to(t("comments"), comments_admin_order_shipment_url(@order, @shipment)) %>
3
+ </li>
4
+
@@ -0,0 +1,2 @@
1
+ <%= render "admin/shared/order_tabs", :current => "Shipments" %>
2
+ <%= render "admin/shared/comments", {:commentable => @shipment, :comments_for => "Shipment ##{@shipment.number}"} %>
@@ -0,0 +1,12 @@
1
+ ---
2
+ en:
3
+ for: for
4
+ comments: Comments
5
+ comment: Comment
6
+ add_comment: Add Comment
7
+ add_comment_type: Add Comment Type
8
+ comment_types: Comment Types
9
+ manage_comment_types: Manage comment types
10
+ applies_to: Applies To
11
+ new_comment_type: New Comment Type
12
+ editing_comment_type: Editing Comment Type
@@ -0,0 +1,33 @@
1
+
2
+ #map.namespace :admin do |admin|
3
+ # admin.resources :comments
4
+ # admin.resources :comment_types
5
+ #
6
+ # admin.resources :orders, :member => {:comments => :get} do |order|
7
+ # order.resources :shipments, :member => {:comments => :get}
8
+ # end
9
+ #end
10
+ #
11
+
12
+ Rails.application.routes.draw do
13
+ namespace :admin do
14
+ resources :comments
15
+ resources :comment_types
16
+
17
+ resources :orders do
18
+ member do
19
+ get :comments
20
+ end
21
+
22
+ resources :shipments do
23
+ member do
24
+ get :comments
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ #match '/admin/comments' => 'admin/comments', :via => [:get, :post]
31
+ # match '/admin/comment_types' => 'admin/comment_types', :via => [:get, :post]
32
+ end
33
+
@@ -0,0 +1,19 @@
1
+ class CreateComments < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :comments do |t|
4
+ t.string :title, :limit => 50, :default => ""
5
+ t.text :comment, :default => ""
6
+ t.references :commentable, :polymorphic => true
7
+ t.references :user
8
+ t.timestamps
9
+ end
10
+
11
+ add_index :comments, :commentable_type
12
+ add_index :comments, :commentable_id
13
+ add_index :comments, :user_id
14
+ end
15
+
16
+ def self.down
17
+ drop_table :comments
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ class CreateCommentTypes < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :comment_types do |t|
4
+ t.string :name
5
+ t.string :applies_to
6
+ t.timestamps
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table :comment_types
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ class AddTypeToComments < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :comments, :comment_type_id, :integer
4
+ end
5
+
6
+ def self.down
7
+ remove_column :comments, :comment_type_id
8
+ end
9
+ end
@@ -0,0 +1,37 @@
1
+ require 'spree_core'
2
+ require 'acts_as_commentable'
3
+ require 'spree_comments_hooks'
4
+
5
+ module SpreeComments
6
+ class Engine < Rails::Engine
7
+
8
+ config.autoload_paths += %W(#{config.root}/lib)
9
+
10
+ def self.activate
11
+ Order.class_eval do
12
+ acts_as_commentable
13
+ end
14
+
15
+ Shipment.class_eval do
16
+ acts_as_commentable
17
+ end
18
+
19
+ Admin::OrdersController.class_eval do
20
+ def comments
21
+ load_object
22
+ @comment_types = CommentType.find(:all, :conditions => {:applies_to => "Order"} )
23
+ end
24
+ end
25
+
26
+ Admin::ShipmentsController.class_eval do
27
+ def comments
28
+ load_object
29
+ @comment_types = CommentType.find(:all, :conditions => {:applies_to => "Shipment"} )
30
+ end
31
+ end
32
+
33
+ end
34
+
35
+ config.to_prepare &method(:activate).to_proc
36
+ end
37
+ end
@@ -0,0 +1,10 @@
1
+ class SpreeCommentsHooks < Spree::ThemeSupport::HookListener
2
+ insert_after :admin_order_tabs, :partial => "admin/orders/tab"
3
+
4
+ insert_after :admin_shipment_edit_buttons, :partial => "admin/shipments/button"
5
+
6
+ insert_after :admin_configurations_menu do
7
+ "<%= configurations_menu_item(I18n.t('comment_types'), admin_comment_types_url, I18n.t('manage_comment_types')) %>"
8
+ end
9
+
10
+ end
@@ -0,0 +1,15 @@
1
+ namespace :spree_comments do
2
+ desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
3
+ task :install do
4
+ Rake::Task['spree_comments:install:migrations'].invoke
5
+ end
6
+
7
+ namespace :install do
8
+ desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
9
+ task :migrations do
10
+ source = File.join(File.dirname(__FILE__), '..', '..', 'db')
11
+ destination = File.join(Rails.root, 'db')
12
+ Spree::FileUtilz.mirror_files(source, destination)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ Gem::Specification.new do |s|
2
+ s.platform = Gem::Platform::RUBY
3
+ s.name = 'spree_comments'
4
+ s.version = '1.0.0'
5
+ s.summary = 'Comments for orders and shipments'
6
+ s.homepage = 'http://www.spreecommerce.com'
7
+ s.author = 'Rails Dog'
8
+ s.email = 'gems@railsdog.com'
9
+ s.required_ruby_version = '>= 1.8.7'
10
+
11
+ s.files = `git ls-files`.split("\n")
12
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13
+ s.require_paths = ["lib"]
14
+ s.has_rdoc = false
15
+
16
+ s.add_dependency('spree_core', '>=0.30.0')
17
+ s.add_dependency('acts_as_commentable', '3.0.0')
18
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_comments
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Rails Dog
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-21 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: spree_core
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 103
30
+ segments:
31
+ - 0
32
+ - 30
33
+ - 0
34
+ version: 0.30.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: acts_as_commentable
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - "="
44
+ - !ruby/object:Gem::Version
45
+ hash: 7
46
+ segments:
47
+ - 3
48
+ - 0
49
+ - 0
50
+ version: 3.0.0
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ description:
54
+ email: gems@railsdog.com
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files: []
60
+
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - README.markdown
65
+ - Rakefile
66
+ - app/controllers/admin/comment_types_controller.rb
67
+ - app/controllers/admin/comments_controller.rb
68
+ - app/models/comment.rb
69
+ - app/models/comment_type.rb
70
+ - app/views/admin/comment_types/_form.html.erb
71
+ - app/views/admin/comment_types/edit.html.erb
72
+ - app/views/admin/comment_types/index.html.erb
73
+ - app/views/admin/comment_types/new.html.erb
74
+ - app/views/admin/orders/_tab.html.erb
75
+ - app/views/admin/orders/comments.html.erb
76
+ - app/views/admin/shared/_comments.html.erb
77
+ - app/views/admin/shipments/_button.html.erb
78
+ - app/views/admin/shipments/comments.html.erb
79
+ - config/locales/en.yml
80
+ - config/routes.rb
81
+ - db/migrate/20091021182639_create_comments.rb
82
+ - db/migrate/20100406085611_create_comment_types.rb
83
+ - db/migrate/20100406100728_add_type_to_comments.rb
84
+ - lib/spree_comments.rb
85
+ - lib/spree_comments_hooks.rb
86
+ - lib/tasks/install.rake
87
+ - spree_comments.gemspec
88
+ has_rdoc: true
89
+ homepage: http://www.spreecommerce.com
90
+ licenses: []
91
+
92
+ post_install_message:
93
+ rdoc_options: []
94
+
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 57
103
+ segments:
104
+ - 1
105
+ - 8
106
+ - 7
107
+ version: 1.8.7
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: Comments for orders and shipments
124
+ test_files: []
125
+