smart_titles 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,52 +1,66 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smart_titles (0.1.2.pre)
4
+ smart_titles (0.2.0)
5
5
  actionpack
6
6
  activesupport
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
- abstract (1.0.0)
12
- actionpack (3.0.5)
13
- activemodel (= 3.0.5)
14
- activesupport (= 3.0.5)
15
- builder (~> 2.1.2)
16
- erubis (~> 2.6.6)
17
- i18n (~> 0.4)
18
- rack (~> 1.2.1)
19
- rack-mount (~> 0.6.13)
20
- rack-test (~> 0.5.7)
21
- tzinfo (~> 0.3.23)
22
- activemodel (3.0.5)
23
- activesupport (= 3.0.5)
24
- builder (~> 2.1.2)
25
- i18n (~> 0.4)
26
- activesupport (3.0.5)
27
- builder (2.1.2)
28
- diff-lcs (1.1.2)
29
- erubis (2.6.6)
30
- abstract (>= 1.0.0)
31
- i18n (0.5.0)
32
- rack (1.2.1)
33
- rack-mount (0.6.13)
11
+ actionpack (3.1.0)
12
+ activemodel (= 3.1.0)
13
+ activesupport (= 3.1.0)
14
+ builder (~> 3.0.0)
15
+ erubis (~> 2.7.0)
16
+ i18n (~> 0.6)
17
+ rack (~> 1.3.2)
18
+ rack-cache (~> 1.0.3)
19
+ rack-mount (~> 0.8.2)
20
+ rack-test (~> 0.6.1)
21
+ sprockets (~> 2.0.0)
22
+ activemodel (3.1.0)
23
+ activesupport (= 3.1.0)
24
+ bcrypt-ruby (~> 3.0.0)
25
+ builder (~> 3.0.0)
26
+ i18n (~> 0.6)
27
+ activesupport (3.1.0)
28
+ multi_json (~> 1.0)
29
+ bcrypt-ruby (3.0.0)
30
+ builder (3.0.0)
31
+ diff-lcs (1.1.3)
32
+ erubis (2.7.0)
33
+ hike (1.2.1)
34
+ i18n (0.6.0)
35
+ mocha (0.9.12)
36
+ multi_json (1.0.3)
37
+ rack (1.3.2)
38
+ rack-cache (1.0.3)
39
+ rack (>= 0.4)
40
+ rack-mount (0.8.3)
34
41
  rack (>= 1.0.0)
35
- rack-test (0.5.7)
42
+ rack-test (0.6.1)
36
43
  rack (>= 1.0)
37
- rspec (2.2.0)
38
- rspec-core (~> 2.2)
39
- rspec-expectations (~> 2.2)
40
- rspec-mocks (~> 2.2)
41
- rspec-core (2.2.1)
42
- rspec-expectations (2.2.0)
44
+ rake (0.9.2)
45
+ rspec (2.6.0)
46
+ rspec-core (~> 2.6.0)
47
+ rspec-expectations (~> 2.6.0)
48
+ rspec-mocks (~> 2.6.0)
49
+ rspec-core (2.6.4)
50
+ rspec-expectations (2.6.0)
43
51
  diff-lcs (~> 1.1.2)
44
- rspec-mocks (2.2.0)
45
- tzinfo (0.3.24)
52
+ rspec-mocks (2.6.0)
53
+ sprockets (2.0.0)
54
+ hike (~> 1.2)
55
+ rack (~> 1.0)
56
+ tilt (!= 1.3.0, ~> 1.1)
57
+ tilt (1.3.3)
46
58
 
47
59
  PLATFORMS
48
60
  ruby
49
61
 
50
62
  DEPENDENCIES
63
+ mocha
64
+ rake
51
65
  rspec
52
66
  smart_titles!
data/README.md CHANGED
@@ -26,12 +26,9 @@ Integration
26
26
  ---
27
27
  You have to insert the following code inside the `<title>` tag in your layout:
28
28
 
29
- <title><%= page_title || "Default title" %></title>
29
+ <title><%= head_title "Default title" %></title>
30
30
 
31
- The default title is displayed only if you haven't specified the title in your view.
32
- You can also omit `||` operator like this:
33
-
34
- <title><%= page_title "Default title" %></title>
31
+ The default title is displayed only if you haven't specified title in your view.
35
32
 
36
33
  With Internationalization
37
34
  ---
@@ -45,9 +42,40 @@ If you are using I18n in your Rails application static titles are specified in t
45
42
  new:
46
43
  title: Create a page
47
44
 
45
+ And then you should just call `title` without any arguments.
46
+
47
+ <%= title %>
48
+
49
+ Note that you don't have to call it if you don't output it.
50
+
51
+ <% title %>
52
+
48
53
  Dynamic titles are set as usual:
49
54
 
50
- <%= title @page.title %>
55
+ <%= title @page.title %>
56
+
57
+ "Default title" will be only used by `head_title` if you call it with no arguments and there will be no title set by the current page.
58
+
59
+ <title><%= head_title %></title>
60
+
61
+ Title Template
62
+ ---
63
+ If you want to add your website name to all of your titles just add :title_template translation
64
+
65
+ en:
66
+ title: The Coolest Store
67
+ title_template: %{title} from the Coolest Store
68
+ products:
69
+ index:
70
+ title: Products
71
+
72
+ And now products#index page will have "Products from the Coolest Store" browser's title. However, `<%= title %>` will still output `<h1>Products</h1>`.
73
+
74
+ Changelog
75
+ ---
76
+ ### 0.2.0
77
+ * `page_title` renamed to `head_title`.
78
+ * Added support for :title_template translation
51
79
 
52
80
  Contributing
53
81
  ---
data/TODO CHANGED
@@ -1 +0,0 @@
1
- * Test all functionality (especially with i18n)
@@ -1,20 +1,33 @@
1
1
  module SmartTitles
2
2
  module Helper
3
3
  MISSING_TRANSLATION = 0
4
-
5
- def page_title(default = nil)
6
- title if @page_title.nil?
7
- @page_title != MISSING_TRANSLATION ? @page_title : default
8
- end
9
4
 
10
- def title(str = nil)
11
- if str.nil?
12
- str = t('.title')
13
- @page_title = t('.title', :default => [:title, MISSING_TRANSLATION])
5
+ def head_title(custom_default_title = nil)
6
+ if title = page_title
7
+ t(:title_template, title: title, default: title)
14
8
  else
15
- @page_title = str
9
+ page_title || custom_default_title || default_title
16
10
  end
17
- content_tag(:h1, str)
11
+ end
12
+
13
+ attr_writer :page_title
14
+
15
+ def page_title
16
+ @page_title || default_page_title
17
+ end
18
+
19
+ def title(new_title = nil)
20
+ self.page_title = new_title if new_title
21
+ content_tag(:h1, page_title) if page_title
22
+ end
23
+
24
+ def default_page_title
25
+ translation = t('.title', default: MISSING_TRANSLATION)
26
+ translation unless translation == MISSING_TRANSLATION
27
+ end
28
+
29
+ def default_title
30
+ t(:title)
18
31
  end
19
32
  end
20
33
  end
@@ -1,3 +1,3 @@
1
1
  module SmartTitles
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
data/smart_titles.gemspec CHANGED
@@ -15,6 +15,8 @@ Gem::Specification.new do |s|
15
15
  s.add_dependency 'activesupport'
16
16
  s.add_dependency 'actionpack'
17
17
  s.add_development_dependency 'rspec'
18
+ s.add_development_dependency 'rake'
19
+ s.add_development_dependency 'mocha'
18
20
 
19
21
  s.files = `git ls-files`.split("\n")
20
22
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -4,19 +4,124 @@ describe SmartTitles::Helper do
4
4
  include ActionView::Helpers
5
5
 
6
6
  before do
