page_title_helper 2.1.0 → 3.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eaf4875e42896ac4021c8469718d914bcacfe096
4
+ data.tar.gz: f1e3fe136f672664c97c08948834a7c8bda199f1
5
+ SHA512:
6
+ metadata.gz: ee336f599ff2d0bf6f2ab1699037ea22ac9ff7da9315f3a219e2a04ec1cf477c1c98589c0a638c66b7bcb8720213970c5024fb583ef683be267bb3e6dd5dfddf
7
+ data.tar.gz: d246357b274f769704ee093cf91d94297e6499d266dfcb547dada9329c81819b451529c4a9b3b886b03bf86e182f233e525d0765dfc071a7a1a76bbf1ca90a09
data/CHANGELOG.md ADDED
@@ -0,0 +1,73 @@
1
+ # Page title helper change log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ This project adheres to [Semantic Versioning](http://semver.org/).
5
+
6
+ Read more at [Keep a CHANGELOG](http://keepachangelog.com/en/0.3.0/)
7
+ about why a change log is important.
8
+
9
+
10
+ ## 3.0.0 [unreleased]
11
+
12
+ ### Added
13
+ - Add Ruby 2.4.0 to the build matrix
14
+ ([#68](https://github.com/lwe/page_title_helper/pull/68))
15
+ - Add a CHANGELOG.md
16
+ ([#59](https://github.com/lwe/page_title_helper/pull/59))
17
+ - Add RuboCop checking to the CI
18
+ ([#52](https://github.com/lwe/page_title_helper/pull/52))
19
+ - Add a CODE_OF_CONDUCT.md
20
+ ([#51](https://github.com/lwe/page_title_helper/pull/51))
21
+ - Update Ruby to 2.3.3 and 2.2.6 on Travis
22
+ ([#38](https://github.com/lwe/page_title_helper/pull/38))
23
+ - Add Ruby 2.3.0 to the build matrix
24
+ - Re-add Ruby 2.0.0 to the build matrix
25
+ ([#29](https://github.com/lwe/page_title_helper/pull/29))
26
+ - Test against Ruby 2.2
27
+ - Use Appraisal for building with different Rails versions
28
+ ([#19](https://github.com/lwe/page_title_helper/pull/19))
29
+
30
+
31
+ ### Changed
32
+ - Replaced Appraisals with specific Gemfiles
33
+ ([#41](https://github.com/lwe/page_title_helper/pull/41))
34
+ - Delete obsolete init.rb file
35
+ ([#61](https://github.com/lwe/page_title_helper/pull/61))
36
+ - Add Rails 5.0 to the build matrix
37
+ ([#42](https://github.com/lwe/page_title_helper/pull/42))
38
+ - Raise RVM and Gem minimum versions
39
+ ([#3](https://github.com/lwe/page_title_helper/pull/3))
40
+
41
+
42
+ ### Deprecated
43
+
44
+
45
+ ### Removed
46
+ - Drop support for Rails 3.2 and 4.0
47
+ ([#39](https://github.com/lwe/page_title_helper/pull/39))
48
+ - Drop support for Ruby 1.9.x
49
+ ([#24](https://github.com/lwe/page_title_helper/pull/24))
50
+
51
+
52
+ ### Fixed
53
+ - Fix @_page_title uninitialized warning
54
+ ([#62](https://github.com/lwe/page_title_helper/pull/62))
55
+ - Fix the Travis build on Ruby 2.3.3
56
+ ([#63](https://github.com/lwe/page_title_helper/pull/63))
57
+ - Do do not shell-out to `git` in Gemfile
58
+ ([#49](https://github.com/lwe/page_title_helper/pull/49))
59
+ - Get the tests to run in Rails 4.2 and 5.0
60
+ ([#40](https://github.com/lwe/page_title_helper/pull/40))
61
+ - Stop requiring version from the main class
62
+ ([#47](https://github.com/lwe/page_title_helper/pull/47))
63
+ - Allow the Rails 3.2 build to fail only with Ruby 2.2
64
+ ([#30](https://github.com/lwe/page_title_helper/pull/30))
65
+ - Allow Rails 3.2 builds to fail
66
+ ([#26](https://github.com/lwe/page_title_helper/pull/26))
67
+ - Configure Travis for better performance
68
+ ([#10](https://github.com/lwe/page_title_helper/pull/10))
69
+ - Remove Gemfile.lock
70
+ ([#1](https://github.com/lwe/page_title_helper/pull/1))
71
+
72
+
73
+ ### Security
@@ -0,0 +1,77 @@
1
+ # Contributor Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age,
8
+ body size, disability, ethnicity, gender identity and expression, level of
9
+ experience, nationality, personal appearance, race, religion, or sexual
10
+ identity and orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+
35
+ ## Our Responsibilities
36
+
37
+ Project maintainers are responsible for clarifying the standards of acceptable
38
+ behavior and are expected to take appropriate and fair corrective action in
39
+ response to any instances of unacceptable behavior.
40
+
41
+ Project maintainers have the right and responsibility to remove, edit, or
42
+ reject comments, commits, code, wiki edits, issues, and other contributions
43
+ that are not aligned to this Code of Conduct, or to ban temporarily or
44
+ permanently any contributor for other behaviors that they deem inappropriate,
45
+ threatening, offensive, or harmful.
46
+
47
+ ## Scope
48
+
49
+ This Code of Conduct applies both within project spaces and in public spaces
50
+ when an individual is representing the project or its community. Examples of
51
+ representing a project or community include using an official project e-mail
52
+ address, posting via an official social media account, or acting as an
53
+ appointed representative at an online or offline event. Representation of a
54
+ project may be further defined and clarified by project maintainers.
55
+
56
+ ## Enforcement
57
+
58
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
59
+ reported by contacting the project team at (lukas dot westermann at gmail dot com).
60
+ All complaints will be reviewed and investigated and will result in a response
61
+ that is deemed necessary and appropriate to the circumstances. The project team
62
+ is obligated to maintain confidentiality with regard to the reporter of an
63
+ incident. Further details of specific enforcement policies may be posted
64
+ separately.
65
+
66
+ Project maintainers who do not follow or enforce the Code of Conduct in good
67
+ faith may face temporary or permanent repercussions as determined by other
68
+ members of the project's leadership.
69
+
70
+ ## Attribution
71
+
72
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
73
+ version 1.4, available at
74
+ [http://contributor-covenant.org/version/1/4/][version].
75
+
76
+ [homepage]: http://contributor-covenant.org
77
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source "http://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
data/README.md CHANGED
@@ -1,26 +1,31 @@
1
1
  # Page title helper
2
2
 
3
- Ever wondered if there was an easier and DRY-way to set your page titles (and/or headings),
4
- introducing _page title helper_, a small Rails 3 view helper to inflect titles from controllers
5
- & actions.
3
+ [![Build Status](https://travis-ci.org/lwe/page_title_helper.svg?branch=master)](https://travis-ci.org/lwe/page_title_helper)
4
+ [![Gem Version](https://badge.fury.io/rb/page_title_helper.svg)](http://badge.fury.io/rb/page_title_helper)
5
+
6
+ This project adheres to [Semantic Versioning](http://semver.org/).
7
+
8
+
9
+ ## What does this gem do?
6
10
 
7
- **Note:** for Rails 2.x please use version 1.0.1: `gem install page_title_helper -v 1.0.1`, because
8
- the latest versions are no longer compatible with Rails 2.x.
11
+ Ever wondered if there was an easier and DRY-way to set your page titles (and/or headings),
12
+ introducing _page title helper_, a small view helper for Rails 4.2 and 5
13
+ to inflect titles from controllers and actions.
9
14
 
10
- In your layout add this to your `<head>`-section:
15
+ In your layout, add this to your `<head>`-section:
11
16
 
12
17
  ...
13
18
  <title><%= page_title %></title>
14
19
  ...
15
-
20
+
16
21
  That's it. Now just add translations, in e.g. `config/locales/en.yml`:
17
22
 
18
23
  en:
19
24
  contacts:
20
25
  index:
21
26
  title: "Contacts"
22
-
23
- When `/contacs/` is requested, the key `:en, :contacts, :index, :title`
27
+
28
+ When `/contacts/` is requested, the key `:en, :contacts, :index, :title`
24
29
  is looked up and printed, together with the applications basename, like: `Contacts - My cool App`.
25
30
  The format etc. is of course configurable, just head down to the options.
26
31
 
@@ -30,13 +35,9 @@ As gem (from rubygems.org):
30
35
 
31
36
  # then add the following line to Gemfile
32
37
  gem 'page_title_helper'
33
-
34
- # living on the bleeding edge?
35
- gem 'page_title_helper', :git => 'git://github.com/lwe/page_title_helper.git'
36
-
37
- or as plain old Rails plugin:
38
38
 
39
- rails plugin install git://github.com/lwe/page_title_helper.git
39
+ # living on the bleeding edge?
40
+ gem 'page_title_helper', git: 'git://github.com/lwe/page_title_helper.git'
40
41
 
41
42
  ## Translated titles
42
43
 
@@ -57,13 +58,13 @@ Need a custom title, or need to fill in some placeholders? Just use the _bang_ m
57
58
  `<title>-tag`as well as in the heading?
58
59
 
59
60
  <h1><%= page_title!(@contact.name) %></h1>
60
-
61
+
61
62
  A call to `page_title` will now return the contacts name, neat :) if for example the
62
63
  `<h1>` does not match the `<title>`, then well, just do something like:
63
64
 
64
65
  <% page_title!(@contact.name + " (" + @contact.company.name + ")") %>
65
66
  <h1><%= @contact.name %></h1>
66
-
67
+
67
68
  Guess, that's it. Of course it's also possible to use `translate` within `page_title!`, to
68
69
  translate custom titles, like:
69
70
 
@@ -74,47 +75,47 @@ translate custom titles, like:
74
75
  title: "Welcome back, {{name}}"
75
76
 
76
77
  # in app/views/dashboard/index.html.erb:
77
- <h1><%= page_title!(t('.title', :name => @user.first_name)) %></h1>
78
+ <h1><%= page_title!(t('.title', name: @user.first_name)) %></h1>
78
79
 
79
80
  ## More fun with <tt>:format</tt>
80
81
 
81
82
  The `:format` option is used to specify how a title is formatted, i.e. if the app name is
82
- prependor appended, or if it contains the account name etc. It uses a similar approach as
83
+ prepended or appended or if it contains the account name etc. It uses a similar approach as
83
84
  paperclip's path interpolations:
84
85
 
85
- page_title :format => ':title / :app' # => "Contacts / My cool app"
86
-
86
+ page_title format: ':title / :app' # => "Contacts / My cool app"
87
+
87
88
  Adding custom interpolations is as easy as defining a block, for example to access the current
88
89
  controller:
89
90
 
90
91
  PageTitleHelper.interpolates :controller do |env|
91
92
  env[:view].controller.controller_name.humanize
92
93
  end
93
-
94
- page_title :format => ':title / :controller / :app' # => "Welcome back / Dashboard / My cool app"
95
-
94
+
95
+ page_title format: ':title / :controller / :app' # => "Welcome back / Dashboard / My cool app"
96
+
96
97
  To access just the title, without any magic app stuff interpolated or appended, use:
97
98
 
98
99
  page_title! "untitled"
99
- page_title :format => false # => "untitled"
100
-
100
+ page_title format: false # => "untitled"
101
+
101
102
  Need a custom format for a single title? Just return an array:
102
103
 
103
104
  # in the view:
104
105
  <h1><%= page_title!(@contact.name, ":title from :company - :app") %></h1> # => <h1>Franz Meyer</h1>
105
-
106
+
106
107
  # in the <head>
107
108
  <title><%= page_title %></title> # => this time it will use custom title like "Franz Meyer from ABC Corp. - My cool app"
108
-
109
+
109
110
  To streamline that feature a bit and simplify reuse of often used formats, it's possible to define format aliases like:
110
111
 
111
112
  # in an initializer, e.g. config/initializers/page_title_helper.rb:
112
113
  PageTitleHelper.formats[:with_company] = ":title from :company - :app"
113
114
  PageTitleHelper.formats[:promo] = ":app - :title" # show app first for promo pages :)
114
-
115
+
115
116
  # then in the view to display a contact...
116
117
  page_title! @contact.name, :with_company
117
-
118
+
118
119
  # ...or for the promo page via config/locales/en.yml (!)
119
120
  en:
120
121
  pages:
@@ -123,7 +124,7 @@ To streamline that feature a bit and simplify reuse of often used formats, it's
123
124
  - "Features comparison"
124
125
  - !ruby/sym promo
125
126
 
126
- Pretty, cool, aint it? The special `:format => :app` works also via the `formats` hash. Then there is also a
127
+ Pretty, cool, ain't it? The special `format: :app` works also via the `formats` hash. Then there is also a
127
128
  `:default` format, which can be used to override the default format.
128
129
 
129
130
  ## All options - explained
@@ -165,10 +166,10 @@ To add or change formats use:
165
166
 
166
167
  # change the default format used (if no format is specified):
167
168
  PageTitleHelper.formats[:default] = ":title // :app"
168
-
169
- # add a custom format alias (which can be used with page_title(:format => :promo))
169
+
170
+ # add a custom format alias (which can be used with page_title(format: :promo))
170
171
  PageTitleHelper.formats[:promo] = ":app // :title"
171
-
172
+
172
173
  _Note:_ it's recommended to add this kind of stuff to an initializer, like e.g.
173
174
  `config/initializers/page_title_helper.rb`.
174
175
 
@@ -178,10 +179,24 @@ The internationalized controller name, with fallback to just display the humaniz
178
179
 
179
180
  PageTitleHelper.interpolates :controller do |env|
180
181
  c = env[:view].controller
181
- I18n.t(c.controller_path.tr('/', '.') + '.controller', :default => c.controller_name.humanize)
182
+ I18n.t(c.controller_path.tr('/', '.') + '.controller', default: c.controller_name.humanize)
182
183
  end
183
-
184
- _Note:_ Put this kind of stuff into an initializer, like `config/initializers/page_title_helper.rb` or someting like that.
185
-
184
+
185
+ _Note:_ Put this kind of stuff into an initializer, like `config/initializers/page_title_helper.rb` or something like that.
186
+
187
+
188
+ ## Contributing
189
+
190
+ Pull request are more than welcome. Please adhere to our
191
+ [CODE_OF_CONDUCT.md](code of conduct) in discussions and contributions.
192
+ Thanks!
193
+
194
+
195
+ ## Maintainers
196
+
197
+ * [@lwe - Lukas Westermann](https://github.com/lwe)
198
+ * [@oliverklee - Oliver Klee](https://github.com/oliverklee)
199
+
200
+
186
201
  ## Licence and copyright
187
202
  Copyright (c) 2009 Lukas Westermann (Zurich, Switzerland), released under the MIT license
data/Rakefile CHANGED
@@ -1,4 +1,3 @@
1
- require 'rubygems'
2
1
  require 'bundler/setup'
3
2
  require 'rake/testtask'
4
3
 
@@ -7,7 +6,7 @@ include Rake::DSL
7
6
  Bundler::GemHelper.install_tasks
8
7
 
9
8
  desc 'Default: run unit tests.'
10
- task :default => :test
9
+ task default: :test
11
10
 
12
11
  desc 'Test the page_title_helper plugin.'
13
12
  Rake::TestTask.new(:test) do |t|
@@ -1,3 +1,3 @@
1
1
  module PageTitleHelper
2
- VERSION = "2.1.0"
3
- end
2
+ VERSION = '3.0.0'.freeze
3
+ end
@@ -7,25 +7,23 @@
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'
11
10
 
12
11
  # PageTitleHelper
13
12
  module PageTitleHelper
14
-
15
13
  # http://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/interpolations.rb
16
14
  module Interpolations
17
15
  extend self
18
16
 
19
17
  def self.interpolate(pattern, *args)
20
18
  instance_methods(false).sort.reverse.inject(pattern.to_s.dup) do |result, tag|
21
- result.gsub(/:#{tag}/) do |match|
19
+ result.gsub(/:#{tag}/) do |_match|
22
20
  send(tag, *args)
23
21
  end
24
22
  end
25
23
  end
26
24
 
27
25
  def app(env)
28
- env[:app] || I18n.translate(:'app.name', :default => File.basename(Rails.root).humanize)
26
+ env[:app] || I18n.translate('app.name', default: File.basename(Rails.root).humanize)
29
27
  end
30
28
 
31
29
  def title(env)
@@ -42,17 +40,17 @@ module PageTitleHelper
42
40
  # be changed globally, which might be useful in some cases.
43
41
  def self.options
44
42
  @options ||= {
45
- :format => :default,
46
- :default => :'app.tagline'
43
+ format: :default,
44
+ default: :'app.tagline'
47
45
  }
48
46
  end
49
47
 
50
48
  # Defined alias formats, pretty useful.
51
49
  def self.formats
52
50
  @formats ||= {
53
- :app => ":app",
54
- :default => ':title - :app',
55
- :title => ":title"
51
+ app: ':app',
52
+ default: ':title - :app',
53
+ title: ':title'
56
54
  }
57
55
  end
58
56
 
@@ -62,7 +60,7 @@ module PageTitleHelper
62
60
  @_page_title.is_a?(Array) ? @_page_title.first : @_page_title
63
61
  end
64
62
 
65
- def page_title(options = nil, &block)
63
+ def page_title(options = nil)
66
64
  return page_title!(yield) if block_given? # define title
67
65
 
68
66
  options = PageTitleHelper.options.merge(options || {}).symbolize_keys!
@@ -70,7 +68,7 @@ module PageTitleHelper
70
68
  options.assert_valid_keys(:app, :default, :format)
71
69
 
72
70
  # read page title and split into 'real' title and customized format
73
- title = @_page_title || page_title_from_translation(options[:default])
71
+ title = @_page_title ||= page_title_from_translation(options[:default])
74
72
  title, options[:format] = *(title << options[:format]) if title.is_a?(Array)
75
73
 
76
74
  # handle format aliases
@@ -78,7 +76,7 @@ module PageTitleHelper
78
76
  format = PageTitleHelper.formats[format] if PageTitleHelper.formats.include?(format)
79
77
 
80
78
  # construct basic env to pass around
81
- env = { :title => title, :app => options.delete(:app), :options => options, :view => self }
79
+ env = { title: title, app: options.delete(:app), options: options, view: self }
82
80
 
83
81
  # interpolate format
84
82
  Interpolations.interpolate(format, env)
@@ -98,7 +96,7 @@ module PageTitleHelper
98
96
  keys << :"#{base}.title"
99
97
  keys << default
100
98
 
101
- I18n.translate(keys.shift, :default => keys)
99
+ I18n.translate(keys.shift, default: keys)
102
100
  end
103
101
  end
104
102
 
@@ -1,28 +1,30 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "page_title_helper/version"
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'page_title_helper/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "page_title_helper"
6
+ s.name = 'page_title_helper'
7
7
  s.version = PageTitleHelper::VERSION
8
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."
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
11
 
12
- s.required_ruby_version = ">= 1.8.7"
13
- s.required_rubygems_version = ">= 1.3.6"
12
+ s.required_ruby_version = '>= 2.0.0'
13
+ s.required_rubygems_version = '>= 1.3.6'
14
14
 
15
- s.authors = ["Lukas Westermann"]
16
- s.email = ["lukas.westermann@gmail.com"]
17
- s.homepage = "http://github.com/lwe/page_title_helper"
15
+ s.authors = ['Lukas Westermann']
16
+ s.email = ['lukas.westermann@gmail.com']
17
+ s.homepage = 'http://github.com/lwe/page_title_helper'
18
18
 
19
- s.files = `git ls-files`.split("\n")
20
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.files = %w{Gemfile LICENSE README.md CODE_OF_CONDUCT.md CHANGELOG.md Rakefile page_title_helper.gemspec} + Dir['**/*.{rb,yml}']
20
+ s.test_files = s.files.grep(%r{^(test|spec)/})
21
21
  s.require_path = 'lib'
22
22
 
23
23
  s.license = 'MIT'
24
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'
25
+ s.add_dependency 'rails', '>= 4.2.0', '< 6.0'
26
+
27
+ s.add_development_dependency 'rake', '>= 10.3.2'
28
+ s.add_development_dependency 'shoulda'
29
+ s.add_development_dependency 'rubocop', '~> 0.49.0'
28
30
  end
@@ -1,71 +1,71 @@
1
+ require 'minitest/autorun'
1
2
  require 'test_helper'
2
- require 'page_title_helper'
3
3
 
4
4
  class MultipleFormatsTest < ActiveSupport::TestCase
5
- context "#page_title supporting multiple formats through arrays" do
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
- should "accept an array passed in the page_title block and use the second argument as format" do
11
- @view.page_title { ["Oh my...!", ":title // :app"] }
12
- assert_equal "Oh my...! // Page title helper", @view.page_title
10
+ should 'accept an array passed in the page_title block and use the second argument as format' do
11
+ @view.page_title { ['Oh my...!', ':title // :app'] }
12
+ assert_equal 'Oh my...! // Page title helper', @view.page_title
13
13
  end
14
14
 
15
- should "still return title as string and not the array" do
16
- assert_equal "Oh my...!", @view.page_title { ["Oh my...!", ":title // :app"] }
15
+ should 'still return title as string and not the array' do
16
+ assert_equal('Oh my...!', @view.page_title { ['Oh my...!', ':title // :app'] })
17
17
  end
18
18
  end
19
19
 
20
- context "#page_title with format aliases" do
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
24
  end
25
25
 
26
- should "have a default alias named :app" do
27
- assert_equal "Page title helper", @view.page_title(:format => :app)
26
+ should 'have a default alias named :app' do
27
+ assert_equal 'Page title helper', @view.page_title(format: :app)
28
28
  end
29
29
 
30
- should "allow custom aliases to be defined and used" do
31
- @view.page_title { "Test" }
32
- assert_equal "Test <-> Page title helper", @view.page_title(:format => :myformat)
30
+ should 'allow custom aliases to be defined and used' do
31
+ @view.page_title { 'Test' }
32
+ assert_equal 'Test <-> Page title helper', @view.page_title(format: :myformat)
33
33
  end
34
34
 
35
- should "fallback to default format, if array is not big enough (i.e. only contains single element...)" do
36
- assert_equal "Test", @view.page_title { ["Test"] }
37
- assert_equal "Test - Page title helper", @view.page_title
35
+ should 'fallback to default format, if array is not big enough (i.e. only contains single element...)' do
36
+ assert_equal('Test', @view.page_title { ['Test'] })
37
+ assert_equal 'Test - Page title helper', @view.page_title
38
38
  end
39
39
 
40
- context "used with the array block" do
41
- should "also allow aliases returned in that array thingy" do
42
- assert_equal "Test", @view.page_title { ["Test", :myformat] }
43
- assert_equal "Test <-> Page title helper", @view.page_title
40
+ context 'used with the array block' do
41
+ should 'also allow aliases returned in that array thingy' do
42
+ assert_equal('Test', @view.page_title { ['Test', :myformat] })
43
+ assert_equal 'Test <-> Page title helper', @view.page_title
44
44
  end
45
45
 
46
- should "override locally supplied :format arguments" do
47
- assert_equal "Something", @view.page_title { ["Something", "* * * :title * * *"] }
48
- assert_equal "* * * Something * * *", @view.page_title(:format => "-= :title =-") # yeah, using x-tra ugly titles :)
46
+ should 'override locally supplied :format arguments' do
47
+ assert_equal('Something', @view.page_title { ['Something', '* * * :title * * *'] })
48
+ assert_equal '* * * Something * * *', @view.page_title(format: '-= :title =-') # yeah, using x-tra ugly titles :)
49
49
  end
50
50
  end
51
51
  end
52
52
 
53
- context "#page_title, aliases and YAML" do
53
+ context '#page_title, aliases and YAML' do
54
54
  setup do
55
- I18n.load_path = [File.join(File.dirname(__FILE__), "en_wohaapp.yml")]
55
+ I18n.load_path = [File.join(File.dirname(__FILE__), 'en_wohaapp.yml')]
56
56
  I18n.reload!
57
- PageTitleHelper.formats[:promo] = ":app > :title"
57
+ PageTitleHelper.formats[:promo] = ':app > :title'
58
58
  @view = TestView.new
59
59
  end
60
60
 
61
- should "allow to overide format through YAML" do
61
+ should 'allow to overide format through YAML' do
62
62
  @view.controller! 'pages', 'features'
63
63
  assert_equal 'Wohaapp > Feature comparison', @view.page_title
64
64
  end
65
65
 
66
- should "handle raw string formats from YAML as well" do
66
+ should 'handle raw string formats from YAML as well' do
67
67
  @view.controller! 'pages', 'signup'
68
68
  assert_equal 'Sign up for Wohaapp now!', @view.page_title
69
69
  end
70
70
  end
71
- end
71
+ end
@@ -1,9 +1,8 @@
1
+ require 'minitest/autorun'
1
2
  require 'test_helper'
2
- require 'page_title_helper'
3
- require 'ostruct'
4
3
 
5
4
  class PageTitleHelperTest < ActiveSupport::TestCase
6
- context "PageTitleHelper" do
5
+ context 'PageTitleHelper' do
7
6
  setup do
8
7
  I18n.load_path = [File.join(File.dirname(__FILE__), 'en.yml')]
9
8
  I18n.reload!
@@ -11,123 +10,123 @@ class PageTitleHelperTest < ActiveSupport::TestCase
11
10
  @view = TestView.new('contacts', 'list')
12
11
  end
13
12
 
14
- context "::Interpolations" do
15
- should "interpolate :app and :title" do
13
+ context '::Interpolations' do
14
+ should 'interpolate :app and :title' do
16
15
  assert_equal 'Page title helper', PageTitleHelper::Interpolations.app({})
17
- assert_equal 'Appname', PageTitleHelper::Interpolations.app({ :app => 'Appname' })
18
- assert_equal 'untitled', PageTitleHelper::Interpolations.title({:title => 'untitled'})
16
+ assert_equal 'Appname', PageTitleHelper::Interpolations.app(app: 'Appname')
17
+ assert_equal 'untitled', PageTitleHelper::Interpolations.title(title: 'untitled')
19
18
  end
20
19
 
21
- should "allow adding custom interpolations" do
20
+ should 'allow adding custom interpolations' do
22
21
  # extend Interpolations
23
22
  PageTitleHelper.interpolates(:app_reverse) { |env| app(env).reverse.downcase }
24
23
 
25
- assert_equal "anna", PageTitleHelper::Interpolations.app_reverse({ :app => 'Anna' })
26
- assert_equal "ppa", PageTitleHelper::Interpolations.interpolate(':app_reverse', { :app => 'app' })
24
+ assert_equal 'anna', PageTitleHelper::Interpolations.app_reverse(app: 'Anna')
25
+ assert_equal 'ppa', PageTitleHelper::Interpolations.interpolate(':app_reverse', app: 'app')
27
26
  end
28
27
 
29
- should "interpolate in correct order, i.e. longest first" do
30
- PageTitleHelper.interpolates(:foobar) { |env| "foobar" }
31
- PageTitleHelper.interpolates(:foobar_test) { |env| "foobar_test" }
32
- PageTitleHelper.interpolates(:title_foobar) { |env| "title_foobar" }
28
+ should 'interpolate in correct order, i.e. longest first' do
29
+ PageTitleHelper.interpolates(:foobar) { |_env| 'foobar' }
30
+ PageTitleHelper.interpolates(:foobar_test) { |_env| 'foobar_test' }
31
+ PageTitleHelper.interpolates(:title_foobar) { |_env| 'title_foobar' }
33
32
 
34
- assert_equal "title_foobar / foobar_test / foobar / foobar_x", PageTitleHelper::Interpolations.interpolate(":title_foobar / :foobar_test / :foobar / :foobar_x", {})
33
+ assert_equal 'title_foobar / foobar_test / foobar / foobar_x', PageTitleHelper::Interpolations.interpolate(':title_foobar / :foobar_test / :foobar / :foobar_x', {})
35
34
  end
36
35
  end
37
36
 
38
- context "#page_title (define w/ block)" do
39
- should "return title from block and render with app name" do
40
- assert_equal 'foo', @view.page_title { "foo" }
37
+ context '#page_title (define w/ block)' do
38
+ should 'return title from block and render with app name' do
39
+ assert_equal('foo', @view.page_title { 'foo' })
41
40
  assert_equal 'foo - Page title helper', @view.page_title
42
41
  end
43
42
 
44
- should "set custom title using a translation with a placeholder" do
45
- assert_equal "Displaying Bella", @view.page_title { I18n.t(:placeholder, :name => 'Bella') }
46
- assert_equal "Displaying Bella - Page title helper", @view.page_title
43
+ should 'set custom title using a translation with a placeholder' do
44
+ assert_equal('Displaying Bella', @view.page_title { I18n.t(:placeholder, name: 'Bella') })
45
+ assert_equal 'Displaying Bella - Page title helper', @view.page_title
47
46
  end
48
47
  end
49
48
 
50
- context "#page_title! (define)" do
51
- should "set page title" do
49
+ context '#page_title! (define)' do
50
+ should 'set page title' do
52
51
  assert_equal 'test', @view.page_title!('test')
53
52
  assert_equal 'test - Page title helper', @view.page_title
54
53
  end
55
54
 
56
- should "set page title and interpret second argument as custom format" do
57
- PageTitleHelper.formats[:bang] = ":title !! :app"
55
+ should 'set page title and interpret second argument as custom format' do
56
+ PageTitleHelper.formats[:bang] = ':title !! :app'
58
57
  assert_equal 'test', @view.page_title!('test', :bang)
59
58
  assert_equal 'test !! Page title helper', @view.page_title
60
59
  end
61
60
  end
62
61
 
63
- context "#page_title (rendering)" do
64
- should "read default title from I18n, based on controller/action" do
62
+ context '#page_title (rendering)' do
63
+ should 'read default title from I18n, based on controller/action' do
65
64
  assert_equal 'contacts.list.title - Page title helper', @view.page_title
66
65
  end
67
66
 
68
- should "only print app name if :format => :app" do
69
- assert_equal 'Page title helper', @view.page_title(:format => :app)
67
+ should 'only print app name if format: :app' do
68
+ assert_equal 'Page title helper', @view.page_title(format: :app)
70
69
  end
71
70
 
72
- should "print custom app name if :app defined and :format => :app" do
73
- assert_equal "Some app", @view.page_title(:app => 'Some app', :format => :app)
71
+ should 'print custom app name if :app defined and format: :app' do
72
+ assert_equal 'Some app', @view.page_title(app: 'Some app', format: :app)
74
73
  end
75
74
 
76
- should "use custom format, if :format option is defined" do
77
- assert_equal 'test', @view.page_title { "test" }
78
- assert_equal "Some app :: test", @view.page_title(:app => "Some app", :format => ':app :: :title')
79
- assert_equal "Some app / test", @view.page_title(:format => 'Some app / :title')
75
+ should 'use custom format, if :format option is defined' do
76
+ assert_equal('test', @view.page_title { 'test' })
77
+ assert_equal 'Some app :: test', @view.page_title(app: 'Some app', format: ':app :: :title')
78
+ assert_equal 'Some app / test', @view.page_title(format: 'Some app / :title')
80
79
  end
81
80
 
82
- should "return just title if :format => false is passed" do
83
- assert_equal 'untitled', @view.page_title { "untitled" }
84
- assert_equal "untitled", @view.page_title(:format => false)
81
+ should 'return just title if format: false is passed' do
82
+ assert_equal('untitled', @view.page_title { 'untitled' })
83
+ assert_equal 'untitled', @view.page_title(format: false)
85
84
  end
86
85
 
87
- should "return title if :format => false and when using the DRY-I18n titles" do
88
- assert_equal "contacts.list.title", @view.page_title(:format => false)
86
+ should 'return title if format: false and when using the DRY-I18n titles' do
87
+ assert_equal 'contacts.list.title', @view.page_title(format: false)
89
88
  end
90
89
 
91
- should "render translated :'app.tagline' if no title is available" do
90
+ should 'render translated :"app.tagline" if no title is available' do
92
91
  @view.controller! 'view/does', 'not_exist'
93
- assert_equal "Default - Page title helper", @view.page_title
92
+ assert_equal 'Default - Page title helper', @view.page_title
94
93
  end
95
94
 
96
- should "render use controller.title as first fallback, if no title exists" do
95
+ should 'render use controller.title as first fallback, if no title exists' do
97
96
  @view.controller! 'admin/account', 'index'
98
- assert_equal 'Account administration - Page title helper', @view.page_title(:default => 'Other default')
97
+ assert_equal 'Account administration - Page title helper', @view.page_title(default: 'Other default')
99
98
  end
100
99
 
101
- should "not fallback to controller.title if controller.action.title exists" do
100
+ should 'not fallback to controller.title if controller.action.title exists' do
102
101
  @view.controller! 'admin/account', 'show'
103
- assert_equal 'Account - Page title helper', @view.page_title(:default => 'Other default')
102
+ assert_equal 'Account - Page title helper', @view.page_title(default: 'Other default')
104
103
  end
105
104
 
106
105
  should 'fallback to controller.new.title if create has no title' do
107
106
  @view.controller! 'admin/account', 'create'
108
- assert_equal 'New account - Page title helper', @view.page_title(:default => 'Other default')
107
+ assert_equal 'New account - Page title helper', @view.page_title(default: 'Other default')
109
108
  end
110
109
 
111
110
  should 'fallback to controller.edit.title if update has no title' do
112
111
  @view.controller! 'admin/account', 'update'
113
- assert_equal 'Edit account - Page title helper', @view.page_title(:default => 'Other default')
112
+ assert_equal 'Edit account - Page title helper', @view.page_title(default: 'Other default')
114
113
  end
115
114
 
116
- should "render custom 'default' string, if title is not available nor controller.title" do
115
+ should 'render custom "default" string, if title is not available nor controller.title' do
117
116
  @view.controller! 'view/does', 'not_exist'
118
- assert_equal 'Some default - Page title helper', @view.page_title(:default => 'Some default')
117
+ assert_equal 'Some default - Page title helper', @view.page_title(default: 'Some default')
119
118
  end
120
119
 
121
- should "render custom default translation, if title is not available nor controller.title" do
120
+ should 'render custom default translation, if title is not available nor controller.title' do
122
121
  @view.controller! 'view/does', 'not_exist'
123
- assert_equal 'Other default - Page title helper', @view.page_title(:default => :'app.other_tagline')
122
+ assert_equal 'Other default - Page title helper', @view.page_title(default: :'app.other_tagline')
124
123
  end
125
124
  end
126
125
 
127
- context "README.md" do
128
- should "interpolate :controller" do
126
+ context 'README.md' do
127
+ should 'interpolate :controller' do
129
128
  PageTitleHelper.interpolates(:controller) { |env| env[:view].controller.controller_name.humanize }
130
- assert_equal "contacts.list.title - Test", @view.page_title(:format => ":title - :controller")
129
+ assert_equal 'contacts.list.title - Test', @view.page_title(format: ':title - :controller')
131
130
  end
132
131
  end
133
132
  end
data/test/test_helper.rb CHANGED
@@ -1,34 +1,41 @@
1
- require 'rubygems'
2
1
  require 'active_support'
3
2
  require 'action_view'
4
- require File.join(File.dirname(__FILE__), '..', 'init')
3
+ require 'page_title_helper'
5
4
 
6
5
  unless defined?(IRB)
7
6
  require 'active_support/test_case'
8
7
  require 'shoulda'
9
8
  end
10
9
 
11
- # fake global rails object
12
- Rails = Object.new
13
- Rails.class_eval do
14
- def root; @pathname ||= Pathname.new('/this/is/just/for/testing/page_title_helper') end
15
- def env; "test" end
10
+ # Use sorted tests. We need to change that after the tests have been converted
11
+ # to RSpec.
12
+ ActiveSupport.test_order = :sorted
13
+
14
+ # fake global Rails module
15
+ module Rails
16
+ class << self
17
+ def root
18
+ @pathname ||= Pathname.new('/this/is/just/for/testing/page_title_helper')
19
+ end
20
+
21
+ def env
22
+ 'test'
23
+ end
24
+ end
16
25
  end
17
26
 
18
27
  # Mock ActionView a bit to allow easy (fake) template assignment
19
28
  class TestView < ActionView::Base
29
+ attr_reader :controller
30
+
20
31
  def initialize(controller_path = nil, action = nil)
21
32
  @controller = ActionView::TestCase::TestController.new
22
33
  @controller.controller_path = controller_path
23
- self.params[:action] = action if action
34
+ params[:action] = action if action
24
35
  end
25
36
 
26
37
  def controller!(controller_path, action)
27
38
  @controller.controller_path = controller_path
28
- self.params[:action] = action
39
+ params[:action] = action
29
40
  end
30
-
31
- def controller
32
- @controller
33
- end
34
- end
41
+ end
metadata CHANGED
@@ -1,64 +1,90 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: page_title_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
5
- prerelease:
4
+ version: 3.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Lukas Westermann
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-04-11 00:00:00.000000000 Z
11
+ date: 2018-03-11 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
16
- requirement: &70160540680580 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
- version: 3.0.0
19
+ version: 4.2.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6.0'
22
23
  type: :runtime
23
24
  prerelease: false
24
- version_requirements: *70160540680580
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 4.2.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6.0'
25
33
  - !ruby/object:Gem::Dependency
26
34
  name: rake
27
- requirement: &70160540680020 !ruby/object:Gem::Requirement
28
- none: false
35
+ requirement: !ruby/object:Gem::Requirement
29
36
  requirements:
30
- - - ! '>='
37
+ - - ">="
31
38
  - !ruby/object:Gem::Version
32
- version: 0.9.2
39
+ version: 10.3.2
33
40
  type: :development
34
41
  prerelease: false
35
- version_requirements: *70160540680020
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 10.3.2
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: shoulda
38
- requirement: &70160540679400 !ruby/object:Gem::Requirement
39
- none: false
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
40
57
  requirements:
41
- - - ! '>='
58
+ - - ">="
42
59
  - !ruby/object:Gem::Version
43
60
  version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rubocop
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.49.0
44
68
  type: :development
45
69
  prerelease: false
46
- version_requirements: *70160540679400
47
- description: Simple, internationalized and DRY page titles and headings for rails.
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.49.0
75
+ description: Simple, internationalized and DRY page titles and headings for Rails.
48
76
  email:
49
77
  - lukas.westermann@gmail.com
50
78
  executables: []
51
79
  extensions: []
52
80
  extra_rdoc_files: []
53
81
  files:
54
- - .gitignore
55
- - .travis.yml
82
+ - CHANGELOG.md
83
+ - CODE_OF_CONDUCT.md
56
84
  - Gemfile
57
- - Gemfile.lock
58
85
  - LICENSE
59
86
  - README.md
60
87
  - Rakefile
61
- - init.rb
62
88
  - lib/page_title_helper.rb
63
89
  - lib/page_title_helper/version.rb
64
90
  - page_title_helper.gemspec
@@ -70,27 +96,26 @@ files:
70
96
  homepage: http://github.com/lwe/page_title_helper
71
97
  licenses:
72
98
  - MIT
99
+ metadata: {}
73
100
  post_install_message:
74
101
  rdoc_options: []
75
102
  require_paths:
76
103
  - lib
77
104
  required_ruby_version: !ruby/object:Gem::Requirement
78
- none: false
79
105
  requirements:
80
- - - ! '>='
106
+ - - ">="
81
107
  - !ruby/object:Gem::Version
82
- version: 1.8.7
108
+ version: 2.0.0
83
109
  required_rubygems_version: !ruby/object:Gem::Requirement
84
- none: false
85
110
  requirements:
86
- - - ! '>='
111
+ - - ">="
87
112
  - !ruby/object:Gem::Version
88
113
  version: 1.3.6
89
114
  requirements: []
90
115
  rubyforge_project:
91
- rubygems_version: 1.8.10
116
+ rubygems_version: 2.6.13
92
117
  signing_key:
93
- specification_version: 3
118
+ specification_version: 4
94
119
  summary: Simple, internationalized and DRY page titles and headings for Rails.
95
120
  test_files:
96
121
  - test/en.yml
data/.gitignore DELETED
@@ -1,3 +0,0 @@
1
- doc/
2
- pkg/
3
- .yardoc
data/.travis.yml DELETED
@@ -1,4 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.8.7
4
- - 1.9.3
data/Gemfile.lock DELETED
@@ -1,98 +0,0 @@
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/init.rb DELETED
@@ -1 +0,0 @@
1
- require 'page_title_helper'