hierarchical_page_titles 0.1.0.pre.2 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ### What is this?
4
4
 
5
- This is a little gem that provides controller and view methods to make displaying of window/page titles DRYer.
5
+ hierarchical_page_titles is a little gem that provides controller and view methods to make displaying of window/page titles DRYer. Currently, it's only compatible with Rails 3.
6
6
 
7
7
  ### Why did you make it?
8
8
 
@@ -12,9 +12,9 @@ I made it because I found that I was doing the same thing over and over in my Ra
12
12
 
13
13
  I'm going to walk through a few use cases and hopefully you'll get the idea.
14
14
 
15
- #### Window and page title are the same
15
+ #### One
16
16
 
17
- Here's what your layout might look like:
17
+ The simplest case is if every page in your site has a title, and you want the window title to reflect the page title. hierarchical_page_titles gives you two helpers, `window_title` and `page_title`, that you can use in your layout. So let's do that:
18
18
 
19
19
  <html>
20
20
  <head><title><%= window_title %></title></head>
@@ -24,12 +24,12 @@ Here's what your layout might look like:
24
24
  </body>
25
25
  </html>
26
26
 
27
- So in your view, you'd do this:
27
+ Now in your view, you use `title` to set the title for that page:
28
28
 
29
29
  <% title "Some Page" %>
30
30
  <p>Some content</p>
31
-
32
- And now when your layout is rendered, it will be this:
31
+
32
+ And now you get this when the page is rendered:
33
33
 
34
34
  <html>
35
35
  <head><title>Some Page</title></head>
@@ -39,9 +39,9 @@ And now when your layout is rendered, it will be this:
39
39
  </body>
40
40
  </html>
41
41
 
42
- #### Window title with prefix
42
+ #### Two
43
43
 
44
- Nothing special required here, just put it in your layout:
44
+ What if you want the name of your site to show up in the window title? The easiest way is to just hard-code it in your layout:
45
45
 
46
46
  <html>
47
47
  <head><title>My Site - <%= window_title %></title></head>
@@ -51,7 +51,7 @@ Nothing special required here, just put it in your layout:
51
51
  </body>
52
52
  </html>
53
53
 
54
- And when the page is rendered:
54
+ And this is what you get when a page is rendered:
55
55
 
56
56
  <html>
57
57
  <head><title>My Site - Some Page</title></head>
@@ -61,45 +61,39 @@ And when the page is rendered:
61
61
  </body>
62
62
  </html>
63
63
 
64
- #### Hiding page title for certain pages
65
-
66
- #### A page hierarchy
67
-
68
- Controllers:
69
-
70
- <pre>
71
- <code>
72
- class ApplicationController < ActionController::Base
73
- window_title "My Site Name"
74
- end
75
- class SupportController < ApplicationController
76
- window_title "Support"
77
- def billing; end
78
- end
79
- </code>
80
- </pre>
81
-
82
- Views:
83
-
84
- <pre>
85
- <code>
86
- #==== app/views/layouts/application.html.erb ====
87
- <html>
88
- <head><title><%= window_title %></title></head>
89
- <body>
90
- <h2><%= page_title %></h2>
91
- </body>
92
- </html>
93
- #==== app/views/support/billing.html.erb ====
94
- # this adds to the window title and the page title at the same time
95
- <% title "Billing FAQs" %>
96
- </code>
97
- </pre>
98
-
99
- When the billing view is rendered:
100
-
101
- * The window title will be "My Site Name - Support - Billing FAQs"
102
- * The page title (in the &lt;h2&gt; tag) will be "Billing FAQs"
64
+ #### Three
65
+
66
+ What if there are some pages on your site in which you don't want to show a page title? Well, another helper hierarchical_page_titles gives you is `page_title?`, which will return true if the page title has been set. So let's say your layout looks like this:
67
+
68
+ <html>
69
+ <head><title><%= window_title %></title></head>
70
+ <body>
71
+ <% if page_title? %>
72
+ <h1><%= page_title %></h1>
73
+ <% end %>
74
+ <%= yield %>
75
+ </body>
76
+ </html>
77
+
78
+ And you have a view in which you set the window title, but not the page title:
79
+
80
+ <% window_title "Some Page" %>
81
+ <p>Some content</p>
82
+
83
+ In this case your page will get rendered as follows:
84
+
85
+ <html>
86
+ <head><title>Some Page</title></head>
87
+ <body>
88
+ <p>Some content</p>
89
+ </body>
90
+ </html>
91
+
92
+ #### Four
93
+
94
+ Let's combine the last two examples. That it, what happens if you want the
95
+
96
+ ....
103
97
 
