headshop 0.2.1 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -3,6 +3,58 @@ Headshop
3
3
 
4
4
  Meta tag management to DRY up your views and SEO the crap out of your site.
5
5
 
6
+ Installation
7
+ ------------
8
+
9
+ To get started with headshop add it to your gemfile:
10
+
11
+ gem 'headshop'
12
+
13
+ Usage
14
+ -----
15
+
16
+ Headshop relies on a yml file to determine the meta tags to display. Create an initializer file (config/intializers/headshop.rb) and tell headshop where your yml file is located.
17
+
18
+ Headshop.setup do |config|
19
+ config.config_file = File.join(Rails.root, 'config', 'headshop.yml')
20
+ end
21
+
22
+ Headshop will search the yml file with the controller name/action name to find the correct tags. To populate the meta tags for the index action on the landing controller:
23
+
24
+ landing:
25
+ index:
26
+ title: Landing Page
27
+ description: Landing Page
28
+ keywords: landing, page
29
+
30
+ Headshop will also look for default meta tags if they are defined. If headshop cannot locate the tags for a controller/action pair, the default tags will be displayed.
31
+
32
+ default_meta:
33
+ title: Default Page
34
+ description: Default Page
35
+ keywords: default, page
36
+
37
+ You can also apply base tags to each matching tag:
38
+
39
+ base_meta:
40
+ title: Headshop |
41
+ description: Headshop |
42
+ keywords: headshop
43
+
44
+ This will output (given the default_meta above):
45
+
46
+ <title>Headshop | Default Page</title>
47
+ <meta name='title' content='Headshop | Default Page' />
48
+ <meta name='description' content='Headshop | Default Page' />
49
+ <meta name='keywords' content='headshop, default, page' />
50
+
51
+ Meta tags aren't limited to title, description and keywords. Headshop will apply any meta tag found in the yml file to your view.
52
+
53
+ Display the meta tag in your view with the meta_tag helper:
54
+
55
+ = meta_tag
56
+
57
+
6
58
  Contributing to providence
7
59
  --------------------------
