happy-titles 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/.rubocop.yml +56 -0
- data/.ruby-version +1 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +110 -0
- data/README.md +190 -0
- data/RELEASE.md +11 -0
- data/Rakefile +2 -23
- data/TODO.md +3 -0
- data/happy-titles.gemspec +23 -46
- data/lib/happy-titles.rb +13 -73
- data/lib/happy-titles/config.rb +37 -0
- data/lib/happy-titles/helpers.rb +28 -0
- data/lib/happy-titles/railtie.rb +6 -5
- data/lib/happy-titles/template.rb +33 -0
- data/lib/happy-titles/template_set.rb +48 -0
- data/lib/happy-titles/version.rb +4 -0
- data/spec/fake_app.rb +7 -0
- data/spec/lib/config_spec.rb +42 -0
- data/spec/lib/happy_titles_spec.rb +20 -0
- data/spec/lib/helpers_spec.rb +76 -0
- data/spec/lib/template_set_spec.rb +63 -0
- data/spec/lib/template_spec.rb +68 -0
- data/spec/spec_helper.rb +66 -19
- metadata +124 -55
- data/.git_ignore +0 -1
- data/README.markdown +0 -153
- data/VERSION +0 -1
- data/init.rb +0 -2
- data/rails/init.rb +0 -2
- data/spec/happy_titles_spec.rb +0 -330
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.1.0
|
data/init.rb
DELETED
data/rails/init.rb
DELETED
data/spec/happy_titles_spec.rb
DELETED
@@ -1,330 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
describe 'Happy Titles!' do
|
4
|
-
|
5
|
-
before do
|
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)
|
14
|
-
end
|
15
|
-
|
16
|
-
describe 'after loading the plugin' do
|
17
|
-
|
18
|
-
it "should be mixed into ActionView::Base" do
|
19
|
-
ActionView::Base.included_modules.include?(HappyTitles).should be_true
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should respond to happy_title_settings class variable' do
|
23
|
-
ActionView::Base.happy_title_settings.should be_a(Hash)
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should respond to happy_title_template class method' do
|
27
|
-
ActionView::Base.should respond_to(:happy_title_template)
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'should respond to happy_title_setting class method' do
|
31
|
-
ActionView::Base.should respond_to(:happy_title_setting)
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'should respond to happy_title helper' do
|
35
|
-
@view.should respond_to(:happy_title)
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'should respond to title helper' do
|
39
|
-
@view.should respond_to(:title)
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
describe 'default settings' do
|
45
|
-
|
46
|
-
it 'should have a default site setting' do
|
47
|
-
ActionView::Base.happy_title_settings[:site].should == 'My Site'
|
48
|
-
end
|
49
|
-
it 'should have a default tagline setting' do
|
50
|
-
ActionView::Base.happy_title_settings[:tagline].should == 'My short, descriptive and witty tagline'
|
51
|
-
end
|
52
|
-
|
53
|
-
describe 'templates' do
|
54
|
-
|
55
|
-
it 'should have a list of templates' do
|
56
|
-
ActionView::Base.happy_title_settings[:templates].should be_a(Hash)
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'should have a default template' do
|
60
|
-
ActionView::Base.happy_title_settings[:templates][:default].should be_an(Array)
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'should have a default template for when the page title is not set' do
|
64
|
-
ActionView::Base.happy_title_settings[:templates][:default][0].should == ':site | :title'
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'should have a default template for when the page title is set' do
|
68
|
-
ActionView::Base.happy_title_settings[:templates][:default][1].should == ':title | :site'
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
describe 'custom settings' do
|
76
|
-
|
77
|
-
it 'should be able to change the default site' do
|
78
|
-
ActionView::Base.happy_title_setting(:site, 'My Custom Site')
|
79
|
-
ActionView::Base.happy_title_settings[:site].should == 'My Custom Site'
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'should be able to change the default tagline' do
|
83
|
-
ActionView::Base.happy_title_setting(:tagline, 'My very custom tagline')
|
84
|
-
ActionView::Base.happy_title_settings[:tagline].should == 'My very custom tagline'
|
85
|
-
end
|
86
|
-
|
87
|
-
describe 'templates' do
|
88
|
-
|
89
|
-
before do
|
90
|
-
@default_templates = ActionView::Base.happy_title_settings[:templates].dup
|
91
|
-
end
|
92
|
-
|
93
|
-
after do
|
94
|
-
ActionView::Base.happy_title_settings[:templates] = @default_templates
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'should be able to change the default templates' do
|
98
|
-
ActionView::Base.happy_title_template(:default, '[:site] :title', ':title at :site')
|
99
|
-
ActionView::Base.happy_title_settings[:templates][:default].should == ['[:site] :title', ':title at :site']
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'should be able to add a new template' do
|
103
|
-
ActionView::Base.happy_title_template(:new_template, '[:site] :title', ':title at :site')
|
104
|
-
ActionView::Base.happy_title_settings[:templates][:new_template].should == ['[:site] :title', ':title at :site']
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'should be able to add a new template with one format' do
|
108
|
-
ActionView::Base.happy_title_template(:new_template, '[:site] :title')
|
109
|
-
ActionView::Base.happy_title_settings[:templates][:new_template].should == ['[:site] :title']
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|
113
|
-
|
114
|
-
end
|
115
|
-
|
116
|
-
describe 'setting the title' do
|
117
|
-
|
118
|
-
it 'should set the title' do
|
119
|
-
@view.title("Happy Title!")
|
120
|
-
@view.page_title.should == "Happy Title!"
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'should overwrite a privously set title' do
|
124
|
-
@view.title('First Page Title')
|
125
|
-
@view.title('Second Page Title')
|
126
|
-
@view.page_title.should eql("Second Page Title")
|
127
|
-
end
|
128
|
-
|
129
|
-
it 'should strip HTML elements from the title' do
|
130
|
-
@view.title('<strong>Cat is</strong>!')
|
131
|
-
@view.page_title.should eql('Cat is!')
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'should escape special entities in the title element' do
|
135
|
-
@view.title('This & That')
|
136
|
-
@view.page_title.should eql('This & That')
|
137
|
-
end
|
138
|
-
|
139
|
-
it 'should handle a mix of HTML and special entities' do
|
140
|
-
@view.title('<strong>This & That</strong>')
|
141
|
-
@view.page_title.should eql('This & That')
|
142
|
-
end
|
143
|
-
|
144
|
-
end
|
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
|
-
|
205
|
-
describe 'reading the title method' do
|
206
|
-
|
207
|
-
it 'should return an empty string when called with no args' do
|
208
|
-
@view.title.should == ''
|
209
|
-
end
|
210
|
-
|
211
|
-
it 'should return @page_title when @page_title is set and is called with no args' do
|
212
|
-
@view.title('Happy Title!')
|
213
|
-
@view.title.should == 'Happy Title!'
|
214
|
-
end
|
215
|
-
|
216
|
-
it 'should not set the title when called with no args' do
|
217
|
-
@view.title
|
218
|
-
@view.happy_title.should have_tag('title', 'My Site | My short, descriptive and witty tagline')
|
219
|
-
end
|
220
|
-
|
221
|
-
end
|
222
|
-
|
223
|
-
describe 'showing the title' do
|
224
|
-
|
225
|
-
it 'should output a valid title element' do
|
226
|
-
@view.happy_title.should have_tag('title')
|
227
|
-
end
|
228
|
-
|
229
|
-
describe 'with default settings' do
|
230
|
-
|
231
|
-
it 'should use the default template when the page title is not set' do
|
232
|
-
@view.happy_title.should have_tag('title', 'My Site | My short, descriptive and witty tagline')
|
233
|
-
end
|
234
|
-
|
235
|
-
it 'should use the default template when the page title is set' do
|
236
|
-
@view.title('Example Page Title')
|
237
|
-
@view.happy_title.should have_tag('title', 'Example Page Title | My Site')
|
238
|
-
end
|
239
|
-
|
240
|
-
end
|
241
|
-
|
242
|
-
describe 'with custom settings' do
|
243
|
-
|
244
|
-
before do
|
245
|
-
@default_site = ActionView::Base.happy_title_settings[:site].dup
|
246
|
-
@default_tagline = ActionView::Base.happy_title_settings[:tagline].dup
|
247
|
-
end
|
248
|
-
|
249
|
-
after do
|
250
|
-
ActionView::Base.happy_title_setting(:site, @default_site)
|
251
|
-
ActionView::Base.happy_title_setting(:tagline, @default_tagline)
|
252
|
-
end
|
253
|
-
|
254
|
-
it 'should render the title with a custom site' do
|
255
|
-
ActionView::Base.happy_title_setting(:site, 'Custom Site')
|
256
|
-
@view.happy_title.should have_tag('title', 'Custom Site | My short, descriptive and witty tagline')
|
257
|
-
end
|
258
|
-
|
259
|
-
it 'should render the title with a custom tagline' do
|
260
|
-
ActionView::Base.happy_title_setting(:tagline, 'My custom tagline...')
|
261
|
-
@view.happy_title.should have_tag('title', 'My Site | My custom tagline...')
|
262
|
-
end
|
263
|
-
|
264
|
-
describe '(templates)' do
|
265
|
-
|
266
|
-
before do
|
267
|
-
@default_templates = ActionView::Base.happy_title_settings[:templates].dup
|
268
|
-
end
|
269
|
-
|
270
|
-
after do
|
271
|
-
ActionView::Base.happy_title_settings[:templates] = @default_templates
|
272
|
-
end
|
273
|
-
|
274
|
-
describe 'template with a single format' do
|
275
|
-
|
276
|
-
before do
|
277
|
-
ActionView::Base.happy_title_template(:default, '[:site] :title')
|
278
|
-
end
|
279
|
-
|
280
|
-
it 'should render the template when the title is not set' do
|
281
|
-
@view.happy_title.should have_tag('title', '[My Site] My short, descriptive and witty tagline')
|
282
|
-
end
|
283
|
-
|
284
|
-
it 'should render the template when the title is set' do
|
285
|
-
@view.title('Another example title')
|
286
|
-
@view.happy_title.should have_tag('title', '[My Site] Another example title')
|
287
|
-
end
|
288
|
-
|
289
|
-
end
|
290
|
-
|
291
|
-
describe 'template with two formats' do
|
292
|
-
|
293
|
-
before do
|
294
|
-
ActionView::Base.happy_title_template(:default, '[:site] :title', ':title at :site')
|
295
|
-
end
|
296
|
-
|
297
|
-
it 'should render the template when the title is not set' do
|
298
|
-
@view.happy_title.should have_tag('title', '[My Site] My short, descriptive and witty tagline')
|
299
|
-
end
|
300
|
-
|
301
|
-
it 'should render the alternate template when the title is set' do
|
302
|
-
@view.title('Would of thought these titles would of got a bit funnier by now')
|
303
|
-
@view.happy_title.should have_tag('title', 'Would of thought these titles would of got a bit funnier by now at My Site')
|
304
|
-
end
|
305
|
-
end
|
306
|
-
|
307
|
-
describe 'using a custom template' do
|
308
|
-
|
309
|
-
before do
|
310
|
-
ActionView::Base.happy_title_template(:custom, '++:site++', ':title ++:site++')
|
311
|
-
end
|
312
|
-
|
313
|
-
it 'should render a custom template when the title is not set' do
|
314
|
-
@view.happy_title(:custom).should have_tag('title', '++My Site++')
|
315
|
-
end
|
316
|
-
|
317
|
-
it 'should render a custom template when the title is not set' do
|
318
|
-
@view.title('Fraid not, I got nothing')
|
319
|
-
@view.happy_title(:custom).should have_tag('title', 'Fraid not, I got nothing ++My Site++')
|
320
|
-
end
|
321
|
-
|
322
|
-
end
|
323
|
-
|
324
|
-
end
|
325
|
-
|
326
|
-
end
|
327
|
-
|
328
|
-
end
|
329
|
-
|
330
|
-
end
|