104
98
  ### How is it different from XYZ?
105
99
 
@@ -116,11 +110,18 @@ There are several related gems/plugins:
116
110
 
117
111
  ### How do I install it?
118
112
 
113
+ Just the usual way:
114
+
119
115
  gem install hierarchical_page_titles
120
116
 
117
+ ### I found a bug! or, I have a feature request...
118
+
119
+ Okay! Please file any issues in [Issues](http://github.com/mcmire/hierarchical_page_titles/issues).
120
+
121
121
  ### How do I contribute?
122
122
 
123
- ### Who wrote this?
123
+ Pull down the code, make a branch, and send me a pull request.
124
+
125
+ ### Author/Copyright/License
124
126
 
125
- (c) 2009 Elliot Winkler (elliot dot winkler at gmail dot com).
126
- Released under the MIT license.
127
+ (c) 2009-2011 Elliot Winkler (email: <elliot.winkler@gmail.com>, twitter: [@mcmire](http://twitter.com/mcmire)). You are free to do whatever you want with this code, as long as I'm not held responsible, blah blah.
@@ -13,9 +13,9 @@ Gem::Specification.new do |s|
13
13
  s.description = %q{A gem that provides controller and view methods to make displaying of window/page titles DRYer.}
14
14
 
15
15
  #s.rubyforge_project = "title_helpers"
16
-
17
- s.files = `git ls-files`.split("\n")
18
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+
17
+ s.files = ["README.md", "hierarchical_page_titles.gemspec"] + Dir["lib/**/*"]
18
+ s.test_files = Dir["{test,spec,features}/**/*"]
19
+ s.executables = Dir["bin/**/*"].map {|f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
  end
@@ -12,7 +12,6 @@ module HierarchicalPageTitles
12
12
  else
13
13
  @_window_titles += titles
14
14
  end
15
- @_window_title_set = true
16
15
  end
17
16
 
18
17
  # Call this in your view with a string to set the page title to that string.
@@ -21,7 +20,6 @@ module HierarchicalPageTitles
21
20
  options = args.extract_options!
22
21
  title = args.first
23
22
  @_page_title = (block_given? ? instance_eval(&block) : title)
24
- @_page_title_set = true
25
23
  end
26
24
 
27
25
  # Call this in your view to set the window title and the page title at the same time.
@@ -30,7 +28,6 @@ module HierarchicalPageTitles
30
28
  options = args.extract_options!
31
29
  window_title(*args, &block)
32
30
  page_title(args.last, &block)
33
- @_title_set = true
34
31
  end
35
32
 
36
33
  def titles
@@ -1,3 +1,3 @@
1
1
  module HierarchicalPageTitles
2
- VERSION = "0.1.0.pre.2"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -14,6 +14,7 @@ module HierarchicalPageTitles
14
14
  @_window_titles ||= []
15
15
  @_window_titles.join(options[:separator])
16
16
  else
17
+ @_window_title_set = true
17
18
  super
18
19
  end
19
20
  end
@@ -25,10 +26,16 @@ module HierarchicalPageTitles
25
26
  if args.empty?
26
27
  @_page_title
27
28
  else
29
+ @_page_title_set = true
28
30
  super
29
31
  end
30
32
  end
31
33
 
34
+ def title(*args)
35
+ @_title_set = true
36
+ super
37
+ end
38
+
32
39
  # TODO: Document
33
40
  def page_title?
34
41
  @_page_title.present?
@@ -41,7 +48,7 @@ module HierarchicalPageTitles
41
48
 
42
49
  # TODO: Document
43
50
  def page_title_set?
44
- @_window_title_set
51
+ @_page_title_set
45
52
  end
46
53
 
47
54
  # TODO: Document
metadata CHANGED
@@ -1,15 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hierarchical_page_titles
3
3
  version: !ruby/object:Gem::Version
4
- hash: -223651651
5
- prerelease: true
4
+ hash: 25
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- - pre
11
- - 2
12
- version: 0.1.0.pre.2
9
+ - 1
10
+ version: 0.1.1
13
11
  platform: ruby
14
12
  authors:
15
13
  - Elliot Winkler
@@ -17,7 +15,7 @@ autorequire:
17
15
  bindir: bin
18
16
  cert_chain: []
19
17
 
20
- date: 2010-12-13 00:00:00 -07:00
18
+ date: 2011-01-06 00:00:00 -07:00
21
19
  default_executable:
22
20
  dependencies: []
23
21
 
@@ -31,19 +29,14 @@ extensions: []
31
29
  extra_rdoc_files: []
32
30
 
33
31
  files:
34
- - .gitignore
35
- - .rvmrc
36
- - Gemfile
37
32
  - README.md
38
- - README.textile
39
- - Rakefile
40
33
  - hierarchical_page_titles.gemspec
41
- - lib/hierarchical_page_titles.rb
42
34
  - lib/hierarchical_page_titles/controller_helpers.rb
43
35
  - lib/hierarchical_page_titles/railtie.rb
44
36
  - lib/hierarchical_page_titles/shared_instance_methods.rb
45
37
  - lib/hierarchical_page_titles/version.rb
46
38
  - lib/hierarchical_page_titles/view_helpers.rb
39
+ - lib/hierarchical_page_titles.rb
47
40
  has_rdoc: true
48
41
  homepage: http://github.com/mcmire/hierarchical_page_titles
49
42
  licenses: []
@@ -65,14 +58,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
58
  required_rubygems_version: !ruby/object:Gem::Requirement
66
59
  none: false
67
60
  requirements:
68
- - - ">"
61
+ - - ">="
69
62
  - !ruby/object:Gem::Version
70
- hash: 25
63
+ hash: 3
71
64
  segments:
72
- - 1
73
- - 3
74
- - 1
75
- version: 1.3.1
65
+ - 0
66
+ version: "0"
76
67
  requirements: []
77
68
 
78
69
  rubyforge_project:
data/.gitignore DELETED
@@ -1,3 +0,0 @@
1
- .DS_Store
2
- *.tmproj
3
- *.gem
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm 1.8.7@hierarchical_page_titles
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gemspec
data/README.textile DELETED
@@ -1,69 +0,0 @@
1
- h2. title_helpers
2
-
3
- h3. Summary
4
-
5
- Rails plugin that provides controller and view methods to make displaying of
6
- window/page titles DRYer.
7
-
8
- h3. Rationale
9
-
10
- Most web sites you'll build have some sort of hierarchy. And most times this
11
- hierarchy will correspond to your controllers. For instance, let's say you have a
12
- support section on your website (@SupportController@), and under that you have FAQs
13
- about billing (the @billing@ action). Now, I think it's important for the window
14
- title to be informative -- in fact, it should come directly from the page hierarchy.
15
- So, going back to our billing FAQs page, you might want the window title to be
16
- "Foo.com - Support - Billing FAQs". But that's going to be a pattern, isn't it?
17
- "Foo.com - #{some controller} - #{some action}". You're not really going to define
18
- the full window title for every action in your code, are you? I'm certainly not going
19
- to. Wouldn't it be better if you could set the window title on a controller basis,
20
- and then, in your view, set the window title for just the action?
21
-
22
- h3. Example
23
-
24
- Controllers:
25
-
26
- <pre>
27
- <code>
28
- class ApplicationController < ActionController::Base
29
- window_title "My Site Name"
30
- end
31
- class SupportController < ApplicationController
32
- window_title "Support"
33
- def billing; end
34
- end
35
- </code>
36
- </pre>
37
-
38
- Views:
39
-
40
- <pre>
41
- <code>
42
- #==== app/views/layouts/application.html.erb ====
43
- <html>
44
- <head><title><%= window_title %></title></head>
45
- <body>
46
- <h2><%= page_title %></h2>
47
- </body>
48
- </html>
49
- #==== app/views/support/billing.html.erb ====
50
- # this adds to the window title and the page title at the same time
51
- <% title "Billing FAQs" %>
52
- </code>
53
- </pre>
54
-
55
- When the billing view is rendered:
56
-
57
- * The window title will be "My Site Name - Support - Billing FAQs"
58
- * The page title (in the &lt;h2&gt; tag) will be "Billing FAQs"
59
-
60
- h3. Installation
61
-
62
- <pre>
63
- script/plugin install git://github.com/mcmire/title_helpers.git
64
- </pre>
65
-
66
- h3. Author
67
-
68
- (c) 2009 Elliot Winkler (elliot dot winkler at gmail dot com).
69
- Released under the MIT license.
data/Rakefile DELETED
@@ -1,2 +0,0 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks