seo_meta 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ class SeoMetum < ActiveRecord::Base
2
+
3
+ end
@@ -0,0 +1,23 @@
1
+ class CreateSeoMeta < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ create_table :seo_meta do |t|
5
+ t.integer :seo_meta_id
6
+ t.string :seo_meta_type
7
+
8
+ t.string :browser_title
9
+ t.string :meta_keywords
10
+ t.text :meta_description
11
+
12
+ t.timestamps
13
+ end
14
+
15
+ add_index :seo_meta, :id
16
+ add_index :seo_meta, [:seo_meta_id, :seo_meta_type]
17
+ end
18
+
19
+ def self.down
20
+ drop_table :seo_meta
21
+ end
22
+
23
+ end
@@ -0,0 +1,9 @@
1
+ require 'refinerycms-generators'
2
+ require 'refinery/generators'
3
+
4
+ class SeoMetaGenerator < ::Refinery::Generators::EngineInstaller
5
+
6
+ source_root File.expand_path('../../../', __FILE__)
7
+ engine_name "seo_meta"
8
+
9
+ end
data/lib/seo_meta.rb ADDED
@@ -0,0 +1,45 @@
1
+ module SeoMeta
2
+
3
+ class << self
4
+ def attributes
5
+ @@attributes ||= {
6
+ :browser_title => :string,
7
+ :meta_keywords => :string,
8
+ :meta_description => :text
9
+ }
10
+ end
11
+ end
12
+
13
+ class Engine < ::Rails::Engine
14
+
15
+ end
16
+
17
+ autoload :ClassMethods, File.expand_path('../seo_meta/class_methods', __FILE__)
18
+ autoload :InstanceMethods, File.expand_path('../seo_meta/instance_methods', __FILE__)
19
+
20
+ end
21
+
22
+ def is_seo_meta(options = {})
23
+ # Let the base know about SeoMetum
24
+ has_one :seo_meta, :class_name => 'SeoMetum',
25
+ :foreign_key => :seo_meta_id, :dependent => :destroy,
26
+ :conditions => {:seo_meta_type => self.name}
27
+
28
+ # Let SeoMetum know about the base
29
+ ::SeoMetum.send :belongs_to, self.name.underscore.gsub('/', '_').to_sym,
30
+ :class_name => self.name
31
+
32
+ # Include the instance methods and extend with the class methods.
33
+ self.send :include, ::SeoMeta::InstanceMethods
34
+ extend ::SeoMeta::ClassMethods
35
+
36
+ # Ensure seo_meta is saved when the model is saved.
37
+ after_save :save_meta_tags
38
+
39
+ # Delegate both the accessor and setters for the fields to :seo_meta
40
+ fields = ::SeoMeta.attributes.keys.reject{|field|
41
+ self.column_names.map(&:to_sym).include?(field)
42
+ }.map{|a| [a, :"#{a}="]}.flatten
43
+
44
+ delegate *fields, :to => :seo_meta
45
+ end
@@ -0,0 +1,5 @@
1
+ module SeoMeta
2
+ module ClassMethods
3
+
4
+ end
5
+ end
@@ -0,0 +1,56 @@
1
+ module SeoMeta
2
+ module InstanceMethods
3
+
4
+ class << self
5
+ def included(base)
6
+ # This has to be introduced using module_eval because it overrides something.
7
+ base.module_eval do
8
+ def seo_meta
9
+ find_seo_meta_tags || build_seo_meta_tags
10
+ end
11
+
12
+ def attributes
13
+ super.merge(seo_meta_attributes)
14
+ end
15
+
16
+ def attributes=(attributes, *args)
17
+ attributes.update(seo_meta_attributes)
18
+ super
19
+ end
20
+
21
+ def update_attributes(attributes, *args)
22
+ attributes.update(seo_meta_attributes) if ::SeoMetum.table_exists?
23
+ super
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ def seo_meta_attributes
30
+ ::SeoMeta.attributes.keys.inject({}) { |attrs, name|
31
+ attrs.merge(name.to_s => send(name))
32
+ }
33
+ end
34
+
35
+ protected
36
+ def build_seo_meta_tags
37
+ if ::SeoMetum.table_exists?
38
+ @seo_meta ||= ::SeoMetum.new :seo_meta_type => self.class.name
39
+ end
40
+ end
41
+
42
+ def find_seo_meta_tags
43
+ if self.persisted? && ::SeoMetum.table_exists?
44
+ @seo_meta ||= ::SeoMetum.where(:seo_meta_type => self.class.name,
45
+ :seo_meta_id => self.id).first
46
+ end
47
+ end
48
+
49
+ def save_meta_tags
50
+ if ::SeoMetum.table_exists?
51
+ seo_meta.seo_meta_id ||= self.id
52
+ seo_meta.save
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,9 @@
1
+ namespace :seo_meta do
2
+
3
+ # call this task my running: rake seo_meta:my_task
4
+ # desc "Description of my task below"
5
+ # task :my_task => :environment do
6
+ # # add your logic here
7
+ # end
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: seo_meta
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.0.0
6
+ platform: ruby
7
+ authors:
8
+ - Philip Arndt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-03-29 00:00:00 +13:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: refinerycms-generators
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: 1.0.1
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ description: SEO Meta tags plugin for Ruby on Rails
28
+ email: parndt@gmail.com
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files: []
34
+
35
+ files:
36
+ - lib/generators/seo_meta_generator.rb
37
+ - lib/seo_meta/class_methods.rb
38
+ - lib/seo_meta/instance_methods.rb
39
+ - lib/seo_meta.rb
40
+ - lib/tasks/seo_meta.rake
41
+ - db/migrate/1_create_seo_meta.rb
42
+ - app/models/seo_metum.rb
43
+ has_rdoc: true
44
+ homepage: http://philiparndt.name
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options: []
49
+
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.6.1
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: SEO Meta tags plugin
71
+ test_files: []
72
+