page_title_helper 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +4 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +98 -0
- data/Rakefile +6 -77
- data/lib/page_title_helper.rb +19 -21
- data/lib/page_title_helper/version.rb +3 -0
- data/page_title_helper.gemspec +28 -0
- data/test/multiple_formats_test.rb +15 -16
- data/test/page_title_helper_test.rb +25 -32
- data/test/test_helper.rb +2 -2
- metadata +62 -71
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
page_title_helper (2.1.0)
|
|
5
|
+
rails (>= 3.0.0)
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: http://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
actionmailer (3.2.3)
|
|
11
|
+
actionpack (= 3.2.3)
|
|
12
|
+
mail (~> 2.4.4)
|
|
13
|
+
actionpack (3.2.3)
|
|
14
|
+
activemodel (= 3.2.3)
|
|
15
|
+
activesupport (= 3.2.3)
|
|
16
|
+
builder (~> 3.0.0)
|
|
17
|
+
erubis (~> 2.7.0)
|
|
18
|
+
journey (~> 1.0.1)
|
|
19
|
+
rack (~> 1.4.0)
|
|
20
|
+
rack-cache (~> 1.2)
|
|
21
|
+
rack-test (~> 0.6.1)
|
|
22
|
+
sprockets (~> 2.1.2)
|
|
23
|
+
activemodel (3.2.3)
|
|
24
|
+
activesupport (= 3.2.3)
|
|
25
|
+
builder (~> 3.0.0)
|
|
26
|
+
activerecord (3.2.3)
|
|
27
|
+
activemodel (= 3.2.3)
|
|
28
|
+
activesupport (= 3.2.3)
|
|
29
|
+
arel (~> 3.0.2)
|
|
30
|
+
tzinfo (~> 0.3.29)
|
|
31
|
+
activeresource (3.2.3)
|
|
32
|
+
activemodel (= 3.2.3)
|
|
33
|
+
activesupport (= 3.2.3)
|
|
34
|
+
activesupport (3.2.3)
|
|
35
|
+
i18n (~> 0.6)
|
|
36
|
+
multi_json (~> 1.0)
|
|
37
|
+
arel (3.0.2)
|
|
38
|
+
builder (3.0.0)
|
|
39
|
+
erubis (2.7.0)
|
|
40
|
+
hike (1.2.1)
|
|
41
|
+
i18n (0.6.0)
|
|
42
|
+
journey (1.0.3)
|
|
43
|
+
json (1.6.6)
|
|
44
|
+
mail (2.4.4)
|
|
45
|
+
i18n (>= 0.4.0)
|
|
46
|
+
mime-types (~> 1.16)
|
|
47
|
+
treetop (~> 1.4.8)
|
|
48
|
+
mime-types (1.18)
|
|
49
|
+
multi_json (1.2.0)
|
|
50
|
+
polyglot (0.3.3)
|
|
51
|
+
rack (1.4.1)
|
|
52
|
+
rack-cache (1.2)
|
|
53
|
+
rack (>= 0.4)
|
|
54
|
+
rack-ssl (1.3.2)
|
|
55
|
+
rack
|
|
56
|
+
rack-test (0.6.1)
|
|
57
|
+
rack (>= 1.0)
|
|
58
|
+
rails (3.2.3)
|
|
59
|
+
actionmailer (= 3.2.3)
|
|
60
|
+
actionpack (= 3.2.3)
|
|
61
|
+
activerecord (= 3.2.3)
|
|
62
|
+
activeresource (= 3.2.3)
|
|
63
|
+
activesupport (= 3.2.3)
|
|
64
|
+
bundler (~> 1.0)
|
|
65
|
+
railties (= 3.2.3)
|
|
66
|
+
railties (3.2.3)
|
|
67
|
+
actionpack (= 3.2.3)
|
|
68
|
+
activesupport (= 3.2.3)
|
|
69
|
+
rack-ssl (~> 1.3.2)
|
|
70
|
+
rake (>= 0.8.7)
|
|
71
|
+
rdoc (~> 3.4)
|
|
72
|
+
thor (~> 0.14.6)
|
|
73
|
+
rake (0.9.2.2)
|
|
74
|
+
rdoc (3.12)
|
|
75
|
+
json (~> 1.4)
|
|
76
|
+
shoulda (3.0.1)
|
|
77
|
+
shoulda-context (~> 1.0.0)
|
|
78
|
+
shoulda-matchers (~> 1.0.0)
|
|
79
|
+
shoulda-context (1.0.0)
|
|
80
|
+
shoulda-matchers (1.0.0)
|
|
81
|
+
sprockets (2.1.2)
|
|
82
|
+
hike (~> 1.2)
|
|
83
|
+
rack (~> 1.0)
|
|
84
|
+
tilt (~> 1.1, != 1.3.0)
|
|
85
|
+
thor (0.14.6)
|
|
86
|
+
tilt (1.3.3)
|
|
87
|
+
treetop (1.4.10)
|
|
88
|
+
polyglot
|
|
89
|
+
polyglot (>= 0.3.1)
|
|
90
|
+
tzinfo (0.3.33)
|
|
91
|
+
|
|
92
|
+
PLATFORMS
|
|
93
|
+
ruby
|
|
94
|
+
|
|
95
|
+
DEPENDENCIES
|
|
96
|
+
page_title_helper!
|
|
97
|
+
rake (>= 0.9.2)
|
|
98
|
+
shoulda
|
data/Rakefile
CHANGED
|
@@ -1,40 +1,13 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'bundler/setup'
|
|
2
3
|
require 'rake/testtask'
|
|
3
|
-
require 'rake/rdoctask'
|
|
4
|
-
require 'yard'
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
task :default => :test
|
|
8
|
-
|
|
9
|
-
def version
|
|
10
|
-
defined?(PageTitleHelper) ? PageTitleHelper::VERSION : "0.0.0.error"
|
|
11
|
-
end
|
|
5
|
+
include Rake::DSL
|
|
12
6
|
|
|
13
|
-
|
|
14
|
-
require File.join(File.dirname(__FILE__), 'lib', 'page_title_helper')
|
|
15
|
-
rescue
|
|
16
|
-
puts "Oops, there was en error loading page_title_helper.rb"
|
|
17
|
-
end
|
|
7
|
+
Bundler::GemHelper.install_tasks
|
|
18
8
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
Jeweler::Tasks.new do |gemspec|
|
|
22
|
-
gemspec.name = "page_title_helper"
|
|
23
|
-
gemspec.version = version
|
|
24
|
-
gemspec.summary = "Simple, internationalized and DRY page titles and headings for rails."
|
|
25
|
-
gemspec.email = "lukas.westermann@gmail.com"
|
|
26
|
-
gemspec.homepage = "http://github.com/lwe/page_title_helper"
|
|
27
|
-
gemspec.authors = ["Lukas Westermann"]
|
|
28
|
-
|
|
29
|
-
gemspec.files.reject! { |f| f =~ /\.gemspec$/ }
|
|
30
|
-
|
|
31
|
-
gemspec.add_dependency('rails', '>= 3.0.0')
|
|
32
|
-
gemspec.add_development_dependency('shoulda')
|
|
33
|
-
end
|
|
34
|
-
Jeweler::GemcutterTasks.new
|
|
35
|
-
rescue LoadError
|
|
36
|
-
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
|
37
|
-
end
|
|
9
|
+
desc 'Default: run unit tests.'
|
|
10
|
+
task :default => :test
|
|
38
11
|
|
|
39
12
|
desc 'Test the page_title_helper plugin.'
|
|
40
13
|
Rake::TestTask.new(:test) do |t|
|
|
@@ -42,47 +15,3 @@ Rake::TestTask.new(:test) do |t|
|
|
|
42
15
|
t.pattern = 'test/**/*_test.rb'
|
|
43
16
|
t.verbose = true
|
|
44
17
|
end
|
|
45
|
-
|
|
46
|
-
desc 'Generate documentation for gravatarify. (requires yard)'
|
|
47
|
-
YARD::Rake::YardocTask.new(:doc) do |t|
|
|
48
|
-
t.files = ['lib/**/*.rb']
|
|
49
|
-
t.options = [
|
|
50
|
-
"--readme", "README.md",
|
|
51
|
-
"--title", "page_title_helper API v#{version} Documentation"
|
|
52
|
-
]
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
namespace :metrics do
|
|
56
|
-
desc 'Report all metrics, i.e. stats and code coverage.'
|
|
57
|
-
task :all => [:stats, :coverage]
|
|
58
|
-
|
|
59
|
-
desc 'Report code statistics for library and tests to shell.'
|
|
60
|
-
task :stats do |t|
|
|
61
|
-
require 'code_statistics'
|
|
62
|
-
dirs = {
|
|
63
|
-
'Libraries' => 'lib',
|
|
64
|
-
'Unit tests' => 'test'
|
|
65
|
-
}.map { |name,dir| [name, File.join(File.dirname(__FILE__), dir)] }
|
|
66
|
-
CodeStatistics.new(*dirs).to_s
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
desc 'Report code coverage to HTML (doc/coverage) and shell (requires rcov).'
|
|
70
|
-
task :coverage do |t|
|
|
71
|
-
rm_f "doc/coverage"
|
|
72
|
-
mkdir_p "doc/coverage"
|
|
73
|
-
rcov = %(rcov -Ilib:test --exclude '\/gems\/' -o doc/coverage -T test/*_test.rb )
|
|
74
|
-
system rcov
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
desc 'Start IRB console with loaded test/test_helper.rb and PageTitleHelper.'
|
|
79
|
-
task :console do |t|
|
|
80
|
-
chdir File.dirname(__FILE__)
|
|
81
|
-
exec 'irb -Ilib -r test/test_helper.rb -r page_title_helper'
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
desc 'Clean up generated files.'
|
|
85
|
-
task :clean do |t|
|
|
86
|
-
FileUtils.rm_rf "doc"
|
|
87
|
-
FileUtils.rm_rf "pkg"
|
|
88
|
-
end
|
data/lib/page_title_helper.rb
CHANGED
|
@@ -7,17 +7,15 @@
|
|
|
7
7
|
#
|
|
8
8
|
# See documentation for +page_title+ for usage examples and more informations.
|
|
9
9
|
require 'active_support'
|
|
10
|
+
require 'page_title_helper/version'
|
|
10
11
|
|
|
11
12
|
# PageTitleHelper
|
|
12
13
|
module PageTitleHelper
|
|
13
14
|
|
|
14
|
-
# Page title version number
|
|
15
|
-
VERSION = "2.0.0".freeze
|
|
16
|
-
|
|
17
15
|
# http://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/interpolations.rb
|
|
18
|
-
module Interpolations
|
|
16
|
+
module Interpolations
|
|
19
17
|
extend self
|
|
20
|
-
|
|
18
|
+
|
|
21
19
|
def self.interpolate(pattern, *args)
|
|
22
20
|
instance_methods(false).sort.reverse.inject(pattern.to_s.dup) do |result, tag|
|
|
23
21
|
result.gsub(/:#{tag}/) do |match|
|
|
@@ -25,21 +23,21 @@ module PageTitleHelper
|
|
|
25
23
|
end
|
|
26
24
|
end
|
|
27
25
|
end
|
|
28
|
-
|
|
26
|
+
|
|
29
27
|
def app(env)
|
|
30
28
|
env[:app] || I18n.translate(:'app.name', :default => File.basename(Rails.root).humanize)
|
|
31
29
|
end
|
|
32
|
-
|
|
30
|
+
|
|
33
31
|
def title(env)
|
|
34
32
|
env[:title]
|
|
35
33
|
end
|
|
36
34
|
end
|
|
37
|
-
|
|
35
|
+
|
|
38
36
|
# Add new, custom, interpolation.
|
|
39
37
|
def self.interpolates(key, &block)
|
|
40
38
|
Interpolations.send(:define_method, key, &block)
|
|
41
39
|
end
|
|
42
|
-
|
|
40
|
+
|
|
43
41
|
# Default options, which are globally referenced and can
|
|
44
42
|
# be changed globally, which might be useful in some cases.
|
|
45
43
|
def self.options
|
|
@@ -48,7 +46,7 @@ module PageTitleHelper
|
|
|
48
46
|
:default => :'app.tagline'
|
|
49
47
|
}
|
|
50
48
|
end
|
|
51
|
-
|
|
49
|
+
|
|
52
50
|
# Defined alias formats, pretty useful.
|
|
53
51
|
def self.formats
|
|
54
52
|
@formats ||= {
|
|
@@ -57,49 +55,49 @@ module PageTitleHelper
|
|
|
57
55
|
:title => ":title"
|
|
58
56
|
}
|
|
59
57
|
end
|
|
60
|
-
|
|
58
|
+
|
|
61
59
|
# Specify page title
|
|
62
60
|
def page_title!(*args)
|
|
63
61
|
@_page_title = args.size > 1 ? args : args.first
|
|
64
62
|
@_page_title.is_a?(Array) ? @_page_title.first : @_page_title
|
|
65
63
|
end
|
|
66
|
-
|
|
64
|
+
|
|
67
65
|
def page_title(options = nil, &block)
|
|
68
66
|
return page_title!(yield) if block_given? # define title
|
|
69
|
-
|
|
67
|
+
|
|
70
68
|
options = PageTitleHelper.options.merge(options || {}).symbolize_keys!
|
|
71
69
|
options[:format] ||= :title # handles :format => false
|
|
72
70
|
options.assert_valid_keys(:app, :default, :format)
|
|
73
|
-
|
|
71
|
+
|
|
74
72
|
# read page title and split into 'real' title and customized format
|
|
75
73
|
title = @_page_title || page_title_from_translation(options[:default])
|
|
76
74
|
title, options[:format] = *(title << options[:format]) if title.is_a?(Array)
|
|
77
|
-
|
|
75
|
+
|
|
78
76
|
# handle format aliases
|
|
79
77
|
format = options.delete(:format)
|
|
80
78
|
format = PageTitleHelper.formats[format] if PageTitleHelper.formats.include?(format)
|
|
81
|
-
|
|
79
|
+
|
|
82
80
|
# construct basic env to pass around
|
|
83
81
|
env = { :title => title, :app => options.delete(:app), :options => options, :view => self }
|
|
84
|
-
|
|
82
|
+
|
|
85
83
|
# interpolate format
|
|
86
84
|
Interpolations.interpolate(format, env)
|
|
87
85
|
end
|
|
88
|
-
|
|
86
|
+
|
|
89
87
|
protected
|
|
90
|
-
|
|
88
|
+
|
|
91
89
|
# Find translation for `controller.action.title` combination, falls back to
|
|
92
90
|
# `controller.title` or supplied default if no title was found.
|
|
93
91
|
def page_title_from_translation(default)
|
|
94
92
|
base = controller.controller_path.tr('/', '.')
|
|
95
93
|
action = params[:action].to_s
|
|
96
|
-
|
|
94
|
+
|
|
97
95
|
keys = [:"#{base}.#{action}.title"]
|
|
98
96
|
keys << :"#{base}.new.title" if action == 'create'
|
|
99
97
|
keys << :"#{base}.edit.title" if action == 'update'
|
|
100
98
|
keys << :"#{base}.title"
|
|
101
99
|
keys << default
|
|
102
|
-
|
|
100
|
+
|
|
103
101
|
I18n.translate(keys.shift, :default => keys)
|
|
104
102
|
end
|
|
105
103
|
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
+
require "page_title_helper/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = "page_title_helper"
|
|
7
|
+
s.version = PageTitleHelper::VERSION
|
|
8
|
+
s.platform = Gem::Platform::RUBY
|
|
9
|
+
s.summary = "Simple, internationalized and DRY page titles and headings for Rails."
|
|
10
|
+
s.description = "Simple, internationalized and DRY page titles and headings for rails."
|
|
11
|
+
|
|
12
|
+
s.required_ruby_version = ">= 1.8.7"
|
|
13
|
+
s.required_rubygems_version = ">= 1.3.6"
|
|
14
|
+
|
|
15
|
+
s.authors = ["Lukas Westermann"]
|
|
16
|
+
s.email = ["lukas.westermann@gmail.com"]
|
|
17
|
+
s.homepage = "http://github.com/lwe/page_title_helper"
|
|
18
|
+
|
|
19
|
+
s.files = `git ls-files`.split("\n")
|
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
21
|
+
s.require_path = 'lib'
|
|
22
|
+
|
|
23
|
+
s.license = 'MIT'
|
|
24
|
+
|
|
25
|
+
s.add_dependency 'rails', '>= 3.0.0'
|
|
26
|
+
s.add_development_dependency 'rake', '>= 0.9.2'
|
|
27
|
+
s.add_development_dependency 'shoulda', '>= 0'
|
|
28
|
+
end
|
|
@@ -1,56 +1,55 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
require 'page_title_helper'
|
|
3
3
|
|
|
4
|
-
class MultipleFormatsTest < ActiveSupport::TestCase
|
|
4
|
+
class MultipleFormatsTest < ActiveSupport::TestCase
|
|
5
5
|
context "#page_title supporting multiple formats through arrays" do
|
|
6
6
|
setup do
|
|
7
7
|
@view = TestView.new('contacts', 'list')
|
|
8
8
|
end
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
should "accept an array passed in the page_title block and use the second argument as format" do
|
|
11
11
|
@view.page_title { ["Oh my...!", ":title // :app"] }
|
|
12
12
|
assert_equal "Oh my...! // Page title helper", @view.page_title
|
|
13
13
|
end
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
should "still return title as string and not the array" do
|
|
16
16
|
assert_equal "Oh my...!", @view.page_title { ["Oh my...!", ":title // :app"] }
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
context "#page_title with format aliases" do
|
|
21
21
|
setup do
|
|
22
|
-
PageTitleHelper.formats[:myformat] = ":title <-> :app"
|
|
22
|
+
PageTitleHelper.formats[:myformat] = ":title <-> :app"
|
|
23
23
|
@view = TestView.new('contacts', 'list')
|
|
24
|
-
@view.template = "contacts/list.html.erb"
|
|
25
24
|
end
|
|
26
|
-
|
|
25
|
+
|
|
27
26
|
should "have a default alias named :app" do
|
|
28
|
-
assert_equal "Page title helper", @view.page_title(:format => :app)
|
|
27
|
+
assert_equal "Page title helper", @view.page_title(:format => :app)
|
|
29
28
|
end
|
|
30
|
-
|
|
29
|
+
|
|
31
30
|
should "allow custom aliases to be defined and used" do
|
|
32
31
|
@view.page_title { "Test" }
|
|
33
32
|
assert_equal "Test <-> Page title helper", @view.page_title(:format => :myformat)
|
|
34
33
|
end
|
|
35
|
-
|
|
34
|
+
|
|
36
35
|
should "fallback to default format, if array is not big enough (i.e. only contains single element...)" do
|
|
37
36
|
assert_equal "Test", @view.page_title { ["Test"] }
|
|
38
37
|
assert_equal "Test - Page title helper", @view.page_title
|
|
39
38
|
end
|
|
40
|
-
|
|
39
|
+
|
|
41
40
|
context "used with the array block" do
|
|
42
41
|
should "also allow aliases returned in that array thingy" do
|
|
43
42
|
assert_equal "Test", @view.page_title { ["Test", :myformat] }
|
|
44
43
|
assert_equal "Test <-> Page title helper", @view.page_title
|
|
45
|
-
end
|
|
46
|
-
|
|
44
|
+
end
|
|
45
|
+
|
|
47
46
|
should "override locally supplied :format arguments" do
|
|
48
47
|
assert_equal "Something", @view.page_title { ["Something", "* * * :title * * *"] }
|
|
49
48
|
assert_equal "* * * Something * * *", @view.page_title(:format => "-= :title =-") # yeah, using x-tra ugly titles :)
|
|
50
49
|
end
|
|
51
50
|
end
|
|
52
51
|
end
|
|
53
|
-
|
|
52
|
+
|
|
54
53
|
context "#page_title, aliases and YAML" do
|
|
55
54
|
setup do
|
|
56
55
|
I18n.load_path = [File.join(File.dirname(__FILE__), "en_wohaapp.yml")]
|
|
@@ -58,12 +57,12 @@ class MultipleFormatsTest < ActiveSupport::TestCase
|
|
|
58
57
|
PageTitleHelper.formats[:promo] = ":app > :title"
|
|
59
58
|
@view = TestView.new
|
|
60
59
|
end
|
|
61
|
-
|
|
60
|
+
|
|
62
61
|
should "allow to overide format through YAML" do
|
|
63
62
|
@view.controller! 'pages', 'features'
|
|
64
63
|
assert_equal 'Wohaapp > Feature comparison', @view.page_title
|
|
65
64
|
end
|
|
66
|
-
|
|
65
|
+
|
|
67
66
|
should "handle raw string formats from YAML as well" do
|
|
68
67
|
@view.controller! 'pages', 'signup'
|
|
69
68
|
assert_equal 'Sign up for Wohaapp now!', @view.page_title
|
|
@@ -7,12 +7,12 @@ class PageTitleHelperTest < ActiveSupport::TestCase
|
|
|
7
7
|
setup do
|
|
8
8
|
I18n.load_path = [File.join(File.dirname(__FILE__), 'en.yml')]
|
|
9
9
|
I18n.reload!
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
@view = TestView.new('contacts', 'list')
|
|
12
12
|
end
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
context "::Interpolations" do
|
|
15
|
-
should "interpolate :app and :title" do
|
|
15
|
+
should "interpolate :app and :title" do
|
|
16
16
|
assert_equal 'Page title helper', PageTitleHelper::Interpolations.app({})
|
|
17
17
|
assert_equal 'Appname', PageTitleHelper::Interpolations.app({ :app => 'Appname' })
|
|
18
18
|
assert_equal 'untitled', PageTitleHelper::Interpolations.title({:title => 'untitled'})
|
|
@@ -21,20 +21,20 @@ class PageTitleHelperTest < ActiveSupport::TestCase
|
|
|
21
21
|
should "allow adding custom interpolations" do
|
|
22
22
|
# extend Interpolations
|
|
23
23
|
PageTitleHelper.interpolates(:app_reverse) { |env| app(env).reverse.downcase }
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
assert_equal "anna", PageTitleHelper::Interpolations.app_reverse({ :app => 'Anna' })
|
|
26
26
|
assert_equal "ppa", PageTitleHelper::Interpolations.interpolate(':app_reverse', { :app => 'app' })
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
should "interpolate in correct order, i.e. longest first" do
|
|
30
|
-
PageTitleHelper.interpolates(:foobar) { "foobar" }
|
|
31
|
-
PageTitleHelper.interpolates(:foobar_test) { "foobar_test" }
|
|
32
|
-
PageTitleHelper.interpolates(:title_foobar) { "title_foobar" }
|
|
33
|
-
|
|
30
|
+
PageTitleHelper.interpolates(:foobar) { |env| "foobar" }
|
|
31
|
+
PageTitleHelper.interpolates(:foobar_test) { |env| "foobar_test" }
|
|
32
|
+
PageTitleHelper.interpolates(:title_foobar) { |env| "title_foobar" }
|
|
33
|
+
|
|
34
34
|
assert_equal "title_foobar / foobar_test / foobar / foobar_x", PageTitleHelper::Interpolations.interpolate(":title_foobar / :foobar_test / :foobar / :foobar_x", {})
|
|
35
|
-
end
|
|
35
|
+
end
|
|
36
36
|
end
|
|
37
|
-
|
|
37
|
+
|
|
38
38
|
context "#page_title (define w/ block)" do
|
|
39
39
|
should "return title from block and render with app name" do
|
|
40
40
|
assert_equal 'foo', @view.page_title { "foo" }
|
|
@@ -44,9 +44,9 @@ class PageTitleHelperTest < ActiveSupport::TestCase
|
|
|
44
44
|
should "set custom title using a translation with a placeholder" do
|
|
45
45
|
assert_equal "Displaying Bella", @view.page_title { I18n.t(:placeholder, :name => 'Bella') }
|
|
46
46
|
assert_equal "Displaying Bella - Page title helper", @view.page_title
|
|
47
|
-
end
|
|
47
|
+
end
|
|
48
48
|
end
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
context "#page_title! (define)" do
|
|
51
51
|
should "set page title" do
|
|
52
52
|
assert_equal 'test', @view.page_title!('test')
|
|
@@ -57,21 +57,14 @@ class PageTitleHelperTest < ActiveSupport::TestCase
|
|
|
57
57
|
PageTitleHelper.formats[:bang] = ":title !! :app"
|
|
58
58
|
assert_equal 'test', @view.page_title!('test', :bang)
|
|
59
59
|
assert_equal 'test !! Page title helper', @view.page_title
|
|
60
|
-
end
|
|
60
|
+
end
|
|
61
61
|
end
|
|
62
|
-
|
|
62
|
+
|
|
63
63
|
context "#page_title (rendering)" do
|
|
64
64
|
should "read default title from I18n, based on controller/action" do
|
|
65
65
|
assert_equal 'contacts.list.title - Page title helper', @view.page_title
|
|
66
66
|
end
|
|
67
|
-
|
|
68
|
-
# currently not feasible :(
|
|
69
|
-
# should "if passed in a hash, use it to expand translations" do
|
|
70
|
-
# @view.controller! 'contacts', 'show'
|
|
71
|
-
# assert_equal 'Contact: Bella', @view.page_title!( :name => "Bella" )
|
|
72
|
-
# assert_equal 'Contact: Bella - Page title helper', @view.page_title
|
|
73
|
-
#end
|
|
74
|
-
|
|
67
|
+
|
|
75
68
|
should "only print app name if :format => :app" do
|
|
76
69
|
assert_equal 'Page title helper', @view.page_title(:format => :app)
|
|
77
70
|
end
|
|
@@ -90,11 +83,11 @@ class PageTitleHelperTest < ActiveSupport::TestCase
|
|
|
90
83
|
assert_equal 'untitled', @view.page_title { "untitled" }
|
|
91
84
|
assert_equal "untitled", @view.page_title(:format => false)
|
|
92
85
|
end
|
|
93
|
-
|
|
86
|
+
|
|
94
87
|
should "return title if :format => false and when using the DRY-I18n titles" do
|
|
95
88
|
assert_equal "contacts.list.title", @view.page_title(:format => false)
|
|
96
89
|
end
|
|
97
|
-
|
|
90
|
+
|
|
98
91
|
should "render translated :'app.tagline' if no title is available" do
|
|
99
92
|
@view.controller! 'view/does', 'not_exist'
|
|
100
93
|
assert_equal "Default - Page title helper", @view.page_title
|
|
@@ -104,21 +97,21 @@ class PageTitleHelperTest < ActiveSupport::TestCase
|
|
|
104
97
|
@view.controller! 'admin/account', 'index'
|
|
105
98
|
assert_equal 'Account administration - Page title helper', @view.page_title(:default => 'Other default')
|
|
106
99
|
end
|
|
107
|
-
|
|
100
|
+
|
|
108
101
|
should "not fallback to controller.title if controller.action.title exists" do
|
|
109
102
|
@view.controller! 'admin/account', 'show'
|
|
110
103
|
assert_equal 'Account - Page title helper', @view.page_title(:default => 'Other default')
|
|
111
|
-
end
|
|
104
|
+
end
|
|
112
105
|
|
|
113
106
|
should 'fallback to controller.new.title if create has no title' do
|
|
114
107
|
@view.controller! 'admin/account', 'create'
|
|
115
|
-
assert_equal 'New account - Page title helper', @view.page_title(:default => 'Other default')
|
|
108
|
+
assert_equal 'New account - Page title helper', @view.page_title(:default => 'Other default')
|
|
116
109
|
end
|
|
117
|
-
|
|
110
|
+
|
|
118
111
|
should 'fallback to controller.edit.title if update has no title' do
|
|
119
112
|
@view.controller! 'admin/account', 'update'
|
|
120
|
-
assert_equal 'Edit account - Page title helper', @view.page_title(:default => 'Other default')
|
|
121
|
-
end
|
|
113
|
+
assert_equal 'Edit account - Page title helper', @view.page_title(:default => 'Other default')
|
|
114
|
+
end
|
|
122
115
|
|
|
123
116
|
should "render custom 'default' string, if title is not available nor controller.title" do
|
|
124
117
|
@view.controller! 'view/does', 'not_exist'
|
|
@@ -130,12 +123,12 @@ class PageTitleHelperTest < ActiveSupport::TestCase
|
|
|
130
123
|
assert_equal 'Other default - Page title helper', @view.page_title(:default => :'app.other_tagline')
|
|
131
124
|
end
|
|
132
125
|
end
|
|
133
|
-
|
|
126
|
+
|
|
134
127
|
context "README.md" do
|
|
135
128
|
should "interpolate :controller" do
|
|
136
129
|
PageTitleHelper.interpolates(:controller) { |env| env[:view].controller.controller_name.humanize }
|
|
137
130
|
assert_equal "contacts.list.title - Test", @view.page_title(:format => ":title - :controller")
|
|
138
|
-
end
|
|
131
|
+
end
|
|
139
132
|
end
|
|
140
133
|
end
|
|
141
134
|
end
|
data/test/test_helper.rb
CHANGED
|
@@ -22,12 +22,12 @@ class TestView < ActionView::Base
|
|
|
22
22
|
@controller.controller_path = controller_path
|
|
23
23
|
self.params[:action] = action if action
|
|
24
24
|
end
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
def controller!(controller_path, action)
|
|
27
27
|
@controller.controller_path = controller_path
|
|
28
28
|
self.params[:action] = action
|
|
29
29
|
end
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
def controller
|
|
32
32
|
@controller
|
|
33
33
|
end
|
metadata
CHANGED
|
@@ -1,109 +1,100 @@
|
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: page_title_helper
|
|
3
|
-
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
5
|
-
prerelease:
|
|
6
|
-
segments:
|
|
7
|
-
- 2
|
|
8
|
-
- 0
|
|
9
|
-
- 0
|
|
10
|
-
version: 2.0.0
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 2.1.0
|
|
5
|
+
prerelease:
|
|
11
6
|
platform: ruby
|
|
12
|
-
authors:
|
|
7
|
+
authors:
|
|
13
8
|
- Lukas Westermann
|
|
14
9
|
autorequire:
|
|
15
10
|
bindir: bin
|
|
16
11
|
cert_chain: []
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
dependencies:
|
|
21
|
-
- !ruby/object:Gem::Dependency
|
|
12
|
+
date: 2012-04-11 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
22
15
|
name: rails
|
|
23
|
-
|
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
|
16
|
+
requirement: &70160540680580 !ruby/object:Gem::Requirement
|
|
25
17
|
none: false
|
|
26
|
-
requirements:
|
|
27
|
-
- -
|
|
28
|
-
- !ruby/object:Gem::Version
|
|
29
|
-
hash: 7
|
|
30
|
-
segments:
|
|
31
|
-
- 3
|
|
32
|
-
- 0
|
|
33
|
-
- 0
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
34
21
|
version: 3.0.0
|
|
35
22
|
type: :runtime
|
|
36
|
-
version_requirements: *id001
|
|
37
|
-
- !ruby/object:Gem::Dependency
|
|
38
|
-
name: shoulda
|
|
39
23
|
prerelease: false
|
|
40
|
-
|
|
24
|
+
version_requirements: *70160540680580
|
|
25
|
+
- !ruby/object:Gem::Dependency
|
|
26
|
+
name: rake
|
|
27
|
+
requirement: &70160540680020 !ruby/object:Gem::Requirement
|
|
28
|
+
none: false
|
|
29
|
+
requirements:
|
|
30
|
+
- - ! '>='
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 0.9.2
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: *70160540680020
|
|
36
|
+
- !ruby/object:Gem::Dependency
|
|
37
|
+
name: shoulda
|
|
38
|
+
requirement: &70160540679400 !ruby/object:Gem::Requirement
|
|
41
39
|
none: false
|
|
42
|
-
requirements:
|
|
43
|
-
- -
|
|
44
|
-
- !ruby/object:Gem::Version
|
|
45
|
-
|
|
46
|
-
segments:
|
|
47
|
-
- 0
|
|
48
|
-
version: "0"
|
|
40
|
+
requirements:
|
|
41
|
+
- - ! '>='
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '0'
|
|
49
44
|
type: :development
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
prerelease: false
|
|
46
|
+
version_requirements: *70160540679400
|
|
47
|
+
description: Simple, internationalized and DRY page titles and headings for rails.
|
|
48
|
+
email:
|
|
49
|
+
- lukas.westermann@gmail.com
|
|
53
50
|
executables: []
|
|
54
|
-
|
|
55
51
|
extensions: []
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
- LICENSE
|
|
59
|
-
- README.md
|
|
60
|
-
files:
|
|
52
|
+
extra_rdoc_files: []
|
|
53
|
+
files:
|
|
61
54
|
- .gitignore
|
|
55
|
+
- .travis.yml
|
|
56
|
+
- Gemfile
|
|
57
|
+
- Gemfile.lock
|
|
62
58
|
- LICENSE
|
|
63
59
|
- README.md
|
|
64
60
|
- Rakefile
|
|
65
61
|
- init.rb
|
|
66
62
|
- lib/page_title_helper.rb
|
|
63
|
+
- lib/page_title_helper/version.rb
|
|
64
|
+
- page_title_helper.gemspec
|
|
67
65
|
- test/en.yml
|
|
68
66
|
- test/en_wohaapp.yml
|
|
69
67
|
- test/multiple_formats_test.rb
|
|
70
68
|
- test/page_title_helper_test.rb
|
|
71
69
|
- test/test_helper.rb
|
|
72
|
-
has_rdoc: true
|
|
73
70
|
homepage: http://github.com/lwe/page_title_helper
|
|
74
|
-
licenses:
|
|
75
|
-
|
|
71
|
+
licenses:
|
|
72
|
+
- MIT
|
|
76
73
|
post_install_message:
|
|
77
|
-
rdoc_options:
|
|
78
|
-
|
|
79
|
-
require_paths:
|
|
74
|
+
rdoc_options: []
|
|
75
|
+
require_paths:
|
|
80
76
|
- lib
|
|
81
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
78
|
none: false
|
|
83
|
-
requirements:
|
|
84
|
-
- -
|
|
85
|
-
- !ruby/object:Gem::Version
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
- 0
|
|
89
|
-
version: "0"
|
|
90
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ! '>='
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: 1.8.7
|
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
84
|
none: false
|
|
92
|
-
requirements:
|
|
93
|
-
- -
|
|
94
|
-
- !ruby/object:Gem::Version
|
|
95
|
-
|
|
96
|
-
segments:
|
|
97
|
-
- 0
|
|
98
|
-
version: "0"
|
|
85
|
+
requirements:
|
|
86
|
+
- - ! '>='
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: 1.3.6
|
|
99
89
|
requirements: []
|
|
100
|
-
|
|
101
90
|
rubyforge_project:
|
|
102
|
-
rubygems_version: 1.
|
|
91
|
+
rubygems_version: 1.8.10
|
|
103
92
|
signing_key:
|
|
104
93
|
specification_version: 3
|
|
105
|
-
summary: Simple, internationalized and DRY page titles and headings for
|
|
106
|
-
test_files:
|
|
94
|
+
summary: Simple, internationalized and DRY page titles and headings for Rails.
|
|
95
|
+
test_files:
|
|
96
|
+
- test/en.yml
|
|
97
|
+
- test/en_wohaapp.yml
|
|
107
98
|
- test/multiple_formats_test.rb
|
|
108
99
|
- test/page_title_helper_test.rb
|
|
109
100
|
- test/test_helper.rb
|