meta-tags 1.2.5 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## 1.2.6 (March 4, 2012)
2
+
3
+ Features:
4
+
5
+ - jQuery.pjax support via `display_title` method. Check README for details
6
+
7
+ ## 1.2.5 (March 3, 2012)
8
+
9
+ Bugfixes:
10
+
11
+ - Fixed bug with overriding open graph attributes
12
+ - Fixed incorrect page title when `:site` is is blank
13
+ - Normalize `:og` attribute to `:open_graph`
14
+
1
15
  ## 1.2.4 (April 26, 2011)
2
16
 
3
17
  Features:
data/README.md CHANGED
@@ -231,6 +231,40 @@ Keywords can be passed as string of comma-separated values, or as an array:
231
231
 
232
232
  Description is a string (HTML will be stripped from output string).
233
233
 
234
+ ### Using with pjax
235
+
236
+ [jQuery.pjax](https://github.com/defunkt/jquery-pjax) is a nice solution for navigation
237
+ without full page reload. The main difference is that layout file will not be rendered,
238
+ so page title will not change. To fix this, when using a page fragment, pjax will check
239
+ the fragment DOM element for a `title` or `data-title` attribute and use any value it finds.
240
+
241
+ MetaTags simplifies this with `display_title` method, which returns fully resolved
242
+ page title (include site, prefix/suffix, etc.) But in this case you will have to
243
+ set default parameters (e.g, `:site`) both in layout file and in your views. To minimize
244
+ code duplication, you can define a helper in `application_helper.rb`:
245
+
246
+ def default_meta_tags
247
+ {
248
+ :title => 'Member Login',
249
+ :description => 'Member login page.',
250
+ :keywords => 'Site, Login, Members',
251
+ :separator => "—".html_safe,
252
+ }
253
+ end
254
+
255
+ Then in your layout file use:
256
+
257
+ <%= display_meta_tags(default_meta_tags) %>
258
+
259
+ And in your pjax templates:
260
+
261
+ <!-- set title here, so we can use it both in "display_title" and in "title" %>
262
+ <% title "My Page title" %>
263
+ <%= content_tag :div, :data => { :title => display_title(default_meta_tags) } do %>
264
+ <h1><%= title %></h1>
265
+ <!-- HTML goes here -->
266
+ <% end %>
267
+
234
268
  ## Alternatives
235
269
 
236
270
  There are several plugins influenced me to create this one:
@@ -246,3 +280,4 @@ There are several plugins influenced me to create this one:
246
280
  * Sergio Cambra (contributor)
247
281
  * Kristoffer Renholm (contributor)
248
282
  * [Jürg Lehni](https://github.com/lehni) (contributor)
283
+ * [Tom Coleman](https://github.com/tmeasday) (contributor)
@@ -1,3 +1,3 @@
1
1
  module MetaTags
2
- VERSION = '1.2.5'
2
+ VERSION = '1.2.6'
3
3
  end
@@ -34,9 +34,10 @@ module MetaTags
34
34
  # This method is best suited for use in helpers. It sets the page title
35
35
  # and returns it (or +headline+ if specified).
36
36
  #
37
- # @param [String, Array] title page title. When passed as an
37
+ # @param [nil, String, Array] title page title. When passed as an
38
38
  # +Array+, parts will be joined divided with configured
39
- # separator value (see {#display_meta_tags}).
39
+ # separator value (see {#display_meta_tags}). When nil, current
40
+ # title will be returned.
40
41
  # @param [String] headline the value to return from method. Useful
41
42
  # for using this method in views to set both page title
42
43
  # and the content of heading tag.
@@ -48,12 +49,14 @@ module MetaTags
48
49
  # title 'Login Page', 'Please login'
49
50
  # @example Set title as array of strings
50
51
  # title :title => ['part1', 'part2'] # => "part1 | part2"
52
+ # @example Get current title
53
+ # title
51
54
  #
52
55
  # @see #display_meta_tags
53
56
  #
54
- def title(title, headline = '')
55
- set_meta_tags(:title => title)
56
- headline.blank? ? title : headline
57
+ def title(title = nil, headline = '')
58
+ set_meta_tags(:title => title) unless title.nil?
59
+ headline.blank? ? meta_tags[:title] : headline
57
60
  end
58
61
 
59
62
  # Set the page keywords.
@@ -188,6 +191,30 @@ module MetaTags
188
191
  result.respond_to?(:html_safe) ? result.html_safe : result
189
192
  end
190
193
 
194
+ # Returns full page title as a string without surrounding <title> tag.
195
+ #
196
+ # The only case when you may need this helper is when you use pjax. This means
197
+ # that your layour file (with display_meta_tags helper) will not be rendered,
198
+ # so you have to pass default arguments like site title in here. You probably
199
+ # want to define helper with default options to minimize code duplication.
200
+ #
201
+ # @param [Hash] meta_tags list of meta tags.
202
+ # @option default [String] :site (nil) site title;
203
+ # @option default [String] :title ("") page title;
204
+ # @option default [String, Boolean] :prefix (" ") text between site name and separator; when +false+, no prefix will be rendered;
205
+ # @option default [String] :separator ("|") text used to separate website name from page title;
206
+ # @option default [String, Boolean] :suffix (" ") text between separator and page title; when +false+, no suffix will be rendered;
207
+ # @option default [Boolean] :lowercase (false) when true, the page name will be lowercase;
208
+ # @option default [Boolean] :reverse (false) when true, the page and site names will be reversed;
209
+ #
210
+ # @example
211
+ # <div data-page-container="true" title="<%= display_title :title => 'My Page', :site => 'PJAX Site' %>">
212
+ #
213
+ def display_title(default = {})
214
+ meta_tags = normalize_open_graph(default).deep_merge!(self.meta_tags)
215
+ build_full_title(meta_tags)
216
+ end
217
+
191
218
  if respond_to? :safe_helper
192
219
  safe_helper :display_meta_tags
193
220
  end
@@ -35,6 +35,10 @@ describe MetaTags::ViewHelper do
35
35
  it 'should respond to "display_meta_tags" helper' do
36
36
  subject.should respond_to(:display_meta_tags)
37
37
  end
38
+
39
+ it 'should respond to "display_title" helper' do
40
+ subject.should respond_to(:display_title)
41
+ end
38
42
  end
39
43
 
40
44
  context 'returning values' do
@@ -46,6 +50,11 @@ describe MetaTags::ViewHelper do
46
50
  subject.title('some-title', 'some-headline').should == 'some-headline'
47
51
  end
48
52
 
53
+ it 'should return title' do
54
+ subject.title('some-title').should == 'some-title'
55
+ subject.title.should == 'some-title'
56
+ end
57
+
49
58
  it 'should return description' do
50
59
  subject.description('some-description').should == 'some-description'
51
60
  end
@@ -337,5 +346,12 @@ describe MetaTags::ViewHelper do
337
346
  end
338
347
  end
339
348
 
349
+ context '.display_title' do
350
+ it 'should display custom title if given' do
351
+ subject.title('someTitle')
352
+ subject.display_title(:site => 'someSite', :title => 'defaultTitle').should == 'someSite | someTitle'
353
+ end
354
+ end
355
+
340
356
  it_behaves_like '.set_meta_tags'
341
357
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meta-tags
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 5
10
- version: 1.2.5
9
+ - 6
10
+ version: 1.2.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dmytro Shteflyuk
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-03 00:00:00 Z
18
+ date: 2012-03-04 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: actionpack