7
- @sample = 'Hello World!'
7
+ @virtual_path = 'posts/new'
8
+ I18n.backend.reload!
8
9
  end
9
10
 
10
- describe '#page_title' do
11
- it 'returns the title set by #title' do
12
- title(@sample)
13
- page_title.should == @sample
11
+ def store_translations(*args)
12
+ I18n.backend.store_translations(:en, *args)
13
+ end
14
+
15
+ describe 'no i18n' do
16
+ describe '#title' do
17
+ it "sets #page_title" do
18
+ title("Hi")
19
+ page_title.should == "Hi"
20
+ end
21
+
22
+ it "returns h1-wrapped title" do
23
+ title("Hi").should == "<h1>Hi</h1>"
24
+ end
25
+ end
26
+
27
+ describe '#page_title' do
28
+ it "returns nil if no title was set" do
29
+ page_title.should == nil
30
+ end
31
+ end
32
+
33
+ describe '#head_title' do
34
+ it 'returns #page_title if it was set' do
35
+ title("Hi")
36
+ head_title.should == "Hi"
37
+ end
38
+
39
+ it "returns missing translation if no title was set" do
40
+ head_title.should include("translation missing: en.title")
41
+ end
42
+
43
+ it "returns title passed if no title was set" do
44
+ head_title("Default").should == "Default"
45
+ end
46
+
47
+ describe 'with :title_template' do
48
+ it "used for page_title" do
49
+ store_translations title_template: "d %{title} b"
50
+ title("New post")
51
+ head_title.should == "d New post b"
52
+ end
53
+
54
+ it "is skipped for custom title" do
55
+ store_translations title_template: "d %{title} b"
56
+ head_title("Default").should == "Default"
57
+ end
58
+ end
14
59
  end
15
60
  end
16
61
 
17
- describe '#title' do
18
- it 'returns the title in h1 tag' do
19
- title(@sample).should == "<h1>#{@sample}</h1>"
62
+ describe 'i18n' do
63
+ describe '#title' do
64
+ it "returns .title wrapped in h1 tag if there are :title and .title" do
65
+ store_translations title: "My Website", posts: { new: { title: "New post" } }
66
+ title.should == "<h1>New post</h1>"
67
+ end
68
+
69
+ it "returns .title wrapped in h1 tag if there is only .title" do
70
+ store_translations posts: { new: { title: "New post" } }
71
+ title.should == "<h1>New post</h1>"
72
+ end
73
+
74
+ it "returns nothing if there is no .title" do
75
+ store_translations title: "My Website"
76
+ title.should == nil
77
+ end
78
+
79
+ it "returns nothing if there are no translations" do
80
+ title.should == nil
81
+ end
82
+ end
83
+
84
+ describe '#head_title' do
85
+ it "returns .title if there are :title and .title" do
86
+ store_translations title: "My Website", posts: { new: { title: "New post" } }
87
+ head_title.should == "New post"
88
+ end
89
+
90
+ it "returns .title if there is only .title" do
91
+ store_translations posts: { new: { title: "New post" } }
92
+ head_title.should == "New post"
93
+ end
94
+
95
+ it "returns :title if there is no .title" do
96
+ store_translations title: "My Website"
97
+ head_title.should == "My Website"
98
+ end
99
+
100
+ it "returns missing translation if there are no tranlations" do
101
+ head_title.should include("translation missing: en.title")
102
+ end
103
+
104
+ it "returns custom title" do
105
+ store_translations title: "My Website"
106
+ head_title("Custom").should == "Custom"
107
+ end
108
+
109
+ it "returns .title even if custom default title is passed" do
110
+ store_translations posts: { new: { title: "New post" } }
111
+ head_title("Custom").should == "New post"
112
+ end
113
+
114
+ describe 'with :title_template' do
115
+ it "used for page_title" do
116
+ store_translations title_template: "d %{title} b", posts: { new: { title: "New post" } }
117
+ head_title.should == "d New post b"
118
+ end
119
+
120
+ it "is skipped for default title" do
121
+ store_translations title: "My Website", title_template: "d %{title} b"
122
+ head_title.should == "My Website"
123
+ end
124
+ end
20
125
  end
