happy-titles 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,10 +1,11 @@
1
+ require 'rubygems'
1
2
  require 'rake'
2
- require 'spec/rake/spectask'
3
+ require 'rspec/core/rake_task'
3
4
 
4
5
  desc 'Test the happy-titles plugin.'
5
- Spec::Rake::SpecTask.new('spec') do |t|
6
- t.spec_files = FileList['spec/**/*_spec.rb']
7
- t.spec_opts = ["-c"]
6
+ RSpec::Core::RakeTask.new('spec') do |t|
7
+ t.pattern = FileList['spec/*_spec.rb']
8
+ t.rspec_opts = ['-c']
8
9
  end
9
10
 
10
11
  begin
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
data/happy-titles.gemspec CHANGED
@@ -1,49 +1,47 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{happy-titles}
8
- s.version = "1.0.0"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andy Pearson"]
12
- s.date = %q{2010-09-14}
12
+ s.date = %q{2011-05-07}
13
13
  s.email = %q{andy@andy-pearson.com}
14
14
  s.extra_rdoc_files = [
15
15
  "README.markdown"
16
16
  ]
17
17
  s.files = [
18
18
  ".git_ignore",
19
- ".gitignore",
20
- "MIT-LICENCE",
21
- "README.markdown",
22
- "Rakefile",
23
- "VERSION",
24
- "happy-titles.gemspec",
25
- "init.rb",
26
- "lib/happy-titles.rb",
27
- "lib/happy-titles/railtie.rb",
28
- "rails/init.rb",
29
- "spec/happy_titles_spec.rb",
30
- "spec/spec_helper.rb"
19
+ "MIT-LICENCE",
20
+ "README.markdown",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "happy-titles.gemspec",
24
+ "init.rb",
25
+ "lib/happy-titles.rb",
26
+ "lib/happy-titles/railtie.rb",
27
+ "rails/init.rb",
28
+ "spec/happy_titles_spec.rb",
29
+ "spec/spec_helper.rb"
31
30
  ]
