heading_with_title 0.0.1
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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE.txt +22 -0
- data/README.md +59 -0
- data/Rakefile +1 -0
- data/heading_with_title.gemspec +23 -0
- data/lib/heading_with_title/helpers.rb +22 -0
- data/lib/heading_with_title/railtie.rb +10 -0
- data/lib/heading_with_title/version.rb +3 -0
- data/lib/heading_with_title.rb +66 -0
- data/spec/heading_with_title/helpers_spec.rb +52 -0
- metadata +122 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 tanraya
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# HeadingWithTitle - A set of helpers for Rails
|
|
2
|
+
|
|
3
|
+
Setting the page heading (e.g H1) at the same time with a page title (inside `<title>` tag).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
First, put this line in your `Gemfile`:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'heading_with_title'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Then run `bundle install` to update your application's bundle.#
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
Add `page_title` call within `<title>` tag:
|
|
18
|
+
|
|
19
|
+
```erb
|
|
20
|
+
<title><%= page_title %></title>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
And then in the views you just call `heading_with_title` helper to set page title with
|
|
24
|
+
heading, or you call `page_title('Something')` to set page title without heading.
|
|
25
|
+
|
|
26
|
+
## Examples:
|
|
27
|
+
```erb
|
|
28
|
+
# Set both title and heading
|
|
29
|
+
<%= heading_with_title 'Users' %>
|
|
30
|
+
|
|
31
|
+
# It also respects a block
|
|
32
|
+
<%= heading_with_title 'Users' do |heading| %>
|
|
33
|
+
<span><%= heading %></span>
|
|
34
|
+
<% end %>
|
|
35
|
+
|
|
36
|
+
# Or you might want to set only page title
|
|
37
|
+
<% page_title 'Users' %>
|
|
38
|
+
```
|
|
39
|
+
## Configuration
|
|
40
|
+
|
|
41
|
+
Create initializer file, `config/initializers/heading_with_title.rb` and put some
|
|
42
|
+
configuration settings into it:
|
|
43
|
+
```ruby
|
|
44
|
+
HeadingWithTitle.configure do |config|
|
|
45
|
+
# Set page title delimeter
|
|
46
|
+
# Example: Page Title / AwesomeApp
|
|
47
|
+
config.title_delimeter = ' / '
|
|
48
|
+
|
|
49
|
+
# Title suffix that shown at the end of page title
|
|
50
|
+
# Accepts String or Proc
|
|
51
|
+
config.title_suffix = ->{ Rails.application.name }
|
|
52
|
+
|
|
53
|
+
# Default heading size (h1 by default)
|
|
54
|
+
config.default_heading_size = :h1
|
|
55
|
+
end
|
|
56
|
+
```
|
|
57
|
+
## License
|
|
58
|
+
|
|
59
|
+
[The MIT License](https://github.com/tanraya/heading_with_title/blob/master/MIT-LICENSE)
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
+
require "heading_with_title/version"
|
|
4
|
+
|
|
5
|
+
# Describe your gem and declare its dependencies:
|
|
6
|
+
Gem::Specification.new do |s|
|
|
7
|
+
s.name = "heading_with_title"
|
|
8
|
+
s.version = HeadingWithTitle::VERSION
|
|
9
|
+
s.authors = ["Andrew Kozloff"]
|
|
10
|
+
s.email = ["demerest@gmail.com"]
|
|
11
|
+
s.homepage = "https://github.com/rocsci/heading_with_title"
|
|
12
|
+
s.summary = "A set of helpers for Rails"
|
|
13
|
+
s.description = "Setting the page heading at the same time with a page title"
|
|
14
|
+
s.license = "MIT"
|
|
15
|
+
s.files = `git ls-files`.split($/)
|
|
16
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
|
17
|
+
s.require_paths = ["lib"]
|
|
18
|
+
|
|
19
|
+
s.add_dependency "rails"
|
|
20
|
+
s.add_development_dependency "bundler", "~> 1.3"
|
|
21
|
+
s.add_development_dependency "rake"
|
|
22
|
+
s.add_development_dependency "rspec"
|
|
23
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
module HeadingWithTitle
|
|
3
|
+
module Helpers #:nodoc:
|
|
4
|
+
# Set page title. Use this method in your views
|
|
5
|
+
def page_title(title = nil)
|
|
6
|
+
if title.present?
|
|
7
|
+
@hwt_title = title
|
|
8
|
+
nil
|
|
9
|
+
else
|
|
10
|
+
suffix = HeadingWithTitle.title_suffix
|
|
11
|
+
suffix = suffix.call if suffix.is_a?(Proc)
|
|
12
|
+
raw ([@hwt_title, suffix].compact.join(HeadingWithTitle.title_delimeter))
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def heading_with_title(heading, &block)
|
|
17
|
+
page_title(heading)
|
|
18
|
+
heading = raw(block.call(heading)) if block_given?
|
|
19
|
+
content_tag(HeadingWithTitle.default_heading_size, heading)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require "heading_with_title/version"
|
|
3
|
+
require "rails"
|
|
4
|
+
require "action_view"
|
|
5
|
+
|
|
6
|
+
# = HeadingWithTitle - A set of helpers for Rails
|
|
7
|
+
#
|
|
8
|
+
# Setting the page heading (e.g H1) at the same time with a page title (inside `<title>` tag).
|
|
9
|
+
#
|
|
10
|
+
# Add `page_title` call within `<title>` tag:
|
|
11
|
+
#
|
|
12
|
+
# <title><%= page_title %></title>
|
|
13
|
+
#
|
|
14
|
+
# And then in the views you just call `heading_with_title` helper to set page title with
|
|
15
|
+
# heading, or you call `page_title('Something')` to set page title without heading.
|
|
16
|
+
#
|
|
17
|
+
# == Examples:
|
|
18
|
+
#
|
|
19
|
+
# # Set both title and heading
|
|
20
|
+
# <%= heading_with_title 'Users' %>
|
|
21
|
+
#
|
|
22
|
+
# # It also respects a block
|
|
23
|
+
# <%= heading_with_title 'Users' do |heading| %>
|
|
24
|
+
# <span><%= heading %></span>
|
|
25
|
+
# <% end %>
|
|
26
|
+
#
|
|
27
|
+
# Or you might want to set only page title
|
|
28
|
+
# <% page_title 'Users' %>
|
|
29
|
+
#
|
|
30
|
+
# == Configuration
|
|
31
|
+
# Create initializer file, `config/initializers/heading_with_title.rb` and put some
|
|
32
|
+
# configuration settings into it:
|
|
33
|
+
#
|
|
34
|
+
# HeadingWithTitle.configure do |config|
|
|
35
|
+
# # Set page title delimeter
|
|
36
|
+
# # Example: Page Title / AwesomeApp
|
|
37
|
+
# config.title_delimeter = ' / '
|
|
38
|
+
#
|
|
39
|
+
# # Title suffix that shown at the end of page title
|
|
40
|
+
# # Accepts String or Proc
|
|
41
|
+
# config.title_suffix = ->{ Rails.application.name }
|
|
42
|
+
#
|
|
43
|
+
# # Default heading size (h1 by default)
|
|
44
|
+
# config.default_heading_size = :h1
|
|
45
|
+
# end
|
|
46
|
+
#
|
|
47
|
+
module HeadingWithTitle
|
|
48
|
+
# Set page title delimeter
|
|
49
|
+
# Example: Page Title / AwesomeApp
|
|
50
|
+
mattr_accessor :title_delimeter
|
|
51
|
+
@@title_delimeter = ' / '
|
|
52
|
+
|
|
53
|
+
# Title suffix that shown at the end of page title
|
|
54
|
+
mattr_accessor :title_suffix
|
|
55
|
+
@@title_suffix = ->{ Rails.application.name }
|
|
56
|
+
|
|
57
|
+
# Default heading size (h1 by default)
|
|
58
|
+
mattr_accessor :default_heading_size
|
|
59
|
+
@@default_heading_size = :h1
|
|
60
|
+
|
|
61
|
+
def self.configure
|
|
62
|
+
yield self
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
require 'heading_with_title/railtie' if defined?(Rails)
|
|
66
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require "heading_with_title"
|
|
3
|
+
|
|
4
|
+
describe HeadingWithTitle::Helpers do
|
|
5
|
+
include ActionView::Helpers
|
|
6
|
+
include HeadingWithTitle::Helpers
|
|
7
|
+
|
|
8
|
+
before { Rails.stub_chain(:application, :name).and_return('AwesomeApp') }
|
|
9
|
+
|
|
10
|
+
describe '.page_title' do
|
|
11
|
+
it 'sets a page title' do
|
|
12
|
+
page_title('Something')
|
|
13
|
+
page_title.should == 'Something / AwesomeApp'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'respects delimeter' do
|
|
17
|
+
HeadingWithTitle.title_delimeter = ' - '
|
|
18
|
+
page_title('Something')
|
|
19
|
+
page_title.should == 'Something - AwesomeApp'
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'returns nil when set an page title' do
|
|
23
|
+
page_title('Something').should be_nil
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe '.heading_with_title' do
|
|
28
|
+
before { HeadingWithTitle.title_delimeter = ' / ' }
|
|
29
|
+
|
|
30
|
+
it 'renders default h1 heading' do
|
|
31
|
+
heading_with_title('Users').should == '<h1>Users</h1>'
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'sets an page title' do
|
|
35
|
+
heading_with_title('Users')
|
|
36
|
+
page_title.should == 'Users / AwesomeApp'
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'applies block' do
|
|
40
|
+
result = heading_with_title 'Users' do |heading|
|
|
41
|
+
"<span>" + heading + "</span>"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
result.should == '<h1><span>Users</span></h1>'
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'respects heading size' do
|
|
48
|
+
HeadingWithTitle.default_heading_size = :h2
|
|
49
|
+
heading_with_title('Users').should == '<h2>Users</h2>'
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: heading_with_title
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Andrew Kozloff
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-11-27 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: rails
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ! '>='
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '0'
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: bundler
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ~>
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '1.3'
|
|
38
|
+
type: :development
|
|
39
|
+
prerelease: false
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ~>
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '1.3'
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: rake
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
none: false
|
|
50
|
+
requirements:
|
|
51
|
+
- - ! '>='
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
type: :development
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
none: false
|
|
58
|
+
requirements:
|
|
59
|
+
- - ! '>='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
- !ruby/object:Gem::Dependency
|
|
63
|
+
name: rspec
|
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
|
65
|
+
none: false
|
|
66
|
+
requirements:
|
|
67
|
+
- - ! '>='
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '0'
|
|
70
|
+
type: :development
|
|
71
|
+
prerelease: false
|
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
73
|
+
none: false
|
|
74
|
+
requirements:
|
|
75
|
+
- - ! '>='
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '0'
|
|
78
|
+
description: Setting the page heading at the same time with a page title
|
|
79
|
+
email:
|
|
80
|
+
- demerest@gmail.com
|
|
81
|
+
executables: []
|
|
82
|
+
extensions: []
|
|
83
|
+
extra_rdoc_files: []
|
|
84
|
+
files:
|
|
85
|
+
- .gitignore
|
|
86
|
+
- Gemfile
|
|
87
|
+
- MIT-LICENSE.txt
|
|
88
|
+
- README.md
|
|
89
|
+
- Rakefile
|
|
90
|
+
- heading_with_title.gemspec
|
|
91
|
+
- lib/heading_with_title.rb
|
|
92
|
+
- lib/heading_with_title/helpers.rb
|
|
93
|
+
- lib/heading_with_title/railtie.rb
|
|
94
|
+
- lib/heading_with_title/version.rb
|
|
95
|
+
- spec/heading_with_title/helpers_spec.rb
|
|
96
|
+
homepage: https://github.com/rocsci/heading_with_title
|
|
97
|
+
licenses:
|
|
98
|
+
- MIT
|
|
99
|
+
post_install_message:
|
|
100
|
+
rdoc_options: []
|
|
101
|
+
require_paths:
|
|
102
|
+
- lib
|
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
|
+
none: false
|
|
105
|
+
requirements:
|
|
106
|
+
- - ! '>='
|
|
107
|
+
- !ruby/object:Gem::Version
|
|
108
|
+
version: '0'
|
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
|
+
none: false
|
|
111
|
+
requirements:
|
|
112
|
+
- - ! '>='
|
|
113
|
+
- !ruby/object:Gem::Version
|
|
114
|
+
version: '0'
|
|
115
|
+
requirements: []
|
|
116
|
+
rubyforge_project:
|
|
117
|
+
rubygems_version: 1.8.24
|
|
118
|
+
signing_key:
|
|
119
|
+
specification_version: 3
|
|
120
|
+
summary: A set of helpers for Rails
|
|
121
|
+
test_files:
|
|
122
|
+
- spec/heading_with_title/helpers_spec.rb
|