middleman-title 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8890ac07e237420852ff05324a82f3b437eb00f4
4
+ data.tar.gz: ca350f34ed2c92bfaaaf26118b9c9d79d438fd18
5
+ SHA512:
6
+ metadata.gz: cafb5818c7b23d812ae006102612d9a2822f587924b65c2505d908d3dda7b7ba7189be29917850c69a262ad94a9d246f337404de0d2dda9e5f9b5ed02ff368f9
7
+ data.tar.gz: d09d8e9543b8a1b56fe0f353bf8c4c518f026f21ea2b7d1d4297c76ee52440dd885a505ed56c9ad841de3432d529137eaead0e5879aec0046216920624ec2a46
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - 2.1.0
5
+
6
+ script: 'bundle exec rspec'
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,76 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ middleman-title (0.0.1)
5
+ middleman-core (~> 3.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (4.0.5)
11
+ i18n (~> 0.6, >= 0.6.9)
12
+ minitest (~> 4.2)
13
+ multi_json (~> 1.3)
14
+ thread_safe (~> 0.1)
15
+ tzinfo (~> 0.3.37)
16
+ diff-lcs (1.2.5)
17
+ erubis (2.7.0)
18
+ ffi (1.9.3)
19
+ hooks (0.4.0)
20
+ uber (~> 0.0.4)
21
+ i18n (0.6.9)
22
+ listen (1.3.1)
23
+ rb-fsevent (>= 0.9.3)
24
+ rb-inotify (>= 0.9)
25
+ rb-kqueue (>= 0.2)
26
+ middleman-core (3.3.2)
27
+ activesupport (~> 4.0.1)
28
+ bundler (~> 1.1)
29
+ erubis
30
+ hooks (~> 0.3)
31
+ i18n (~> 0.6.9)
32
+ listen (~> 1.1)
33
+ padrino-helpers (~> 0.12.1)
34
+ rack (>= 1.4.5, < 2.0)
35
+ rack-test (~> 0.6.2)
36
+ thor (>= 0.15.2, < 2.0)
37
+ tilt (~> 1.4.1, < 2.0)
38
+ minitest (4.7.5)
39
+ multi_json (1.10.0)
40
+ padrino-helpers (0.12.2)
41
+ i18n (~> 0.6, >= 0.6.7)
42
+ padrino-support (= 0.12.2)
43
+ tilt (~> 1.4.1)
44
+ padrino-support (0.12.2)
45
+ activesupport (>= 3.1)
46
+ rack (1.5.2)
47
+ rack-test (0.6.2)
48
+ rack (>= 1.0)
49
+ rake (10.3.1)
50
+ rb-fsevent (0.9.4)
51
+ rb-inotify (0.9.4)
52
+ ffi (>= 0.5.0)
53
+ rb-kqueue (0.2.2)
54
+ ffi (>= 0.5.0)
55
+ rspec (2.14.1)
56
+ rspec-core (~> 2.14.0)
57
+ rspec-expectations (~> 2.14.0)
58
+ rspec-mocks (~> 2.14.0)
59
+ rspec-core (2.14.8)
60
+ rspec-expectations (2.14.5)
61
+ diff-lcs (>= 1.1.3, < 2.0)
62
+ rspec-mocks (2.14.6)
63
+ thor (0.19.1)
64
+ thread_safe (0.3.3)
65
+ tilt (1.4.1)
66
+ tzinfo (0.3.39)
67
+ uber (0.0.6)
68
+
69
+ PLATFORMS
70
+ ruby
71
+
72
+ DEPENDENCIES
73
+ bundler (~> 1.6)
74
+ middleman-title!
75
+ rake (~> 10.3, >= 10.3.1)
76
+ rspec (~> 2.14, >= 2.14.1)
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Justin Cypret
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,82 @@
1
+
2
+ # Middleman Title
3
+ [![Build Status](https://travis-ci.org/jcypret/middleman-title.svg?branch=master)](https://travis-ci.org/jcypret/middleman-title)
4
+
5
+ This Middleman extension allows you to easily set page titles for your website.
6
+
7
+ ## Setup
8
+ Add the following line to `Gemfile`, then run `bundle install`:
9
+
10
+ gem 'middleman-title'
11
+
12
+ After installation, activate the extension in `config.rb`:
13
+
14
+ activate :title, site: 'Your Website Name', separator: ' — '
15
+
16
+ *The separator is optional and will default to a dash.*
17
+
18
+
19
+ ## Setting Title and Adding to Layout
20
+
21
+ In your layout file, you can use the `page_title` helper to output the current page title:
22
+
23
+ <title><%= page_title %></title>
24
+
25
+ Then, add a page `title` to the Frontmatter any page:
26
+
27
+ ---
28
+ title: The title of this page goes here
29
+ ---
30
+
31
+ This would output:
32
+
33
+ The title of this page goes here — Your Website Name
34
+
35
+
36
+ ## Outputting Website Name First
37
+
38
+ Sometimes it is desirable to put the website name first, such as on the home page. This can be done by setting `title_reverse` to `true` in the frontmatter of the page.
39
+
40
+ ---
41
+ title: The title of this page goes here
42
+ title_reverse: true
43
+ ---
44
+
45
+ This would output:
46
+
47
+ Your Website Name — The title of this page goes here
48
+
49
+ You can also put the website name first on every page by setting it when you activate the extension:
50
+
51
+ activate :title, site: 'Your Website Name', reverse: true
52
+
53
+ Then on any page where you want the website name to come last, you can set `title_reverse` to false in the Frontmatter:
54
+
55
+ ---
56
+ title: The title of this page goes here
57
+ title_reverse: false
58
+ ---
59
+
60
+
61
+ ## Multi-level Page Titles
62
+
63
+ When your website has heirachy, it is sometimes desirable to have multiple parts to the title. This can be done by passing an array in the Frontmatter:
64
+
65
+ ---
66
+ title:
67
+ - John Doe
68
+ - Staff
69
+ ---
70
+
71
+ This would output:
72
+
73
+ John Doe — Staff — Your Website Name
74
+
75
+
76
+ ## Contributing
77
+
78
+ 1. Fork it ( https://github.com/[my-github-username]/middleman-title/fork )
79
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
80
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
81
+ 4. Push to the branch (`git push origin my-new-feature`)
82
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+
@@ -0,0 +1,6 @@
1
+ require 'middleman-core'
2
+
3
+ ::Middleman::Extensions.register(:title) do
4
+ require 'middleman-title/extension'
5
+ ::Middleman::Title
6
+ end
@@ -0,0 +1,18 @@
1
+ require 'middleman-title/helpers'
2
+
3
+ module Middleman
4
+ module Title
5
+ class << self
6
+
7
+ def registered(app, options_hash = {}, &block)
8
+ app.helpers Helpers
9
+ @@options = options_hash
10
+ end
11
+
12
+ def options
13
+ @@options
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,67 @@
1
+ module Middleman
2
+ module Title
3
+ module Helpers
4
+
5
+ def page_title
6
+ title = []
7
+ title = add_page_name_to_title(title)
8
+ title = add_website_name_to_title(title)
9
+ title.compact.join(title_separator)
10
+ end
11
+
12
+ private
13
+ def options
14
+ Title.options
15
+ end
16
+
17
+ def website_name
18
+ current_page.data.title_site || options[:site]
19
+ end
20
+
21
+ def title_separator
22
+ options[:separator] || ' &mdash; '
23
+ end
24
+
25
+ def title_reverse
26
+ if current_page.data.title_reverse == false
27
+ false
28
+ else
29
+ current_page.data.title_reverse || options[:reverse]
30
+ end
31
+ end
32
+
33
+ def page_name
34
+ page_name = current_page.data.title
35
+
36
+ if page_name.is_a? Array
37
+ page_name = page_name.join(title_separator)
38
+ end
39
+
40
+ page_name
41
+ end
42
+
43
+ def add_website_name_to_title(title)
44
+ if current_page.data.title_site == false || website_name.nil?
45
+ title
46
+ elsif website_name_first?
47
+ title.unshift(website_name)
48
+ else
49
+ title << website_name
50
+ end
51
+ end
52
+
53
+ def add_page_name_to_title(title)
54
+ title << page_name
55
+ end
56
+
57
+ def website_name_first?
58
+ title_reverse
59
+ end
60
+
61
+ def hide_website_name?
62
+ current_page.data.title_site == false
63
+ end
64
+
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,5 @@
1
+ module Middleman
2
+ module Title
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require 'middleman-title'
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'middleman-title/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'middleman-title'
8
+ spec.version = Middleman::Title::VERSION
9
+ spec.authors = ['Justin Cypret']
10
+ spec.email = ['jcypret@gmail.com']
11
+ spec.summary = 'A Middleman extension for setting the page title'
12
+ spec.description = 'A Middleman extension for setting the page title'
13
+ spec.homepage = 'https://github.com/jcypret/middleman-title'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'middleman-core', '~> 3.2'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.6'
24
+ spec.add_development_dependency 'rake', '~> 10.3', '>= 10.3.1'
25
+ spec.add_development_dependency 'rspec', '~> 2.14', '>= 2.14.1'
26
+ end
@@ -0,0 +1,93 @@
1
+ require 'spec_helper'
2
+
3
+ describe Middleman::Title::Helpers do
4
+ let(:h) { Class.new { extend Middleman::Title::Helpers } }
5
+
6
+ describe '#page_title' do
7
+ before(:each) do
8
+ h.stub_chain(:current_page, :data, :title).and_return(nil)
9
+ h.stub_chain(:current_page, :data, :title_site).and_return(nil)
10
+ h.stub_chain(:current_page, :data, :title_reverse).and_return(nil)
11
+ end
12
+
13
+ context 'website name is set' do
14
+ before(:each) { h.stub(:options) { { site: 'Website Name' } } }
15
+
16
+ context 'page name is set' do
17
+ before(:each) { h.stub_chain(:current_page, :data, :title).and_return('How to Say Hello to the World') }
18
+
19
+ it 'puts website name last by default' do
20
+ expect(h.page_title).to eq 'How to Say Hello to the World &mdash; Website Name'
21
+ end
22
+
23
+ it 'puts website name first when frontmatter title_reverse is true' do
24
+ h.stub_chain(:current_page, :data, :title_reverse).and_return(true)
25
+ expect(h.page_title).to eq 'Website Name &mdash; How to Say Hello to the World'
26
+ end
27
+
28
+ it 'puts website name last when frontmatter title_reverse is false' do
29
+ h.stub_chain(:current_page, :data, :title_reverse).and_return(false)
30
+ expect(h.page_title).to eq 'How to Say Hello to the World &mdash; Website Name'
31
+ end
32
+
33
+ it 'puts website name first when activate reverse is true' do
34
+ h.stub(:options) { { site: 'Website Name', reverse: true } }
35
+ expect(h.page_title).to eq 'Website Name &mdash; How to Say Hello to the World'
36
+ end
37
+
38
+ it 'puts website name last when activate reverse is true but frontmatter is false' do
39
+ h.stub(:options) { { site: 'Website Name', reverse: true } }
40
+ h.stub_chain(:current_page, :data, :title_reverse).and_return(false)
41
+ expect(h.page_title).to eq 'How to Say Hello to the World &mdash; Website Name'
42
+ end
43
+
44
+ context 'separator is set' do
45
+ it 'to a vertical bar' do
46
+ h.stub(:options) { { site: 'Website Name', separator: ' | ' } }
47
+ expect(h.page_title).to eq 'How to Say Hello to the World | Website Name'
48
+ end
49
+ end
50
+
51
+ context 'but website name set to false in frontmatter' do
52
+ it 'returns only page name' do
53
+ h.stub_chain(:current_page, :data, :title_site).and_return(false)
54
+ expect(h.page_title).to eq 'How to Say Hello to the World'
55
+ end
56
+ end
57
+
58
+ context 'page name is an array' do
59
+ it 'joins page name with separator' do
60
+ h.stub_chain(:current_page, :data, :title).and_return(['John Doe', 'Staff'])
61
+ expect(h.page_title).to eq 'John Doe &mdash; Staff &mdash; Website Name'
62
+ end
63
+ end
64
+ end
65
+
66
+ context 'page name is not set' do
67
+ it 'returns only the website name' do
68
+ expect(h.page_title).to eq 'Website Name'
69
+ end
70
+ end
71
+ end
72
+
73
+ context 'website name is not set' do
74
+ before(:each) { h.stub(:options) { {} } }
75
+
76
+ context 'page name is set' do
77
+ before(:each) { h.stub_chain(:current_page, :data, :title).and_return('How to Say Hello to the World') }
78
+
79
+ it 'returns only the page name' do
80
+ expect(h.page_title).to eq 'How to Say Hello to the World'
81
+ end
82
+ end
83
+
84
+ context 'page name is not set' do
85
+ it 'returns an empty string' do
86
+ expect(h.page_title).to eq ''
87
+ end
88
+ end
89
+
90
+ end
91
+
92
+ end
93
+ end
@@ -0,0 +1,8 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'middleman-title/extension'
5
+
6
+ RSpec.configure do |config|
7
+ # some (optional) config here
8
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-title
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Justin Cypret
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: middleman-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.3'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 10.3.1
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '10.3'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 10.3.1
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '2.14'
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 2.14.1
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '2.14'
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 2.14.1
81
+ description: A Middleman extension for setting the page title
82
+ email:
83
+ - jcypret@gmail.com
84
+ executables: []
85
+ extensions: []
86
+ extra_rdoc_files: []
87
+ files:
88
+ - ".gitignore"
89
+ - ".rspec"
90
+ - ".travis.yml"
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - LICENSE.md
94
+ - README.md
95
+ - Rakefile
96
+ - lib/middleman-title.rb
97
+ - lib/middleman-title/extension.rb
98
+ - lib/middleman-title/helpers.rb
99
+ - lib/middleman-title/version.rb
100
+ - lib/middleman_extension.rb
101
+ - middleman-title.gemspec
102
+ - spec/extension_spec.rb
103
+ - spec/spec_helper.rb
104
+ homepage: https://github.com/jcypret/middleman-title
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.2.2
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: A Middleman extension for setting the page title
128
+ test_files:
129
+ - spec/extension_spec.rb
130
+ - spec/spec_helper.rb