Skip to content

Commit

Permalink
Refactor codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Trung Lê committed Aug 31, 2011
1 parent b3659d2 commit 6af0359
Show file tree
Hide file tree
Showing 19 changed files with 65 additions and 66 deletions.
3 changes: 2 additions & 1 deletion Versionfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"0.11.x" => { :branch => "0-11-x" }
"0.30.x" => { :branch => "0-30-x" }
"0.60.x" => { :branch => "master" }
"0.60.x" => { :branch => "0-60-x" }
"0.70.x" => { :branch => "master" }
2 changes: 1 addition & 1 deletion app/controllers/admin/comment_types_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
class Admin::CommentTypesController < Admin::ResourceController
end
end
2 changes: 1 addition & 1 deletion app/controllers/admin/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ class Admin::CommentsController < Admin::ResourceController
def location_after_save
:back
end
end
end
6 changes: 6 additions & 0 deletions app/controllers/admin/orders_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Admin::OrdersController.class_eval do
def comments
load_object
@comment_types = CommentType.where(:applies_to => "Order")
end
end
6 changes: 6 additions & 0 deletions app/controllers/admin/shipments_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Admin::ShipmentsController.class_eval do
def comments
load_object
@comment_types = CommentType.where(:applies_to => "Shipment")
end
end
3 changes: 3 additions & 0 deletions app/models/order_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Order.class_eval do
acts_as_commentable
end
3 changes: 3 additions & 0 deletions app/models/shipment_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Shipment.class_eval do
acts_as_commentable
end
6 changes: 3 additions & 3 deletions app/views/admin/comment_types/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<%- locals = {:f => f} -%>
<%= hook :admin_comment_type_form_fields, locals do %>
<%= f.field_container :name do %>
<%= f.label :name, t("name") %><br />
<%= f.label :name, t(:name) %><br />
<%= f.text_field :name, :class => 'fullwidth title' %>
<%= error_message_on :comment_type, :name %>
<% end %>
<%= f.field_container :applies_to do %>
<%= f.label :applies_to, t("applies_to") %><br />
<%= f.text_field :applies_to, :value => f.object.nil? ? "Order" : f.object.applies_to, :class => 'fullwidth title' %>
<%= f.label :applies_to, t(:applies_to) %><br />
<%= f.text_field :applies_to, :value => f.object.nil? ? 'Order' : f.object.applies_to, :class => 'fullwidth title' %>
<%= error_message_on :comment_type, :applies_to%>
<% end %>
Expand Down
8 changes: 4 additions & 4 deletions app/views/admin/comment_types/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<%= render :partial => 'admin/shared/configuration_menu' %>
<%= hook :admin_comment_type_edit_form_header do %>
<h1><%= t("editing_comment_type") %></h1>
<%= render "shared/error_messages", :target => @comment_type %>
<h1><%= t(:editing_comment_type) %></h1>
<%= render 'shared/error_messages', :target => @comment_type %>
<% end %>
<%= hook :admin_comment_type_edit_form do %>
<%= form_for(@comment_type, :url => object_url, :html => { :method => :put }) do |f| %>
<%= render :partial => "form", :locals => { :f => f } %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= hook :admin_comment_type_edit_form_buttons do %>
<%= render :partial => "admin/shared/edit_resource_links" %>
<%= render :partial => 'admin/shared/edit_resource_links' %>
<% end %>
<% end %>
<% end %>
14 changes: 7 additions & 7 deletions app/views/admin/comment_types/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<%= render :partial => 'admin/shared/configuration_menu' %>

<div class='toolbar'>
<ul class='actions'>
<div class="toolbar">
<ul class="actions">
<li>
<%= button_link_to t("new_comment_type"), new_object_url, :icon => 'add' %>
<%= button_link_to t(:new_comment_type), new_object_url, :icon => 'add' %>
</li>
</ul>
<br class='clear' />
<br class="clear" />
</div>

<h1><%= t("comment_types") %></h1>
<h1><%= t(:comment_types) %></h1>

<table class="index">
<thead>
<tr>
<%= hook :admin_comment_types_index_headers do %>
<th><%= t("name") %></th>
<th><%= t("applies_to") %></th>
<th><%= t(:name) %></th>
<th><%= t(:applies_to) %></th>
<% end %>
<th>
<% hook :admin_comment_types_index_header_actions %>
Expand Down
8 changes: 4 additions & 4 deletions app/views/admin/comment_types/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<%= render :partial => 'admin/shared/configuration_menu' %>
<%= hook :admin_comment_type_new_form_header do %>
<h1><%= t("new_comment_type") %></h1>
<h1><%= t(:new_comment_type) %></h1>

