Skip to content

Commit

Permalink
migration to replace keywords field, tags in field drawer instead
Browse files Browse the repository at this point in the history
  • Loading branch information
will-r committed Oct 11, 2011
1 parent 2883017 commit d9f8f62
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
5 changes: 2 additions & 3 deletions app/views/admin/assets/_tags.html.haml
Expand Up @@ -3,8 +3,7 @@
/ - include_javascript 'admin/taggable'
- fields_for :asset, @asset do |f|
%tr
%td.label
%label{:for=>"asset_title"}
= f.label :keywords
%th.label
= f.label :keywords
%td.field
= f.text_field :keywords, :class => 'textbox tagger'
9 changes: 9 additions & 0 deletions app/views/admin/pages/_tags.html.haml
@@ -0,0 +1,9 @@
/ - include_stylesheet 'admin/taggable'
/ - include_javascript 'autocomplete'
/ - include_javascript 'admin/taggable'
- fields_for :page, @page do |f|
%tr
%th.label
= f.label :keywords
%td.field
= f.text_field :keywords, :class => 'textbox tagger'
15 changes: 15 additions & 0 deletions db/migrate/20111011075109_keywords_field.rb
@@ -0,0 +1,15 @@
class KeywordsField < ActiveRecord::Migration
def self.up
Page.find(:all).each do |page|
if keywords = page.field(:keywords).try(:content)
page.attached_tags = Tag.from_list(keywords)
page.save
end
page.field(:keywords).delete
end
end

def self.down

end
end
3 changes: 0 additions & 3 deletions lib/taggable/model.rb
Expand Up @@ -119,9 +119,6 @@ def closely_related
self.attached_tags.empty? ? [] : self.class.from_all_tags(self.attached_tags) - [self]
end

# in the case of pages and anything else that keywords in the same way this overrides the existing column
# the rest of the time it's just another way of specifying tags.

def keywords
self.attached_tags.map {|t| t.title}.join(', ')
end
Expand Down
12 changes: 5 additions & 7 deletions taggable_extension.rb
Expand Up @@ -17,13 +17,11 @@ def activate
SiteController.send :include, Taggable::SiteController # some path and parameter handling in support of library pages
Admin::PagesController.send :include, Taggable::AdminPagesController # tweaks the admin interface to make page tags more prominent
UserActionObserver.instance.send :add_observer!, Tag # tags get creator-stamped

unless defined? admin.tag
Radiant::AdminUI.send :include, Taggable::AdminUI
Radiant::AdminUI.load_taggable_regions
admin.asset.edit.add :extended_metadata, 'furniture'
admin.asset.edit.add :extended_metadata, 'tags'
end
Radiant::AdminUI.send :include, Taggable::AdminUI unless defined? admin.tag
admin.tag ||= Radiant::AdminUI.load_taggable_regions
admin.asset.edit.add :extended_metadata, 'furniture'
admin.asset.edit.add :extended_metadata, 'tags'
admin.page.edit.add :extended_metadata, 'tags'

tab("Content") do
add_item("Tags", "/admin/tags")
Expand Down

0 comments on commit d9f8f62

Please sign in to comment.