8
60
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.1
data/headshop.gemspec ADDED
@@ -0,0 +1,79 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{headshop}
8
+ s.version = "0.3.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Chuck Collins"]
12
+ s.date = %q{2011-05-13}
13
+ s.description = %q{Manage meta tags through an external yml file. Easy configuration. Takes ugly boilerplate away from your app.}
14
+ s.email = %q{chuck.collins@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rvmrc",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.markdown",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "headshop.gemspec",
29
+ "lib/headshop.rb",
30
+ "lib/headshop/meta_tag_helper.rb",
31
+ "spec/headshop.yml",
32
+ "spec/headshop_no_default_no_base.yml",
33
+ "spec/lib/headshop/meta_tag_helper_spec.rb",
34
+ "spec/lib/headshop_spec.rb",
35
+ "spec/spec_helper.rb"
36
+ ]
37
+ s.homepage = %q{http://github.com/ccollins/headshop}
38
+ s.licenses = ["MIT"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = %q{1.3.7}
41
+ s.summary = %q{Meta tag management to DRY up your views and SEO the crap out of your site.}
42
+ s.test_files = [
43
+ "spec/lib/headshop/meta_tag_helper_spec.rb",
44
+ "spec/lib/headshop_spec.rb",
45
+ "spec/spec_helper.rb"
46
+ ]
47
+
48
+ if s.respond_to? :specification_version then
49
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
+ s.specification_version = 3
51
+
52
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
54
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
55
+ s.add_development_dependency(%q<mocha>, [">= 0"])
56
+ s.add_development_dependency(%q<providence>, [">= 0"])
57
+ s.add_development_dependency(%q<rails>, [">= 0"])
58
+ s.add_development_dependency(%q<rspec-rails>, [">= 0"])
59
+ s.add_development_dependency(%q<rcov>, [">= 0"])
60
+ else
61
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
62
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
63
+ s.add_dependency(%q<mocha>, [">= 0"])
64
+ s.add_dependency(%q<providence>, [">= 0"])
65
+ s.add_dependency(%q<rails>, [">= 0"])
66
+ s.add_dependency(%q<rspec-rails>, [">= 0"])
67
+ s.add_dependency(%q<rcov>, [">= 0"])
68
+ end
69
+ else
70
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
71
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
72
+ s.add_dependency(%q<mocha>, [">= 0"])
73
+ s.add_dependency(%q<providence>, [">= 0"])
74
+ s.add_dependency(%q<rails>, [">= 0"])
75
+ s.add_dependency(%q<rspec-rails>, [">= 0"])
76
+ s.add_dependency(%q<rcov>, [">= 0"])
77
+ end
78
+ end
79
+
data/lib/headshop.rb CHANGED
@@ -16,12 +16,7 @@ module Headshop
16
16
  def self.setup
17
17
  yield self
18
18
  end
19
-
20
- def self.has_meta_data_for?(controller, action)
21
- self.meta_data.has_key?(controller) && self.meta_data[controller].has_key?(action)
22
- end
23
19
  end
24
20
 
25
21
  require 'headshop/meta_tag_helper'
26
-
27
22
  ActionView::Base.send :include, Headshop::MetaTagHelper
@@ -1,12 +1,29 @@
1
+ require 'action_view'
2
+
1
3
  module Headshop::MetaTagHelper
4
+ include ActionView::Helpers::TagHelper
5
+
2
6
  def meta_tag
3
- write_meta_data(get_meta_data_for(controller_name, action_name))
7
+ write_meta_data(get_meta_data_for(controller_path, action_name))
8
+ end
9
+
10
+ def find_meta_data_for(controller, action)
11
+ controller_path = controller.split('/')
12
+ md = Headshop.meta_data
13
+ has_controller_meta_data = true
14
+
15
+ controller_path.each do |key|
16
+ has_controller_meta_data = has_controller_meta_data & md.has_key?(key)
17
+ md = md[key] if has_controller_meta_data
18
+ end
19
+
20
+ md[action] if has_controller_meta_data && md.has_key?(action)
4
21
  end
5
22
 
6
23
  def get_meta_data_for(controller, action)
7
- if Headshop.has_meta_data_for?(controller, action)
8
- Headshop.meta_data[controller][action]
9
- elsif Headshop.meta_data.has_key?('default_meta')
24
+ if meta_data = find_meta_data_for(controller, action)
25
+ meta_data
26
+ else
10
27
  Headshop.meta_data['default_meta']
11
28
  end
12
29
  end
@@ -20,8 +37,8 @@ module Headshop::MetaTagHelper
20
37
  end
21
38
 
22
39
  def write_meta_data meta_data
23
- result = meta_data.reduce('') { |memo, obj| memo += "<meta name='#{obj[0]}' content='#{apply_base_tag(obj[0], obj[1])}' />\n" }
24
- result += "<title>#{apply_base_tag('title', meta_data['title'])}</title>\n" if meta_data.has_key?('title')
25
- result.respond_to?(:html_safe) ? result.html_safe : result
40
+ display_meta = meta_data.collect { |meta| tag(:meta, {:name => meta[0], :content => apply_base_tag(meta[0], meta[1])}, false, false) }
41
+ display_meta.push(content_tag(:title, apply_base_tag('title', meta_data['title']), nil, false)) if meta_data.has_key?('title')
42
+ display_meta.join("\n").html_safe
26
43
  end
27
44
  end
data/spec/headshop.yml CHANGED
@@ -13,7 +13,29 @@ controller:
13
13
  description: 'action_description'
14
14
  keywords: 'action_keywords'
15
15
  title: 'action_title'
16
+
17
+ namespace:
18
+ controller:
19
+ action:
20
+ description: 'namespace_description'
21
+ keywords: 'namespace_keywords'
22
+ title: 'namespace_title'
16
23
 
24
+ n:
25
+ a:
26
+ m:
27
+ e:
28
+ s:
29
+ p:
30
+ a:
31
+ c:
32
+ e:
33
+ controller:
34
+ action:
35
+ description: 'namespace_description'
36
+ keywords: 'namespace_keywords'
37
+ title: 'namespace_title'
38
+
17
39
  tester:
18
40
  default_meta:
19
41
  description: 'tester_description'
@@ -24,7 +24,7 @@ describe Headshop::MetaTagHelper do
24
24
 
25
25
  context "#meta_tag" do
26
26
  before(:each) do
27
- Class.stub!(:controller_name).and_return('controller')
27
+ Class.stub!(:controller_path).and_return('controller')
28
28
  Class.stub!(:action_name).and_return('action')
29
29
  end
30
30
 
@@ -40,18 +40,18 @@ describe Headshop::MetaTagHelper do
40
40
  end
41
41
 
42
42
  meta_data = Class.meta_tag
43
- /<title>action_title<\/title>\n/.should =~ meta_data
44
- /<meta name='title' content='action_title' \/>\n/.should =~ meta_data
45
- /<meta name='description' content='action_description' \/>\n/.should =~ meta_data
46
- /<meta name='keywords' content='action_keywords' \/>\n/.should =~ meta_data
43
+ /<title>action_title<\/title>/.should =~ meta_data
44
+ /<meta content="action_title" name="title" \/>/.should =~ meta_data
45
+ /<meta content="action_description" name="description" \/>/.should =~ meta_data
46
+ /<meta content="action_keywords" name="keywords" \/>/.should =~ meta_data
47
47
  end
48
48
 
49
49
  it "should write the meta data for controller/action" do
50
50
  meta_data = Class.meta_tag
51
- /<title>base | action_title<\/title>\n/.should =~ meta_data
52
- /<meta name='title' content='base | action_title' \/>\n/.should =~ meta_data
53
- /<meta name='description' content='base | action_description' \/>\n/.should =~ meta_data
54
- /<meta name='keywords' content='base, action_keywords' \/>\n/.should =~ meta_data
51
+ /<title>base | action_title<\/title>/.should =~ meta_data
52
+ /<meta content="base | action_title" name="title" \/>/.should =~ meta_data
53
+ /<meta content="base | action_description" name="description" \/>/.should =~ meta_data
54
+ /<meta content="base, action_keywords" name="keywords" \/>/.should =~ meta_data
55
55
  end
56
56
  end
57
57
 
@@ -68,6 +68,10 @@ describe Headshop::MetaTagHelper do
68
68
  Class.get_meta_data_for('controller', 'action').should == {"title"=>"action_title", "description"=>"action_description", "keywords"=>"action_keywords"}
69
69
  end
70
70
 
71
+ it "should return meta data for a namespaced controller and action" do
72
+ Class.get_meta_data_for('n/a/m/e/s/p/a/c/e/controller', 'action').should == {"title"=>"namespace_title", "description"=>"namespace_description", "keywords"=>"namespace_keywords"}
73
+ end
74
+
71
75
  it "should return nil when a controller and action arent found and no default set" do
72
76
  Headshop.setup do |config|
73
77
  config.config_file = File.join(File.dirname(__FILE__), '..', '..', 'headshop_no_default_no_base.yml')
@@ -80,7 +84,39 @@ describe Headshop::MetaTagHelper do
80
84
  context "#write_meta_data" do
81
85
  it "should write meta data for anything" do
82
86
  meta_data = Class.write_meta_data({:yousocrazy => :tester})
83
- /<meta name='yousocrazy' content='tester' \/>\n/.should =~ meta_data
87
+ /<meta content="tester" name="yousocrazy" \/>/.should =~ meta_data
88
+ end
89
+ end
90
+
91
+ context "#find_meta_data_for" do
92
+ before(:all) do
93
+ Headshop.setup do |config|
94
+ config.config_file = File.join(File.dirname(__FILE__), '..', '..', 'headshop.yml')
95
+ end
96
+ end
97
+
98
+ it "should return nil if no meta data" do
99
+ Class.find_meta_data_for('noway', 'noway').should be_nil
100
+ end
101
+
102
+ it "should return true if the controller/action key are found" do
103
+ Class.find_meta_data_for('controller', 'action').should == {"title"=>"action_title", "description"=>"action_description", "keywords"=>"action_keywords"}
104
+ end
105
+
106
+ it "should return true for a namespaced controller" do
107
+ Class.find_meta_data_for('namespace/controller', 'action').should == {"title"=>"namespace_title", "description"=>"namespace_description", "keywords"=>"namespace_keywords"}
108
+ end
109
+
110
+ it "should return nil for a namespaced controller that is not found" do
111
+ Class.find_meta_data_for('noway/controller', 'action').should be_nil
112
+ end
113
+
114
+ it "should be able to deeply nest a controller" do
115
+ Class.find_meta_data_for('n/a/m/e/s/p/a/c/e/controller', 'action').should == {"title"=>"namespace_title", "description"=>"namespace_description", "keywords"=>"namespace_keywords"}
116
+ end
117
+
118
+ it "should be able to deeply nest a controller and return nil" do
119
+ Class.find_meta_data_for('s/h/a/m/a/l/a/m/a/d/i/n/g/o/n/g/controller', 'action').should be_nil
84
120
  end
85
121
  end
86
122
  end
@@ -28,20 +28,4 @@ describe Headshop do
28
28
  Headshop.meta_data.should == {:test => 'test'}
29
29
  end
30
30
  end
31
-
32
- context "#has_meta_data_for?" do
33
- before(:all) do
34
- Headshop.setup do |config|
35
- config.config_file = File.join(File.dirname(__FILE__), '..', 'headshop.yml')
36
- end
37
- end
38
-
39
- it "should return false if no meta data" do
40
- Headshop.has_meta_data_for?('noway', 'noway').should be_false
41
- end
42
-
43
- it "should return true if the controller/action key are found" do
44
- Headshop.has_meta_data_for?('controller', 'action').should be_true
45
- end
46
- end
47
31
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: headshop
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 1
10
- version: 0.2.1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chuck Collins
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-10 00:00:00 -05:00
18
+ date: 2011-05-13 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -138,6 +138,7 @@ files:
138
138
  - README.markdown
139
139
  - Rakefile
140
140
  - VERSION
141
+ - headshop.gemspec
141
142
  - lib/headshop.rb
142
143
  - lib/headshop/meta_tag_helper.rb
143
144
  - spec/headshop.yml