From 1bbeefe805efba28ef9c237a1c27f3f1ce1d5dc0 Mon Sep 17 00:00:00 2001 From: hukl Date: Mon, 2 Feb 2009 23:46:46 +0100 Subject: refactored the whole tagging thing. now using acts_as_taggable_on_steroids instead of a homebrew solution --- app/helpers/content_helper.rb | 4 ++- app/models/flag.rb | 3 --- app/models/page.rb | 41 +++---------------------------- db/migrate/20090201211159_create_flags.rb | 13 ---------- lib/update_importer.rb | 21 ++++------------ test/fixtures/flags.yml | 7 ------ test/unit/flag_test.rb | 8 ------ 7 files changed, 12 insertions(+), 85 deletions(-) delete mode 100644 app/models/flag.rb delete mode 100644 db/migrate/20090201211159_create_flags.rb delete mode 100644 test/fixtures/flags.yml delete mode 100644 test/unit/flag_test.rb diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb index 3cf3488..385bca0 100644 --- a/app/helpers/content_helper.rb +++ b/app/helpers/content_helper.rb @@ -10,7 +10,7 @@ module ContentHelper begin if content =~ /]*)>/ tag = $~.to_s - matched_data = $1.scan(/\w+\=\"[a-zA-Z\s\/_\d]*\"/) + matched_data = $1.scan(/\w+\=\"[a-zA-Z\s\/_\d,]*\"/) matched_data.each do |data| splitted_data = data.split("=") @@ -18,6 +18,8 @@ module ContentHelper end content.sub(tag, render_collection(options)) + else + content end rescue diff --git a/app/models/flag.rb b/app/models/flag.rb deleted file mode 100644 index 6d67377..0000000 --- a/app/models/flag.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Flag < ActiveRecord::Base - has_and_belongs_to_many :pages -end diff --git a/app/models/page.rb b/app/models/page.rb index e1bddb2..5908029 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -1,39 +1,9 @@ -# Alternativ queries for the named_scope with one or two inner joins. -# Loading the Flags themselves would be another query. -# Could be faster on larger data sets. -# -# Single Join: -# -# Page.find( -# :all, -# :joins => 'JOIN flags_pages on pages.id = flags_pages.page_id', -# :include => :flags, -# :conditions => ['flags_pages.flag_id IN (?)', [1,2]] -# ) -# Two inner joins: -# -# Page.find( -# :all, -# :joins => :flags_pages, -# :conditions => ['flags_pages.flag_id IN (?)', [1,2]] -# ) -# -# Page.find_by_sql("select p.* from pages p JOIN flags_pages f on p.id = f.page_id where (f.flag_id IN (1,2))") - class Page < ActiveRecord::Base belongs_to :node - has_and_belongs_to_many :flags - - acts_as_list :column => :revision, :scope => :node_id - named_scope :with_flags, lambda {|flag_names| - if (flags = Flag.find_all_by_name(flag_names)).empty? - {} - else - {:include => :flags, :conditions => ['flags_pages.flag_id IN (?)', flags.map(&:id)] } - end - } + acts_as_taggable + acts_as_list :column => :revision, :scope => :node_id # options[:limit], - :order => "#{options[:order_by]} #{options[:order_direction]}" - ) + debugger + pages = Page.find_tagged_with(options[:flags], :match_all => true) end end \ No newline at end of file diff --git a/db/migrate/20090201211159_create_flags.rb b/db/migrate/20090201211159_create_flags.rb deleted file mode 100644 index 3b9da43..0000000 --- a/db/migrate/20090201211159_create_flags.rb +++ /dev/null @@ -1,13 +0,0 @@ -class CreateFlags < ActiveRecord::Migration - def self.up - create_table :flags do |t| - t.string :name - - t.timestamps - end - end - - def self.down - drop_table :flags - end -end diff --git a/lib/update_importer.rb b/lib/update_importer.rb index 7947376..ec9033a 100644 --- a/lib/update_importer.rb +++ b/lib/update_importer.rb @@ -17,18 +17,7 @@ class UpdateImporter @updates = Node.create!( :slug => 'updates' ) @updates.move_to_child_of Node.root end - - unless @update_flag = Flag.find_by_name("update") - @update_flag = Flag.create!( :name => "update" ) - end - - unless @pm_flag = Flag.find_by_name("pressemitteilung") - @pm_flag = Flag.create!( :name => "pressemitteilung" ) - end - - unless @event_flag = Flag.find_by_name("event") - @event_flag = Flag.create!( :name => "event" ) - end + end # Class Methods @@ -96,12 +85,12 @@ class UpdateImporter ) end - page.flags << @update_flag if page + page.tag_list.add("update") if page if (flags = xhtml.elements['flags']) && page - page.flags << @event_flag if flags.attributes['calendar'] - page.flags << @pm_flag if flags.attributes['pm'] - + page.tag_list.add("event") if flags.attributes['calendar'] + page.tag_list.add("pressemitteilung") if flags.attributes['pm'] + page.save print "#{page.title} >>> " puts flags.attributes['calendar'].inspect end diff --git a/test/fixtures/flags.yml b/test/fixtures/flags.yml deleted file mode 100644 index 157d747..0000000 --- a/test/fixtures/flags.yml +++ /dev/null @@ -1,7 +0,0 @@ -# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html - -one: - name: MyString - -two: - name: MyString diff --git a/test/unit/flag_test.rb b/test/unit/flag_test.rb deleted file mode 100644 index 49b0d96..0000000 --- a/test/unit/flag_test.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'test_helper' - -class FlagTest < ActiveSupport::TestCase - # Replace this with your real tests. - test "the truth" do - assert true - end -end -- cgit v1.3