From d971d941df4351ad42b41896b3446f3d43fa9bcd Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Wed, 6 Feb 2008 22:27:46 +0100 Subject: [PATCH 01/12] Enhance include_into with alias_method_chaining, closing #152 --- vendor/plugins/aaa/init.rb | 38 ++++++++++++++--- vendor/plugins/aaa/test/include_into_test.rb | 45 ++++++++++++++++++++ 2 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 vendor/plugins/aaa/test/include_into_test.rb diff --git a/vendor/plugins/aaa/init.rb b/vendor/plugins/aaa/init.rb index a50e38c3..0743048a 100644 --- a/vendor/plugins/aaa/init.rb +++ b/vendor/plugins/aaa/init.rb @@ -3,7 +3,7 @@ Module.class_eval do # A hash that maps Class names to an array of Modules to mix in when the class is instantiated. - @@class_mixins = {} + @@class_mixins = {} unless defined?(@@class_mixins) mattr_reader :class_mixins # Specifies that this module should be included into the given classes when they are instantiated. @@ -11,18 +11,46 @@ # module FooMethods # include_into "Foo", "Bar" # end + # + # You can also specify a hash to have your module's methods alias_method_chained to the target + # class' methods. + # + # module FooMethods + # include_into "Foo", :method => :feature + # end + # + # This will alias Foo#method to the newly included FooMethods#method_with_feature. The former + # method Foo#method will continue to be available as Foo#method_without_feature. + # def include_into(*klasses) klasses.flatten! + aliases = klasses.last.is_a?(Hash) ? klasses.pop : {} klasses.each do |klass| - (@@class_mixins[klass] ||= []) << name.to_s + (@@class_mixins[klass] ||= []) << [name.to_s, aliases] @@class_mixins[klass].uniq! end end - + # add any class mixins that have been registered for this class def auto_include! - mixins = @@class_mixins[name] - send(:include, *mixins.collect { |name| name.constantize }) if mixins + if mixins = @@class_mixins[name] + mixins.each do |name, aliases| + include name.constantize + aliases.each { |args| alias_chain *args } + end + end + end + + def alias_chain(target, feature) + (class << self; self end).class_eval <<-EOC, __FILE__, __LINE__ + def method_added_with_#{target}_#{feature}(method) + if method == :#{target} && !method_defined?(:#{target}_without_#{feature}) + alias_method_chain :#{target}, :#{feature} + end + method_added_without_#{target}_#{feature}(method) + end + alias_method_chain :method_added, :#{target}_#{feature} + EOC end end diff --git a/vendor/plugins/aaa/test/include_into_test.rb b/vendor/plugins/aaa/test/include_into_test.rb new file mode 100644 index 00000000..ee82fdf5 --- /dev/null +++ b/vendor/plugins/aaa/test/include_into_test.rb @@ -0,0 +1,45 @@ +ENV['RAILS_ENV'] = 'test' +RAILS_ROOT = File.join(File.dirname(__FILE__), '../../../../') + +require 'rubygems' +require 'active_support' +require 'test/unit' + +require File.join(File.dirname(__FILE__), '..', 'init.rb') + +module Chocolate + include_into 'Cookie', 'Coffee', :taste => :chocolate + def taste_with_chocolate; "#{self.class.name} with chocolate!" end +end + +module Latte + include_into 'Coffee', 'Chai' +end + +class Cookie + def taste; "just a #{self.class.name}" end +end + +class Coffee + def taste; "just a #{self.class.name}" end +end + +class Chai +end + +class IncludeIntoTest < Test::Unit::TestCase + def test_module_should_be_included_to_given_classes + assert Cookie.included_modules.include?(Chocolate) + assert Coffee.included_modules.include?(Chocolate) + end + + def test_methods_should_be_alias_chained_in_given_classes + assert_equal 'Cookie with chocolate!', Cookie.new.taste + assert_equal 'Coffee with chocolate!', Coffee.new.taste + end + + def test_should_work_without_alias_option + assert Coffee.included_modules.include?(Latte) + assert Chai.included_modules.include?(Latte) + end +end \ No newline at end of file From e3d50f6906b0cd4fc641e645cea953bcbdb4143a Mon Sep 17 00:00:00 2001 From: rick Date: Sun, 10 Feb 2008 12:37:31 -0800 Subject: [PATCH 02/12] make the plugins index look more like the articles index --- app/views/admin/articles/index.rhtml | 2 +- app/views/admin/plugins/index.rhtml | 26 +++++++++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/views/admin/articles/index.rhtml b/app/views/admin/articles/index.rhtml index d33be898..dd6ea098 100644 --- a/app/views/admin/articles/index.rhtml +++ b/app/views/admin/articles/index.rhtml @@ -36,7 +36,7 @@ <% end %> -<% if @articles.any? %> +<% if @articles.size > 0 -%> <% content_tag :p, :class => 'total' do %> Total: <%= content_tag :strong, @articles.total_entries %> articles. diff --git a/app/views/admin/plugins/index.rhtml b/app/views/admin/plugins/index.rhtml index 2e8cf2c5..3e5a7835 100644 --- a/app/views/admin/plugins/index.rhtml +++ b/app/views/admin/plugins/index.rhtml @@ -1,13 +1,6 @@ - -<% content_for :sidebar do %> -
-Configurable plugins may include modifiable properties, notes, homepage, author, and version information. -
-<% end %> - -<% if @plugins.any? %> +<% if @plugins.size > 0 -%> - +
@@ -20,4 +13,19 @@ Configurable plugins may include modifiable properties, notes, homepage, author,
Plugin
+<% end %> + +<% content_for :action_nav do %> + + + +<% end -%> + +<% content_for :sidebar do %> +
+Configurable plugins may include modifiable properties, notes, homepage, author, and version information. +
<% end %> \ No newline at end of file From 4fa8ef5bc51ae5ed44489f6c794698465cd47d92 Mon Sep 17 00:00:00 2001 From: rick Date: Sun, 10 Feb 2008 12:50:41 -0800 Subject: [PATCH 03/12] stupid change --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index ce590c8e..d7a9f564 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -23,7 +23,7 @@ # use this order: :text, :title, :id, :class, :rel link_to_article article, "click here", "this article", "article-1", "articles", "whatever-rel-means" -* encode search/tag urls properly [rob-twf] +* encode search/tag urls properly. [rob-twf] * update article forms to explain new tag syntax (comma and space delimited tags) [xavier, rick] From c7467fc9cd283855b37c299d30435b996090fe14 Mon Sep 17 00:00:00 2001 From: rick Date: Sun, 10 Feb 2008 12:53:05 -0800 Subject: [PATCH 04/12] stupid change --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index d7a9f564..0c1b5f6e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -27,7 +27,7 @@ * update article forms to explain new tag syntax (comma and space delimited tags) [xavier, rick] -* start converting tests to rspec +* start converting tests to rspec. * tweak mephisto_init to support the new ActionController::Dispatcher class. [Rob Anderton] From 63595132bf71bf02fedd4e784d91ec5aeabaffe7 Mon Sep 17 00:00:00 2001 From: rick Date: Sun, 10 Feb 2008 13:09:06 -0800 Subject: [PATCH 05/12] stupid change --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 0c1b5f6e..12bef767 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -33,7 +33,7 @@ * Don't generate an article event for unversioned changes. [Marcus Brito] -* Switch to will_paginate plugin [Mislav] +* Switch to will_paginate plugin. [Mislav] * unit test fixes for those not using mysql or psql [Mislav] From 12c2a0e9120b1c0000f221712e0f9c7e8b6c2ff4 Mon Sep 17 00:00:00 2001 From: rick Date: Sun, 10 Feb 2008 13:09:47 -0800 Subject: [PATCH 06/12] stupid change --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 12bef767..e8773210 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,7 +2,7 @@ * Experimental comment preview. [court3nay] -* Add multi-site admin interface [Vincent, j2m] +* Add multi-site admin interface. [Vincent, j2m] * Update Wordpress converter to support Wordpress 2.3+ [Aubrey] From c22c0f8ed058a6779369627f6bfcecbd8dff07ce Mon Sep 17 00:00:00 2001 From: rick Date: Sun, 10 Feb 2008 13:10:28 -0800 Subject: [PATCH 07/12] stupid change --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index e8773210..835a75a0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -35,7 +35,7 @@ * Switch to will_paginate plugin. [Mislav] -* unit test fixes for those not using mysql or psql [Mislav] +* unit test fixes for those not using mysql or psql. [Mislav] * add comment moderation links to the overview [court3nay] From 92a285c5d4c8c58b6014f065e1e2a85d11aae4b3 Mon Sep 17 00:00:00 2001 From: rick Date: Sun, 10 Feb 2008 13:15:35 -0800 Subject: [PATCH 08/12] stupid change --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 835a75a0..57fb739a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -37,7 +37,7 @@ * unit test fixes for those not using mysql or psql. [Mislav] -* add comment moderation links to the overview [court3nay] +* add comment moderation links to the overview. [court3nay] * convert tests to use test/spec instead of simply bdd [Chris McGrath] From 9aff95d9073df6ad111917cc885f31a5e9b1b844 Mon Sep 17 00:00:00 2001 From: rick Date: Sun, 10 Feb 2008 13:18:20 -0800 Subject: [PATCH 09/12] stupid change --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 57fb739a..3480c7ec 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -39,7 +39,7 @@ * add comment moderation links to the overview. [court3nay] -* convert tests to use test/spec instead of simply bdd [Chris McGrath] +* convert tests to use test/spec instead of simply bdd. [Chris McGrath] * move xmlrpc stuff to plugin. rails doesn't include AWS anymore. May need some simple autodetection so the plugin just prints a warning if AWS isn't found. From e073c14e67be2ad14e5ffdf57a4371be2888f2ce Mon Sep 17 00:00:00 2001 From: rick Date: Sun, 10 Feb 2008 15:57:33 -0800 Subject: [PATCH 10/12] useless commit (testing post-receive hook) --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 3480c7ec..2e169fd2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -49,7 +49,7 @@ * Fix controllers so include_into works with them. -* Change plugin class/module to Mephisto::Plugin and Mephisto::Plugins. Sorry for the breakage (still technically experimental!) +* Change plugin class/module to Mephisto::Plugin and Mephisto::Plugins. Sorry for the breakage (still technically experimental!). * Fix admin overview date timezone. [Ben Wyrosdick] From a1a2cf95d10710f87b6f1b60819dcca164cf96fa Mon Sep 17 00:00:00 2001 From: rick Date: Sun, 10 Feb 2008 15:59:44 -0800 Subject: [PATCH 11/12] useless commit (testing post-receive hook) --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 2e169fd2..4885596e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,7 +4,7 @@ * Add multi-site admin interface. [Vincent, j2m] -* Update Wordpress converter to support Wordpress 2.3+ [Aubrey] +* Update Wordpress converter to support Wordpress 2.3+. [Aubrey] * refactor so that admin/comments is more restful, allow inline comment editing in the admin. [court3nay] From b9b07612fbb61a73530bd0920ef62ddbddfb2aa7 Mon Sep 17 00:00:00 2001 From: rick Date: Wed, 13 Feb 2008 10:06:05 -0800 Subject: [PATCH 12/12] fix bug in moderate comments page --- app/views/admin/articles/_page_nav.rhtml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/admin/articles/_page_nav.rhtml b/app/views/admin/articles/_page_nav.rhtml index 8eb5b1e4..e6e34c08 100644 --- a/app/views/admin/articles/_page_nav.rhtml +++ b/app/views/admin/articles/_page_nav.rhtml @@ -38,7 +38,7 @@
  •  
    • - <% if @article && controller.controller_name == 'articles' && controller.action_name == 'edit' %> + <% if @article && controller.controller_name == 'articles' && controller.action_name == 'edit' -%>
    • - <% end %> + <% end -%> <% if controller.controller_name == 'comments' && controller.action_name == 'index' -%>
    • @@ -54,7 +54,7 @@ <%= options_for_select ['All', 'Unapproved', 'Approved'], params[:filter].to_s.humanize %>
    • - <% end %> + <% end -%>
    -<% end unless @article.new_record? && @article.comments.empty? -%> \ No newline at end of file +<% end unless @article && @article.new_record? && @article.comments.size == 0 -%> \ No newline at end of file