Permalink
Browse files

Added plugin 'seo_meta' to project, replacing our handling of meta ta…

…gs. Sooo meta.
  • Loading branch information...
1 parent 5f76c00 commit b6132a06ded2abd80fbe636b0328a6290178416c @parndt parndt committed Mar 29, 2011
View
@@ -56,5 +56,4 @@ end
# Add i18n support (optional, you can remove this if you really want to).
gem 'refinerycms-i18n', '~> 0.9.9.16'
-
# END USER DEFINED
View
@@ -35,6 +35,7 @@ PATH
refinerycms-core (~> 0.9.9.13)
refinerycms-pages (0.9.9.13)
refinerycms-core (~> 0.9.9.13)
+ seo_meta (~> 1.0.0)
refinerycms-resources (0.9.9.13)
dragonfly (~> 0.8.2)
rack-cache (>= 0.5.3)
@@ -207,6 +208,8 @@ GEM
ffi (>= 1.0.7)
json_pure
rubyzip
+ seo_meta (1.0.0)
+ refinerycms-generators (~> 1.0.1)
sqlite3 (1.3.3)
term-ansicolor (1.0.5)
thor (0.14.6)
@@ -0,0 +1,72 @@
+class CreateSeoMeta < ActiveRecord::Migration
+
+ def self.up
+ create_table :seo_meta do |t|
+ t.integer :seo_meta_id
+ t.string :seo_meta_type
+
+ t.string :browser_title
+ t.string :meta_keywords
+ t.text :meta_description
+
+ t.timestamps
+ end
+
+ add_index :seo_meta, :id
+ add_index :seo_meta, [:seo_meta_id, :seo_meta_type]
+
+ # Grab the attributes of the records that currently exist
+ existing_translations = ::Page::Translation.all.map(&:attributes)
+
+ # Remove columns
+ ::SeoMeta.attributes.keys.each do |field|
+ if ::Page::Translation.column_names.map(&:to_sym).include?(field)
+ remove_column ::Page::Translation.table_name, field
+ end
+ end
+
+ # Reset column information because otherwise the old columns will still exist.
+ ::Page::Translation.reset_column_information
+
+ # Re-attach seo_meta
+ ::Page::Translation.module_eval do
+ is_seo_meta
+ end
+
+ # Migrate data
+ existing_translations.each do |translation|
+ ::Page::Translation.find(translation['id']).update_attributes(
+ ::SeoMeta.attributes.keys.inject({}) {|attributes, name|
+ attributes.merge(name => translation[name.to_s])
+ }
+ )
+ end
+ end
+
+ def self.down
+ # Grab the attributes of the records that currently exist
+ existing_translations = ::Page::Translation.all.map(&:attributes)
+
+ # Add columns back to your model
+ ::SeoMeta.attributes.each do |field, field_type|
+ unless ::Page::Translation.column_names.map(&:to_sym).include?(field)
+ add_column ::Page::Translation.table_name, field, field_type
+ end
+ end
+
+ # Reset column information because otherwise the new columns won't exist yet.
+ ::Page::Translation.reset_column_information
+
+ # Migrate data
+ existing_translations.each do |translation|
+ ::Page::Translation.update_all(
+ ::SeoMeta.attributes.keys.inject({}) {|attributes, name|
+ attributes.merge(name => translation[name.to_s])
+ }, :id => translation['id']
+ )
+ end
+
+ drop_table :seo_meta
+ end
+
+end
View
@@ -3,6 +3,28 @@
class Page < ActiveRecord::Base
translates :title, :meta_keywords, :meta_description, :browser_title, :custom_title if self.respond_to?(:translates)
+
+ # Set up support for meta tags through translations.
+ if defined?(::Page::Translation) && Page::Translation.table_exists?
+ def translation
+ if @translation.nil? or @translation.try(:locale) != Globalize.locale
+ @translation = translations.with_locale(Globalize.locale).first
+ @translation ||= translations.build(:locale => Globalize.locale)
+ end
+
+ @translation
+ end
+
+ # Instruct the Translation model to have meta tags.
+ ::Page::Translation.module_eval do
+ is_seo_meta
+ end
+
+ # Delegate all SeoMeta attributes to the active translation.
+ delegate *(::SeoMeta.attributes.keys.map{|a| [a, :"#{a}="]}.flatten), :to => :translation
+ after_save proc {|m| m.translation.save}
+ end
+
attr_accessor :locale # to hold temporarily
validates :title, :presence => true
@@ -0,0 +1,72 @@
+class CreateSeoMeta < ActiveRecord::Migration
+
+ def self.up
+ create_table :seo_meta do |t|
+ t.integer :seo_meta_id
+ t.string :seo_meta_type
+
+ t.string :browser_title
+ t.string :meta_keywords
+ t.text :meta_description
+
+ t.timestamps
+ end
+
+ add_index :seo_meta, :id
+ add_index :seo_meta, [:seo_meta_id, :seo_meta_type]
+
+ # Grab the attributes of the records that currently exist
+ existing_translations = ::Page::Translation.all.map(&:attributes)
+
+ # Remove columns
+ ::SeoMeta.attributes.keys.each do |field|
+ if ::Page::Translation.column_names.map(&:to_sym).include?(field)
+ remove_column ::Page::Translation.table_name, field
+ end
+ end
+
+ # Reset column information because otherwise the old columns will still exist.
+ ::Page::Translation.reset_column_information
+
+ # Re-attach seo_meta
+ ::Page::Translation.module_eval do
+ is_seo_meta
+ end
+
+ # Migrate data
+ existing_translations.each do |translation|
+ ::Page::Translation.find(translation['id']).update_attributes(
+ ::SeoMeta.attributes.keys.inject({}) {|attributes, name|
+ attributes.merge(name => translation[name.to_s])
+ }
+ )
+ end
+ end
+
+ def self.down
+ # Grab the attributes of the records that currently exist
+ existing_translations = ::Page::Translation.all.map(&:attributes)
+
+ # Add columns back to your model
+ ::SeoMeta.attributes.each do |field, field_type|
+ unless ::Page::Translation.column_names.map(&:to_sym).include?(field)
+ add_column ::Page::Translation.table_name, field, field_type
+ end
+ end
+
+ # Reset column information because otherwise the new columns won't exist yet.
+ ::Page::Translation.reset_column_information
+
+ # Migrate data
+ existing_translations.each do |translation|
+ ::Page::Translation.find(translation['id']).update_attributes(
+ ::SeoMeta.attributes.keys.inject({}) {|attributes, name|
+ attributes.merge(name => translation[name.to_s])
+ }
+ )
+ end
+
+ drop_table :seo_meta
+ end
+
+end
View
@@ -26,6 +26,7 @@
]
s.add_dependency 'refinerycms-core', '~> #{::Refinery::Version}'
+ s.add_dependency 'seo_meta', '~> 1.0.0'
end
EOF
@@ -1,6 +1,7 @@
require 'refinerycms-core'
require 'awesome_nested_set'
require 'globalize3'
+require 'seo_meta'
module Refinery
module Pages
@@ -5,7 +5,7 @@ Gem::Specification.new do |s|
s.version = %q{0.9.9.13}
s.summary = %q{Pages engine for Refinery CMS}
s.description = %q{The default content engine of Refinery CMS. This engine handles the administration and display of user-editable pages.}
- s.date = %q{2011-03-28}
+ s.date = %q{2011-03-30}
s.email = %q{info@refinerycms.com}
s.homepage = %q{http://refinerycms.com}
s.rubyforge_project = %q{refinerycms}
@@ -87,6 +87,7 @@ Gem::Specification.new do |s|
'db/migrate/20101216194133_remove_cached_slug_from_pages.rb',
'db/migrate/20110307025652_translate_custom_title_on_pages.rb',
'db/migrate/20110314213540_remove_translated_fields_from_pages.rb',
+ 'db/migrate/20110329080451_create_seo_meta.rb',
'db/seeds',
'db/seeds/pages.rb',
'features',
@@ -115,4 +116,5 @@ Gem::Specification.new do |s|
]
s.add_dependency 'refinerycms-core', '~> 0.9.9.13'
+ s.add_dependency 'seo_meta', '~> 1.0.0'
end

0 comments on commit b6132a0

Please sign in to comment.