32
31
  s.homepage = %q{http://github.com/andypearson/happy-titles}
33
- s.rdoc_options = ["--charset=UTF-8"]
34
32
  s.require_paths = ["lib"]
35
- s.rubygems_version = %q{1.3.6}
33
+ s.rubygems_version = %q{1.3.7}
36
34
  s.summary = %q{A simple way to handle page titles in your layouts.}
37
35
  s.test_files = [
38
36
  "spec/happy_titles_spec.rb",
39
- "spec/spec_helper.rb"
37
+ "spec/spec_helper.rb"
40
38
  ]
41
39
 
42
40
  if s.respond_to? :specification_version then
43
41
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
42
  s.specification_version = 3
45
43
 
46
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
45
  else
48
46
  end
49
47
  else
data/lib/happy-titles.rb CHANGED
@@ -16,12 +16,20 @@ module HappyTitles
16
16
  content_tag(:title, render_title_template(template_key))
17
17
  end
18
18
 
19
- def title(page_title = nil)
19
+ def title(page_title = nil, settings = {})
20
+
21
+ if page_title && page_title.is_a?(Hash)
22
+ settings = page_title
23
+ page_title = settings[:title] ? settings[:title] : nil
24
+ end
25
+
26
+ @happy_title_settings = settings
20
27
  if page_title
21
28
  @page_title = h(page_title.gsub(/<\/?[^>]*>/, '')) if page_title
22
29
  else
23
30
  @page_title || ''
24
31
  end
32
+
25
33
  end
26
34
 
27
35
  def self.included(base)
@@ -46,18 +54,26 @@ module HappyTitles
46
54
 
47
55
  def render_title_template(template_key)
48
56
  key = (@page_title && @@happy_title_settings[:templates][template_key][1]) ? 1 : 0
49
- substitute_placeholders(@@happy_title_settings[:templates][template_key][key])
57
+ template = read_happy_title_setting(:template) ? read_happy_title_setting(:template) : @@happy_title_settings[:templates][template_key][key]
58
+ substitute_placeholders(template)
50
59
  end
51
60
 
52
61
  def substitute_placeholders(template)
53
62
  title = template
54
63
  title = title.gsub(':title', title_text)
55
- title = title.gsub(':site', @@happy_title_settings[:site])
56
- title = title.gsub(':tagline', @@happy_title_settings[:tagline])
64
+ title = title.gsub(':site', read_happy_title_setting(:site))
65
+ title = title.gsub(':tagline', read_happy_title_setting(:tagline))
66
+ end
67
+
68
+ def read_happy_title_setting(key)
69
+ setting = @@happy_title_settings[key]
70
+ setting = @happy_title_settings[key] if @happy_title_settings && !@happy_title_settings[key].blank?
71
+ setting = setting.call if setting.is_a?(Proc)
72
+ setting
57
73
  end
58
74
 
59
75
  def title_text
60
- (@page_title) ? @page_title : @@happy_title_settings[:tagline]
76
+ (@page_title) ? @page_title : read_happy_title_setting(:tagline)
61
77
  end
62
78
 
63
79
  end
@@ -4,6 +4,13 @@ describe 'Happy Titles!' do
4
4
 
5
5
  before do
6
6
  @view = ActionView::Base.new
7
+ @default_site = ActionView::Base.happy_title_settings[:site].dup
8
+ @default_tagline = ActionView::Base.happy_title_settings[:tagline].dup
9
+ end
10
+
11
+ after do
12
+ ActionView::Base.happy_title_setting(:site, @default_site)
13
+ ActionView::Base.happy_title_setting(:tagline, @default_tagline)
7
14
  end
8
15
 
9
16
  describe 'after loading the plugin' do
@@ -67,16 +74,6 @@ describe 'Happy Titles!' do
67
74
 
68
75
  describe 'custom settings' do
69
76
 
70
- before do
71
- @default_site = ActionView::Base.happy_title_settings[:site].dup
72
- @default_tagline = ActionView::Base.happy_title_settings[:tagline].dup
73
- end
74
-
75
- after do
76
- ActionView::Base.happy_title_setting(:site, @default_site)
77
- ActionView::Base.happy_title_setting(:tagline, @default_tagline)
78
- end
79
-
80
77
  it 'should be able to change the default site' do
81
78
  ActionView::Base.happy_title_setting(:site, 'My Custom Site')
82
79
  ActionView::Base.happy_title_settings[:site].should == 'My Custom Site'
@@ -120,7 +117,7 @@ describe 'Happy Titles!' do
120
117
 
121
118
  it 'should set the title' do
122
119
  @view.title("Happy Title!")
123
- @view.send(:page_title).should == "Happy Title!"
120
+ @view.page_title.should == "Happy Title!"
124
121
  end
125
122
 
126
123
  it 'should overwrite a privously set title' do
@@ -146,6 +143,65 @@ describe 'Happy Titles!' do
146
143
 
147
144
  end
148
145
 
146
+ describe 'setting the title with a hash' do
147
+
148
+ it 'should overwite the title' do
149
+ @view.title(:title => 'My page title')
150
+ @view.happy_title.should have_tag('title', 'My page title | My Site')
151
+ end
152
+
153
+ it 'should overwrite the site' do
154
+ @view.title(:site => 'Overridden Site')
155
+ @view.happy_title.should have_tag('title', 'Overridden Site | My short, descriptive and witty tagline')
156
+ end
157
+
158
+ it 'should not overwrite the site if the provided value is blank' do
159
+ @view.title(:site => '')
160
+ @view.happy_title.should have_tag('title', 'My Site | My short, descriptive and witty tagline')
161
+ end
162
+
163
+ it 'should overwrite the tagline' do
164
+ @view.title(:tagline => 'Overridden Tagline')
165
+ @view.happy_title.should have_tag('title', 'My Site | Overridden Tagline')
166
+ end
167
+
168
+ it 'should not overwrite the tagline if the provided value is blank' do
169
+ @view.title(:tagline => '')
170
+ @view.happy_title.should have_tag('title', 'My Site | My short, descriptive and witty tagline')
171
+ end
172
+
173
+ it 'should overwrite the template' do
174
+ @view.title(:template => '[[:site]] -- :title')
175
+ @view.happy_title.should have_tag('title', '[[My Site]] -- My short, descriptive and witty tagline')
176
+ end
177
+
178
+ it 'should not overwrite the template if the provided value is blank' do
179
+ @view.title(:template => '')
180
+ @view.happy_title.should have_tag('title', 'My Site | My short, descriptive and witty tagline')
181
+ end
182
+
183
+ it 'should allow you to set the title seperatly' do
184
+ @view.title('Custom page title', :site => 'Overridden Tagline')
185
+ @view.happy_title.should have_tag('title', 'Custom page title | Overridden Tagline')
186
+ end
187
+
188
+ end
189
+
190
+ describe 'procs as settings' do
191
+
192
+ it 'should allow a proc for the site name and tagline' do
193
+ @view.title(:site => Proc.new { "Site Number #{2 + 2}" }, :tagline => Proc.new { "Tagline Number #{12 - 8}" })
194
+ @view.happy_title.should have_tag('title', 'Site Number 4 | Tagline Number 4')
195
+ end
196
+
197
+ it 'should allow a proc for the site name and tagline from settings' do
198
+ ActionView::Base.happy_title_setting(:site, Proc.new { "Site Number #{3 + 3}" })
199
+ ActionView::Base.happy_title_setting(:tagline, Proc.new { "Tagline Number #{10 - 4}" })
200
+ @view.happy_title.should have_tag('title', 'Site Number 6 | Tagline Number 6')
201
+ end
202
+
203
+ end
204
+
149
205
  describe 'reading the title method' do
150
206
 
151
207
  it 'should return an empty string when called with no args' do
data/spec/spec_helper.rb CHANGED
@@ -1,22 +1,22 @@
1
1
  # coding: utf-8
2
2
  require 'rubygems'
3
3
 
4
- gem 'activesupport', '2.3.8'
5
- gem 'actionpack', '2.3.8'
4
+ gem 'activesupport', '~> 3.0'
5
+ gem 'actionpack', '~> 3.0'
6
6
  require 'active_support'
7
7
  require 'action_pack'
8
8
  require 'action_view'
9
9
  require 'action_controller'
10
10
 
11
- gem 'rspec', '>= 1.2.6'
12
- gem 'rspec-rails', '>= 1.2.6'
11
+ gem 'rspec', '~> 2.5'
12
+ gem 'rspec-rails', '~> 2.5'
13
13
  gem 'hpricot', '>= 0.6.1'
14
14
  gem 'rspec_tag_matchers', '>= 1.0.0'
15
15
  require 'rspec_tag_matchers'
16
16
 
17
17
  require File.join(File.dirname(__FILE__), "../lib/happy-titles")
18
18
 
19
- Spec::Runner.configure do |config|
19
+ RSpec.configure do |config|
20
20
  config.include(RspecTagMatchers)
21
21
  end
22
22
 
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: happy-titles
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 19
4
5
  prerelease: false
5
6
  segments:
6
7
  - 1
8
+ - 1
7
9
  - 0
8
- - 0
9
- version: 1.0.0
10
+ version: 1.1.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Andy Pearson
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-09-14 00:00:00 +01:00
18
+ date: 2011-05-07 00:00:00 +01:00
18
19
  default_executable:
19
20
  dependencies: []
20
21
 
@@ -28,7 +29,6 @@ extra_rdoc_files:
28
29
  - README.markdown
29
30
  files:
30
31
  - .git_ignore
31
- - .gitignore
32
32
  - MIT-LICENCE
33
33
  - README.markdown
34
34
  - Rakefile
@@ -45,28 +45,32 @@ homepage: http://github.com/andypearson/happy-titles
45
45
  licenses: []
46
46
 
47
47
  post_install_message:
48
- rdoc_options:
49
- - --charset=UTF-8
48
+ rdoc_options: []
49
+
50
50
  require_paths:
51
51
  - lib
52
52
  required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
53
54
  requirements:
54
55
  - - ">="
55
56
  - !ruby/object:Gem::Version
57
+ hash: 3
56
58
  segments:
57
59
  - 0
58
60
  version: "0"
59
61
  required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
60
63
  requirements:
61
64
  - - ">="
62
65
  - !ruby/object:Gem::Version
66
+ hash: 3
63
67
  segments:
64
68
  - 0
65
69
  version: "0"
66
70
  requirements: []
67
71
 
68
72
  rubyforge_project:
69
- rubygems_version: 1.3.6
73
+ rubygems_version: 1.3.7
70
74
  signing_key:
71
75
  specification_version: 3
72
76
  summary: A simple way to handle page titles in your layouts.
data/.gitignore DELETED
@@ -1,2 +0,0 @@
1
- .DS_Store
2
- pkg