21
126
  end
22
127
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
- require 'rspec'
4
- require 'rails/all'
3
+ require 'active_support/all'
4
+ require 'action_view'
5
5
  require 'smart_titles'
6
6
 
7
7
  # Requires supporting files with custom matchers and macros, etc,
@@ -9,5 +9,5 @@ require 'smart_titles'
9
9
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
10
 
11
11
  RSpec.configure do |config|
12
-
12
+ config.mock_with :mocha
13
13
  end
metadata CHANGED
@@ -1,60 +1,77 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: smart_titles
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
4
5
  prerelease:
5
- version: 0.1.2
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Semyon Perepelitsa
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-03-14 00:00:00 +07:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
12
+ date: 2011-09-03 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
17
15
  name: activesupport
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70267713724040 !ruby/object:Gem::Requirement
20
17
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
24
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
25
22
  type: :runtime
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: actionpack
29
23
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70267713724040
25
+ - !ruby/object:Gem::Dependency
26
+ name: actionpack
27
+ requirement: &70267713723160 !ruby/object:Gem::Requirement
31
28
  none: false
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
35
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
36
33
  type: :runtime
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
34
+ prerelease: false
35
+ version_requirements: *70267713723160
36
+ - !ruby/object:Gem::Dependency
39
37
  name: rspec
38
+ requirement: &70267713722240 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
40
45
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
46
+ version_requirements: *70267713722240
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: &70267713721580 !ruby/object:Gem::Requirement
42
50
  none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: "0"
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
47
55
  type: :development
48
- version_requirements: *id003
56
+ prerelease: false
57
+ version_requirements: *70267713721580
58
+ - !ruby/object:Gem::Dependency
59
+ name: mocha
60
+ requirement: &70267713720720 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70267713720720
49
69
  description:
50
70
  email: sema@sema.in
51
71
  executables: []
52
-
53
72
  extensions: []
54
-
55
73
  extra_rdoc_files: []
56
-
57
- files:
74
+ files:
58
75
  - .document
59
76
  - .gitignore
60
77
  - .rspec
@@ -64,7 +81,6 @@ files:
64
81
  - README.md
65
82
  - Rakefile
66
83
  - TODO
67
- - VERSION
68
84
  - lib/smart_titles.rb
69
85
  - lib/smart_titles/helper.rb
70
86
  - lib/smart_titles/railtie.rb
@@ -72,34 +88,37 @@ files:
72
88
  - smart_titles.gemspec
73
89
  - spec/smart_titles_helper_spec.rb
74
90
  - spec/spec_helper.rb
75
- has_rdoc: true
76
91
  homepage: http://github.com/semaperepelitsa/smart_titles
77
- licenses:
92
+ licenses:
78
93
  - MIT
79
94
  post_install_message:
80
95
  rdoc_options: []
81
-
82
- require_paths:
96
+ require_paths:
83
97
  - lib
84
- required_ruby_version: !ruby/object:Gem::Requirement
98
+ required_ruby_version: !ruby/object:Gem::Requirement
85
99
  none: false
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: "0"
90
- required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ segments:
105
+ - 0
106
+ hash: 2783804746369927006
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
108
  none: false
92
- requirements:
93
- - - ">="
94
- - !ruby/object:Gem::Version
95
- version: "0"
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ segments:
114
+ - 0
115
+ hash: 2783804746369927006
96
116
  requirements: []
97
-
98
117
  rubyforge_project:
99
- rubygems_version: 1.6.1
118
+ rubygems_version: 1.8.10
100
119
  signing_key:
101
120
  specification_version: 3
102
121
  summary: Really convenient way to set up page titles in Rails application.
103
- test_files:
122
+ test_files:
104
123
  - spec/smart_titles_helper_spec.rb
105
124
  - spec/spec_helper.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.1