<%= render "shared/error_messages", :target => @comment_type %>
<%= render 'shared/error_messages', :target => @comment_type %>
<% end %>
<%= hook :admin_comment_type_new_form do %>
<%= form_for(:comment_type, :url => collection_url) do |f| %>
<%= render :partial => "form", :locals => { :f => f } %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= hook :admin_comment_type_new_form_buttons do %>
<%= render :partial => "admin/shared/new_resource_links" %>
<%= render :partial => 'admin/shared/new_resource_links' %>
<% end %>
<% end %>
<% end %>
4 changes: 2 additions & 2 deletions app/views/admin/orders/_tab.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<li <%= raw ' class="active"' if (defined? current and current == "Comments") %>>
<%= link_to t("comments"), comments_admin_order_url(@order) %>
<li <%= raw ' class="active"' if (defined? current and current == 'Comments') %>>
<%= link_to t(:comments), comments_admin_order_url(@order) %>
</li>
4 changes: 2 additions & 2 deletions app/views/admin/orders/comments.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<%= render "admin/shared/order_tabs", :current => "Comments" %>
<%= render "admin/shared/comments", :commentable => @order %>
<%= render 'admin/shared/order_tabs', :current => 'Comments' %>
<%= render 'admin/shared/comments', :commentable => @order %>
6 changes: 3 additions & 3 deletions app/views/admin/shared/_comment_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<tr>
<th style="width:140px;"><%= "#{I18n::t('spree.date')}/#{I18n::t('spree.time')}" %></th>
<% if @comment_types and !@comment_types.empty? %>
<th><%= I18n::t("type") %></th>
<th><%= t(:type) %></th>
<% end %>
<th><%= I18n::t("comment") %></th>
<th><%= t(:comment) %></th>
</tr>
<% commentable.comments.reverse.each_with_index do |comment, index| %>
<tr id="<%= dom_id(comment) %>">
Expand All @@ -14,7 +14,7 @@
<% end %>
<td>
<div id="order-comment-header-<%= index %>" class="order-comment-header">
<strong><%= comment.user.email + ' ' + I18n::t('said')%> :</strong>
<strong><%= comment.user.email + ' ' + t(:said)%> :</strong>
</div>
<div id="order-comment-body-<%= index %>" class="order-comment-body">
<%= comment.comment.html_safe %>
Expand Down
10 changes: 5 additions & 5 deletions app/views/admin/shared/_comments.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1><%= "#{t("comments")} #{(t('for') + " " + comments_for unless (comments_for rescue nil).nil?)}"%></h1>
<h1><%= "#{t(:comments)} #{(t(:for) + " " + comments_for unless (comments_for rescue nil).nil?)}"%></h1>

<%= render 'admin/shared/comment_list', :commentable => commentable %>

Expand All @@ -10,22 +10,22 @@

<table class="index">
<thead>
<th colspan="2"><%= t('add_comment') %></th>
<th colspan="2"><%= t(:add_comment) %></th>
</thead>
<tbody>
<% if @comment_types.present? %>
<tr>
<td><%= f.label :comment_type_id, t("type") %><br /></td>
<td><%= f.label :comment_type_id, t(:type) %><br /></td>
<td><%= f.select :comment_type_id, @comment_types.map{|ct| [ct.name, ct.id]},{} ,:class => 'title' %></td>
</tr>
<% end %>
<tr>
<td style="width:140px;"><%= f.label :comment, t("comment") %></td>
<td style="width:140px;"><%= f.label :comment, t(:comment) %></td>
<td><%= f.text_area :comment, {:style => 'height:150px;', :class => 'fullwidth'} %></td>
</tr>
<tr>
<td>&nbsp;</td>
<td> <%= button t('add_comment') %></td>
<td><%= button t(:add_comment) %></td>
</tr>
</tbody>
</table>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/shipments/_button.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<li>
<%= button_link_to(t("comments"), comments_admin_order_shipment_url(@order, @shipment)) %>
<%= button_link_to(t(:comments), comments_admin_order_shipment_url(@order, @shipment)) %>
</li>

4 changes: 2 additions & 2 deletions app/views/admin/shipments/comments.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<%= render "admin/shared/order_tabs", :current => "Shipments" %>
<%= render "admin/shared/comments", {:commentable => @shipment, :comments_for => "Shipment ##{@shipment.number}"} %>
<%= render 'admin/shared/order_tabs', :current => 'Shipments' %>
<%= render 'admin/shared/comments', {:commentable => @shipment, :comments_for => "Shipment ##{@shipment.number}"} %>
33 changes: 7 additions & 26 deletions lib/spree_comments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,12 @@ class Engine < Rails::Engine

config.autoload_paths += %W(#{config.root}/lib)

def self.activate
Order.class_eval do
acts_as_commentable
end

Shipment.class_eval do
acts_as_commentable
end

Admin::OrdersController.class_eval do
def comments
load_order
@comment_types = CommentType.where(:applies_to => "Order")
end
end

Admin::ShipmentsController.class_eval do
def comments
load_shipment
@comment_types = CommentType.where(:applies_to => "Shipment")
end
end

end
def self.activate
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
Rails.env.production? ? require(c) : load(c)
end
end

config.to_prepare &method(:activate).to_proc
end
config.to_prepare &method(:activate).to_proc
end
end
7 changes: 3 additions & 4 deletions spree_comments.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ Gem::Specification.new do |s|
s.name = 'spree_comments'
s.version = '1.0.0'
s.summary = 'Comments for orders and shipments'
s.homepage = 'http://www.spreecommerce.com'
s.homepage = 'https://github.com/spree/spree_comments'
s.author = 'Rails Dog'
s.email = 'gems@railsdog.com'
s.required_ruby_version = '>= 1.8.7'

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.require_paths = ["lib"]
s.has_rdoc = false
s.require_paths = ["lib"]

s.add_dependency('spree_core', '>=0.30.0')
s.add_dependency('spree_core', '>=0.60.1')
s.add_dependency('acts_as_commentable', '3.0.0')
end

0 comments on commit 6af0359

Please sign in to comment.