entitlement 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,121 @@
1
+ # Entitlement
2
+
3
+ Entitlement lets you set your page titles in a simple, DRY way.
4
+
5
+ Often you want a page's title to match its heading. Although this is simple to arrange, adding Entitlement to your Gemfile instead is a one-liner. And I'm sure you don't want to write tests for your page titles.
6
+
7
+
8
+ ## Getting started
9
+
10
+ To write out your page title, use `title`:
11
+
12
+ ```html+erb
13
+ <head>
14
+ <title><%= title %></title>
15
+ </head>
16
+ ```
17
+
18
+ To set your page title, use `tee` in your page's header. This will write it out on the spot too.
19
+
20
+ ```html+erb
21
+ <h1><%= tee 'My page' %></h1>
22
+ ```
23
+
24
+ `tee` is easy to remember because:
25
+
26
+ * it's a phonetic alias for `t` (for title), and
27
+ * it acts like Unix's `tee`.
28
+
29
+ Or you can just use `title` again:
30
+
31
+ ```html+erb
32
+ <h1><%= title 'My page' %></h1>
33
+ ```
34
+
35
+
36
+ ## Include your site's name
37
+
38
+ Use `:site`:
39
+
40
+ ```html+erb
41
+ <head>
42
+ <title><%= title :site => 'My site' %></title>
43
+ </head>
44
+ ```
45
+
46
+ This will output, for example:
47
+
48
+ ```html
49
+ <head>
50
+ <title>My page - My site</title>
51
+ </head>
52
+ ```
53
+
54
+
55
+ ## Reverse the title's order
56
+
57
+ Use `:big_endian`:
58
+
59
+ ```html+erb
60
+ <head>
61
+ <title><%= title :site => 'My site', :big_endian => true %></title>
62
+ </head>
63
+ ```
64
+
65
+ Which will produce:
66
+
67
+ ```html
68
+ <head>
69
+ <title>My site - My page</title>
70
+ </head>
71
+ ```
72
+
73
+ ## Change the separator
74
+
75
+ Use `:separator`:
76
+
77
+ ```html+erb
78
+ <head>
79
+ <title><%= title :site => 'My site', :separator => ': ' %></title>
80
+ </head>
81
+ ```
82
+
83
+ Which will produce:
84
+
85
+ ```html
86
+ <head>
87
+ <title>My page: My site</title>
88
+ </head>
89
+ ```
90
+
91
+
92
+ ## Have a breadcrumb-like hierarchy
93
+
94
+ Pass the levels to `tee` (or `title`). Go from small to large whether or not you're using `:big_endian` in the site's title.
95
+
96
+ ```html+erb
97
+ <h1><%= tee 'Some article', 'Europe', 'News' %></h1>
98
+ ```
99
+
100
+ Which will produce:
101
+
102
+ ```
103
+ <h1>Some article</h1>
104
+ ```
105
+
106
+ And:
107
+
108
+ ```
109
+ <title>Some article - Europe - News</title>
110
+ ```
111
+
112
+
113
+ ## Inspiration
114
+
115
+ [Headliner](https://github.com/mokolabs/headliner)
116
+
117
+
118
+ ## Intellectual Property
119
+
120
+ Copyright 2012 Andy Stewart (boss@airbladesoftware.com).
121
+ Released under the MIT licence.
data/entitlement.gemspec CHANGED
@@ -3,22 +3,20 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
  require "entitlement/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "entitlement"
6
+ s.name = 'entitlement'
7
7
  s.version = Entitlement::VERSION
8
- s.authors = ["Andy Stewart"]
9
- s.email = ["boss@airbladesoftware.com"]
10
- s.homepage = ""
11
- s.summary = 'Easy page titles in Rails 3.'
8
+ s.authors = ['Andy Stewart']
9
+ s.email = ['boss@airbladesoftware.com']
10
+ s.homepage = 'https://github.com/airblade/entitlement'
11
+ s.summary = 'Simple page titles in Rails 3.'
12
12
  s.description = s.summary
13
13
 
14
- s.rubyforge_project = "entitlement"
14
+ s.rubyforge_project = 'entitlement'
15
15
 
16
16
  s.files = `git ls-files`.split("\n")
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- # specify any dependencies here; for example:
22
- # s.add_development_dependency "rspec"
23
- # s.add_runtime_dependency "rest-client"
21
+ s.add_runtime_dependency 'rails', '~> 3'
24
22
  end
@@ -0,0 +1,9 @@
1
+ require 'entitlement/view_helpers'
2
+
3
+ module Entitlement
4
+ class Railtie < Rails::Railtie
5
+ initializer 'entitlement.view_helpers' do
6
+ ActionView::Base.send :include, ViewHelpers
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Entitlement
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,35 @@
1
+ module Entitlement
2
+ module ViewHelpers
3
+
4
+ def title(*args)
5
+ if args.empty?
6
+ render_title
7
+ elsif args.first.is_a?(Hash)
8
+ render_title args.first
9
+ else
10
+ tee *args
11
+ end
12
+ end
13
+
14
+ def tee(*args)
15
+ @page_title = args
16
+ args.first.html_safe
17
+ end
18
+
19
+ private
20
+
21
+ def render_title(options = {})
22
+ defaults = {
23
+ :separator => ' - ',
24
+ :big_endian => false
25
+ }
26
+ options = defaults.merge options
27
+
28
+ @page_title ||= []
29
+ @page_title << options[:site] if options[:site]
30
+ @page_title.reverse! if options[:big_endian]
31
+ @page_title.join(options[:separator]).html_safe
32
+ end
33
+
34
+ end
35
+ end
data/lib/entitlement.rb CHANGED
@@ -1,5 +1,2 @@
1
- require "entitlement/version"
2
-
3
- module Entitlement
4
- # Your code goes here...
5
- end
1
+ require 'entitlement/railtie' if defined?(Rails)
2
+ require 'entitlement/version'
@@ -0,0 +1,143 @@
1
+ require 'test/unit'
2
+ require 'action_view'
3
+ require 'entitlement/view_helpers'
4
+
5
+
6
+ class View
7
+ include Entitlement::ViewHelpers
8
+ end
9
+
10
+
11
+ class ViewHelpersTest < Test::Unit::TestCase
12
+
13
+ def setup
14
+ @view = View.new
15
+ end
16
+
17
+ #
18
+ # tee
19
+ #
20
+
21
+ def test_tee_with_one_argument
22
+ out = @view.tee 'My page'
23
+ assert_equal 'My page', out
24
+ end
25
+
26
+ def test_tee_with_two_arguments
27
+ out = @view.tee 'My page', 'Some section'
28
+ assert_equal 'My page', out
29
+ end
30
+
31
+ def test_tee_is_html_safe
32
+ out = @view.tee 'My page'
33
+ assert out.html_safe?
34
+ end
35
+
36
+ #
37
+ # title as tee
38
+ #
39
+
40
+ def test_title_as_tee_alias_with_one_argument
41
+ out = @view.title 'My page'
42
+ assert_equal out, 'My page'
43
+ end
44
+
45
+ def test_title_as_tee_alias_with_two_arguments
46
+ out = @view.title 'My page', 'Some section'
47
+ assert_equal 'My page', out
48
+ end
49
+
50
+ def test_title_as_tee_alias_is_html_safe
51
+ out = @view.title 'My page'
52
+ assert out.html_safe?
53
+ end
54
+
55
+ #
56
+ # title rendering
57
+ #
58
+
59
+ def test_title_without_arguments
60
+ @view.tee 'My page'
61
+ out = @view.title
62
+ assert_equal 'My page', out
63
+ end
64
+
65
+ def test_title_without_arguments_via_title
66
+ @view.title 'My page'
67
+ out = @view.title
68
+ assert_equal 'My page', out
69
+ end
70
+
71
+ def test_title_with_site
72
+ @view.tee 'My page'
73
+ out = @view.title :site => 'My site'
74
+ assert_equal 'My page - My site', out
75
+ end
76
+
77
+ def test_title_with_site_via_title
78
+ @view.title 'My page'
79
+ out = @view.title :site => 'My site'
80
+ assert_equal 'My page - My site', out
81
+ end
82
+
83
+ def test_title_with_sections
84
+ @view.tee 'My page', 'Some section'
85
+ out = @view.title
86
+ assert_equal 'My page - Some section', out
87
+ end
88
+
89
+ def test_title_with_sections_via_title
90
+ @view.title 'My page', 'Some section'
91
+ out = @view.title
92
+ assert_equal 'My page - Some section', out
93
+ end
94
+
95
+ def test_title_with_site_and_sections
96
+ @view.tee 'My page', 'Some section'
97
+ out = @view.title :site => 'My site'
98
+ assert_equal 'My page - Some section - My site', out
99
+ end
100
+
101
+ def test_title_with_site_and_sections_via_title
102
+ @view.title 'My page', 'Some section'
103
+ out = @view.title :site => 'My site'
104
+ assert_equal 'My page - Some section - My site', out
105
+ end
106
+
107
+ def test_title_with_custom_separator
108
+ @view.tee 'My page'
109
+ out = @view.title :site => 'My site', :separator => ': '
110
+ assert_equal 'My page: My site', out
111
+ end
112
+
113
+ def test_title_with_custom_separator_via_title
114
+ @view.title 'My page'
115
+ out = @view.title :site => 'My site', :separator => ': '
116
+ assert_equal 'My page: My site', out
117
+ end
118
+
119
+ def test_title_big_endian
120
+ @view.tee 'My page', 'Some section'
121
+ out = @view.title :site => 'My site', :big_endian => true
122
+ assert_equal 'My site - Some section - My page', out
123
+ end
124
+
125
+ def test_title_big_endian_via_title
126
+ @view.title 'My page', 'Some section'
127
+ out = @view.title :site => 'My site', :big_endian => true
128
+ assert_equal 'My site - Some section - My page', out
129
+ end
130
+
131
+ def test_title_is_html_safe
132
+ @view.tee 'My page'
133
+ out = @view.title
134
+ assert out.html_safe?
135
+ end
136
+
137
+ def test_title_is_html_safe_via_title
138
+ @view.title 'My page'
139
+ out = @view.title
140
+ assert out.html_safe?
141
+ end
142
+
143
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: entitlement
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,9 +9,20 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-10 00:00:00.000000000 Z
13
- dependencies: []
14
- description: Easy page titles in Rails 3.
12
+ date: 2012-02-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &2154720800 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2154720800
25
+ description: Simple page titles in Rails 3.
15
26
  email:
16
27
  - boss@airbladesoftware.com
17
28
  executables: []
@@ -20,11 +31,15 @@ extra_rdoc_files: []
20
31
  files:
21
32
  - .gitignore
22
33
  - Gemfile
34
+ - README.md
23
35
  - Rakefile
24
36
  - entitlement.gemspec
25
37
  - lib/entitlement.rb
38
+ - lib/entitlement/railtie.rb
26
39
  - lib/entitlement/version.rb
27
- homepage: ''
40
+ - lib/entitlement/view_helpers.rb
41
+ - test/view_helpers_test.rb
42
+ homepage: https://github.com/airblade/entitlement
28
43
  licenses: []
29
44
  post_install_message:
30
45
  rdoc_options: []
@@ -47,5 +62,6 @@ rubyforge_project: entitlement
47
62
  rubygems_version: 1.8.11
48
63
  signing_key:
49
64
  specification_version: 3
50
- summary: Easy page titles in Rails 3.
51
- test_files: []
65
+ summary: Simple page titles in Rails 3.
66
+ test_files:
67
+ - test/view_helpers_test.rb