dyn_meta 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -1
- data/README.rdoc +34 -38
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/dyn_meta.gemspec +5 -4
- data/lib/dyn_meta/action_controller.rb +10 -21
- data/spec/dyn_meta_spec.rb +9 -10
- data/spec/en.yml +6 -5
- metadata +38 -37
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
= DynMeta
|
2
2
|
|
3
|
-
Automate the lookup of page meta information based on the current request. Meta information such as page titles and descriptions can be stored in a translations file rather than floating around in controllers or views.
|
3
|
+
Automate the lookup of page meta information based on the current request context. Meta information such as page titles and descriptions can be stored in a translations file rather than floating around in controllers or views.
|
4
|
+
|
5
|
+
== Please Note
|
6
|
+
|
7
|
+
The usage of dyn_meta has changed from *page_* methods to a simple *meta* method.
|
4
8
|
|
5
9
|
== Installation
|
6
10
|
|
@@ -17,61 +21,53 @@ Install the gem
|
|
17
21
|
Set up your translations as follows:
|
18
22
|
|
19
23
|
en:
|
20
|
-
|
21
|
-
<
|
22
|
-
<
|
23
|
-
<
|
24
|
+
meta:
|
25
|
+
<meta key pluralized>:
|
26
|
+
<controller>:
|
27
|
+
<action>:
|
28
|
+
<id>: "Some meta value"
|
24
29
|
|
25
30
|
For example:
|
26
31
|
|
27
32
|
en:
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
33
|
+
meta:
|
34
|
+
titles:
|
35
|
+
users:
|
36
|
+
new: "Create Your Account"
|
37
|
+
edit: "Update Your Account"
|
32
38
|
|
33
39
|
You usually won't go down to the _id_ level but occasionally it's useful:
|
34
40
|
|
35
41
|
en:
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
+
meta:
|
43
|
+
titles:
|
44
|
+
pages:
|
45
|
+
show:
|
46
|
+
tos: "Terms of Service"
|
47
|
+
pp: "Privacy Policy"
|
48
|
+
about: "About My Site"
|
42
49
|
|
43
50
|
You can define catch-alls via the _default_ key:
|
44
51
|
|
45
52
|
en:
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
53
|
+
meta:
|
54
|
+
titles:
|
55
|
+
default: "My Super Site"
|
56
|
+
users:
|
57
|
+
default: "Manage Your Account"
|
58
|
+
new: "Create Your Account"
|
59
|
+
edit: "Update Your Account"
|
52
60
|
|
53
61
|
|
54
|
-
DynMeta provides one method *
|
55
|
-
|
56
|
-
<title><%= page_detail(:page_title) %></title>
|
57
|
-
<meta name="description" content="<%= page_detail(:page_description) %>" />
|
58
|
-
|
59
|
-
Alternatively, DynMeta matches any method starting with *page_* so you could just do:
|
60
|
-
|
61
|
-
<title><%= page_title %></title>
|
62
|
-
<meta name="description" content="<%= page_description %>" />
|
63
|
-
|
64
|
-
Be sure to add the *page_* methods as helpers in your application controller:
|
65
|
-
|
66
|
-
class ApplicationController < ActionController::Base
|
62
|
+
DynMeta provides one method *meta*. It's both a setter and a getter. Just use the *meta* method in your template:
|
67
63
|
|
68
|
-
|
69
|
-
|
64
|
+
<title><%= meta(:title) %></title>
|
65
|
+
<meta name="description" content="<%= meta(:description) %>" />
|
70
66
|
|
71
|
-
If you'd like to override meta content you can just pass a value to the
|
67
|
+
If you'd like to override meta content you can just pass a value to the *meta* method:
|
72
68
|
|
73
69
|
def show
|
74
70
|
@user = User.find(params[:id])
|
75
|
-
|
71
|
+
meta(:title, "#{@user.display_name} :: Profile")
|
76
72
|
end
|
77
73
|
|
data/Rakefile
CHANGED
@@ -15,8 +15,8 @@ Jeweler::Tasks.new do |gem|
|
|
15
15
|
gem.name = "dyn_meta"
|
16
16
|
gem.homepage = "http://github.com/mnelson/dyn_meta"
|
17
17
|
gem.license = "MIT"
|
18
|
-
gem.summary = %Q{Automate the lookup of page meta information based on the current request}
|
19
|
-
gem.description = %Q{Automate the lookup of page meta information based on the current request. Meta information such as page titles and descriptions can be stored in a translations file rather than floating around in controllers or views.}
|
18
|
+
gem.summary = %Q{Automate the lookup of page meta information based on the current request context}
|
19
|
+
gem.description = %Q{Automate the lookup of page meta information based on the current request context. Meta information such as page titles and descriptions can be stored in a translations file rather than floating around in controllers or views.}
|
20
20
|
gem.email = "mike@mikeonrails.com"
|
21
21
|
gem.authors = ["Mike Nelson"]
|
22
22
|
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/dyn_meta.gemspec
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dyn_meta}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Mike Nelson"]
|
12
|
-
s.date = %q{
|
13
|
-
s.description = %q{Automate the lookup of page meta information based on the current request. Meta information such as page titles and descriptions can be stored in a translations file rather than floating around in controllers or views.}
|
12
|
+
s.date = %q{2011-10-05}
|
13
|
+
s.description = %q{Automate the lookup of page meta information based on the current request context. Meta information such as page titles and descriptions can be stored in a translations file rather than floating around in controllers or views.}
|
14
14
|
s.email = %q{mike@mikeonrails.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
"README.rdoc",
|
26
26
|
"Rakefile",
|
27
27
|
"VERSION",
|
28
|
+
"dyn_meta-0.0.3.gem",
|
28
29
|
"dyn_meta.gemspec",
|
29
30
|
"features/dyn_meta.feature",
|
30
31
|
"features/step_definitions/dyn_meta_steps.rb",
|
@@ -39,7 +40,7 @@ Gem::Specification.new do |s|
|
|
39
40
|
s.licenses = ["MIT"]
|
40
41
|
s.require_paths = ["lib"]
|
41
42
|
s.rubygems_version = %q{1.3.7}
|
42
|
-
s.summary = %q{Automate the lookup of page meta information based on the current request}
|
43
|
+
s.summary = %q{Automate the lookup of page meta information based on the current request context}
|
43
44
|
s.test_files = [
|
44
45
|
"spec/dyn_meta_spec.rb",
|
45
46
|
"spec/spec_helper.rb"
|
@@ -3,41 +3,30 @@ module DynMeta
|
|
3
3
|
|
4
4
|
def self.included(base)
|
5
5
|
base.class_eval do
|
6
|
-
helper_method :
|
6
|
+
helper_method :meta
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
12
|
-
|
13
|
-
else
|
14
|
-
super
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def respond_to?(method_name, include_private = false)
|
19
|
-
method_name.to_s =~ /^page_/ || super
|
20
|
-
end
|
21
|
-
|
22
|
-
def page_detail(name, val = nil)
|
23
|
-
in_name = "@#{name}"
|
10
|
+
def meta(name, val = nil)
|
11
|
+
|
12
|
+
in_name = "@meta_#{name}"
|
24
13
|
return instance_variable_set(in_name, val) if val.present?
|
25
14
|
return instance_variable_get(in_name) if instance_variable_get(in_name)
|
26
|
-
|
27
|
-
|
15
|
+
|
16
|
+
trans = I18n.translate("meta.#{name.to_s.pluralize}") || {}
|
28
17
|
hash = trans
|
29
|
-
|
18
|
+
[:controller, :action, :id].each do |p|
|
30
19
|
val = params[p] && hash[params[p].to_s.to_sym] || nil
|
31
20
|
if val.nil?
|
32
|
-
return hash[:default] || trans[:default] || nil
|
21
|
+
return instance_variable_set(in_name, hash[:default] || trans[:default] || nil)
|
33
22
|
elsif val.is_a?(Hash)
|
34
23
|
hash = val
|
35
24
|
else
|
36
|
-
return val
|
25
|
+
return instance_variable_set(in_name, val)
|
37
26
|
end
|
38
27
|
end
|
39
28
|
end
|
40
|
-
|
29
|
+
|
41
30
|
end
|
42
31
|
end
|
43
32
|
|
data/spec/dyn_meta_spec.rb
CHANGED
@@ -9,31 +9,30 @@ describe "DynMeta" do
|
|
9
9
|
|
10
10
|
it "should have dyn_meta methods included" do
|
11
11
|
a = controller
|
12
|
-
a.respond_to?(:
|
13
|
-
a.respond_to?(:page_title).should be_true
|
12
|
+
a.respond_to?(:meta).should be_true
|
14
13
|
end
|
15
14
|
|
16
15
|
it "should define instance variables when they don't exist" do
|
17
16
|
a = controller
|
18
|
-
a.
|
19
|
-
a.
|
17
|
+
a.instance_variable_get('@meta_title').should be_nil
|
18
|
+
a.meta(:title, 'value')
|
19
|
+
a.instance_variable_get('@meta_title').should eql('value')
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should return nil when trans hash doesn't exist" do
|
23
23
|
a = controller
|
24
|
-
a.
|
24
|
+
a.meta(:description).should be_nil
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should look at controller action and id for translations" do
|
28
28
|
a = controller(:controller => 'users', :action => 'edit')
|
29
|
-
a.
|
29
|
+
a.meta(:title).should eql("Update your account")
|
30
|
+
a.meta(:title).should eql("Update your account")
|
30
31
|
end
|
31
32
|
|
32
33
|
it "should fall back to default values" do
|
33
|
-
|
34
|
-
|
35
|
-
a.params = {:controller => 'organizations'}
|
36
|
-
a.page_title.should eql("My Great Startup Idea")
|
34
|
+
controller.meta(:title).should eql("Users, this is for you")
|
35
|
+
controller({:controller => 'organizations'}).meta(:title).should eql("My Great Startup Idea")
|
37
36
|
end
|
38
37
|
|
39
38
|
|
data/spec/en.yml
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
en:
|
2
2
|
foo: bar
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
meta:
|
4
|
+
titles:
|
5
|
+
default: "My Great Startup Idea"
|
6
|
+
users:
|
7
|
+
default: "Users, this is for you"
|
8
|
+
edit: "Update your account"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dyn_meta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mike Nelson
|
@@ -15,14 +15,11 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-10-05 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
23
|
-
type: :runtime
|
24
|
-
name: rails
|
25
|
-
version_requirements: &id001 !ruby/object:Gem::Requirement
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
23
|
none: false
|
27
24
|
requirements:
|
28
25
|
- - ">="
|
@@ -31,12 +28,12 @@ dependencies:
|
|
31
28
|
segments:
|
32
29
|
- 0
|
33
30
|
version: "0"
|
34
|
-
|
35
|
-
- !ruby/object:Gem::Dependency
|
31
|
+
name: rails
|
36
32
|
prerelease: false
|
37
|
-
type: :
|
38
|
-
|
39
|
-
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
37
|
none: false
|
41
38
|
requirements:
|
42
39
|
- - ~>
|
@@ -47,12 +44,12 @@ dependencies:
|
|
47
44
|
- 1
|
48
45
|
- 0
|
49
46
|
version: 2.1.0
|
50
|
-
|
51
|
-
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
52
48
|
prerelease: false
|
53
49
|
type: :development
|
54
|
-
|
55
|
-
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
53
|
none: false
|
57
54
|
requirements:
|
58
55
|
- - ">="
|
@@ -61,12 +58,12 @@ dependencies:
|
|
61
58
|
segments:
|
62
59
|
- 0
|
63
60
|
version: "0"
|
64
|
-
|
65
|
-
- !ruby/object:Gem::Dependency
|
61
|
+
name: cucumber
|
66
62
|
prerelease: false
|
67
63
|
type: :development
|
68
|
-
|
69
|
-
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
67
|
none: false
|
71
68
|
requirements:
|
72
69
|
- - ~>
|
@@ -77,12 +74,12 @@ dependencies:
|
|
77
74
|
- 0
|
78
75
|
- 0
|
79
76
|
version: 1.0.0
|
80
|
-
|
81
|
-
- !ruby/object:Gem::Dependency
|
77
|
+
name: bundler
|
82
78
|
prerelease: false
|
83
79
|
type: :development
|
84
|
-
|
85
|
-
|
80
|
+
version_requirements: *id004
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
86
83
|
none: false
|
87
84
|
requirements:
|
88
85
|
- - ~>
|
@@ -93,12 +90,12 @@ dependencies:
|
|
93
90
|
- 5
|
94
91
|
- 1
|
95
92
|
version: 1.5.1
|
96
|
-
|
97
|
-
- !ruby/object:Gem::Dependency
|
93
|
+
name: jeweler
|
98
94
|
prerelease: false
|
99
|
-
type: :
|
100
|
-
|
101
|
-
|
95
|
+
type: :development
|
96
|
+
version_requirements: *id005
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
102
99
|
none: false
|
103
100
|
requirements:
|
104
101
|
- - ">="
|
@@ -108,12 +105,12 @@ dependencies:
|
|
108
105
|
- 2
|
109
106
|
- 0
|
110
107
|
version: "2.0"
|
111
|
-
|
112
|
-
- !ruby/object:Gem::Dependency
|
108
|
+
name: rails
|
113
109
|
prerelease: false
|
114
110
|
type: :runtime
|
115
|
-
|
116
|
-
|
111
|
+
version_requirements: *id006
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
117
114
|
none: false
|
118
115
|
requirements:
|
119
116
|
- - ">"
|
@@ -123,8 +120,11 @@ dependencies:
|
|
123
120
|
- 0
|
124
121
|
- 0
|
125
122
|
version: "0.0"
|
126
|
-
|
127
|
-
|
123
|
+
name: i18n
|
124
|
+
prerelease: false
|
125
|
+
type: :runtime
|
126
|
+
version_requirements: *id007
|
127
|
+
description: Automate the lookup of page meta information based on the current request context. Meta information such as page titles and descriptions can be stored in a translations file rather than floating around in controllers or views.
|
128
128
|
email: mike@mikeonrails.com
|
129
129
|
executables: []
|
130
130
|
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- README.rdoc
|
143
143
|
- Rakefile
|
144
144
|
- VERSION
|
145
|
+
- dyn_meta-0.0.3.gem
|
145
146
|
- dyn_meta.gemspec
|
146
147
|
- features/dyn_meta.feature
|
147
148
|
- features/step_definitions/dyn_meta_steps.rb
|
@@ -184,7 +185,7 @@ rubyforge_project:
|
|
184
185
|
rubygems_version: 1.3.7
|
185
186
|
signing_key:
|
186
187
|
specification_version: 3
|
187
|
-
summary: Automate the lookup of page meta information based on the current request
|
188
|
+
summary: Automate the lookup of page meta information based on the current request context
|
188
189
|
test_files:
|
189
190
|
- spec/dyn_meta_spec.rb
|
190
191
|
- spec/spec_helper.rb
|