tophat 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - jruby
5
+ - rbx
6
+ - ree
7
+ - ruby-head
data/Guardfile ADDED
@@ -0,0 +1,6 @@
1
+ guard 'rspec', :cli => '--format documentation' do
2
+ watch(%r{^spec/.+_spec\.rb})
3
+ watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch(%r{^lib/tophat/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_helper_spec.rb" }
5
+ watch('spec/spec_helper.rb') { "spec" }
6
+ end
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
- TopHat
2
- ======
1
+ TopHat [![Build Status](https://secure.travis-ci.org/spagalloco/tophat.png)](http://travis-ci.org/spagalloco/tophat)
2
+ ====================================================================================================================
3
3
 
4
4
  TopHat is a set of view helpers to keep your layouts and views DRY.
5
5
 
@@ -32,12 +32,14 @@ Usage Options
32
32
 
33
33
  Use these options to customize the title format:
34
34
 
35
- * :prefix (text between site name and separator)
36
- * :separator (text used to separate website name from page title)
37
- * :suffix (text between separator and page title)
38
- * :lowercase (when true, the page name will be lowercase)
39
- * :reverse (when true, the page and site names will be reversed)
40
- * :default (default title to use when title is blank)
35
+ * `:prefix` (text between site name and separator) [default: '']
36
+ * `:separator` (text used to separate website name from page title)
37
+ * `:suffix` (text between separator and page title) [default: ' ']
38
+ * `:lowercase` (when true, the entire title will be lowercase)
39
+ * `:uppercase` (when true, the entire title will be uppercase)
40
+ * `:reverse` (when true, the page and site names will be reversed)
41
+ * `:reverse_on_default` (when true it will lead to a 'Default Title | Site' title when using a default title)
42
+ * `:default` (default title to use when title is blank)
41
43
 
42
44
  And here are a few examples to give you ideas.
43
45
 
@@ -51,8 +53,8 @@ These options can be set as defaults for your layout, or when setting the title
51
53
 
52
54
  <% title "My page title", :lowercase => true, :separator => "~" %>
53
55
 
54
- Meta Tag Usage
55
- --------------
56
+ Meta Tags
57
+ ---------
56
58
 
57
59
  TopHat also works with keywords and descriptions. In your view, simply declare the keywords and description.
58
60
 
@@ -82,6 +84,71 @@ want to merge your default tags with those in your view? just pass merge_default
82
84
 
83
85
  <%= keywords :default => 'Yoko, Linda', :merge_default => true %>
84
86
 
87
+ There are also convenience methods for a few common meta tags:
88
+
89
+ <%= noindex() %> # outputs: <meta content="noindex" name="robots" />
90
+ <%= noindex('googlebot') # outputs: <meta content="noindex" name="googlebot" />
91
+ <%= nofollow() %> # outputs: <meta content="nofollow" name="robots" />
92
+ <%= nofollow('googlebot') # outputs: <meta content="nofollow" name="googlebot" />
93
+ <%= canonical('http://mysite.com/somepath/') %> # outputs: <link href="http://mysite.com/somepath/" rel="canonical" />
94
+
95
+ Browser Conditionals
96
+ --------------------
97
+
98
+ TopHat can generate a lot of different browser conditional comments as well:
99
+
100
+ ie_5_conditional do
101
+ stylesheet_link_tag 'ie'
102
+ end
103
+
104
+ will render:
105
+
106
+ <!--[if IE 5]>
107
+ <link href="/stylesheets/ie.css" media="screen" rel="stylesheet" type="text/css" />
108
+ <![endif]-->
109
+
110
+ You can also pass in conditions via an argument to the conditional:
111
+
112
+ ie_5_5_conditional(:lt) => <!--[if lt IE 5.5]>
113
+ ie_5_5_conditional(:gt) => <!--[if gt IE 5.5]>
114
+ ie_5_conditional(:lte) => <!--[if lte IE 5]>
115
+ ie_5_conditional(:gte) => <!--[if gte IE 5]>
116
+ if_5_5_conditional(:not) => <!--[if !IE 5]>
117
+ webkit_conditional(:eq) => <!--[if eq Webkit]>
118
+
119
+ A lot of browsers are supported, check the code for the full listing.
120
+
121
+ OpenGraph Helpers
122
+ -----------------
123
+
124
+ TopHat can also generate Facebook OpenGraph tags. In your views, you can assign any number of attributes by passing a block to the opengraph helper. This will store the attributes for that page.
125
+
126
+ opengraph do |graph|
127
+ graph.title 'Rain Man'
128
+ graph.type 'Movie'
129
+ end
130
+
131
+ To embed OpenGraph tags on your page, you'll need to reference opengraph in your layout.
132
+
133
+ <%= opengraph %>
134
+
135
+ You can add an app_id and/or admin ids in your layout:
136
+
137
+ <%= opengraph(:app_id => 'MyApp', :admins => [123, 1234]) %>
138
+
139
+ When used in combination, TopHat will render:
140
+
141
+ <meta content="MyApp" property="fb:app_id" />
142
+ <meta content="123,1234" property="fb:admins" />
143
+ <meta content="movie" property="og:type" />
144
+ <meta content="Rain Man" property="og:title" />
145
+
146
+ There's also a helper for the html tag along with the opengraph namespaces:
147
+
148
+ html_with_opengraph => <html xmlns:fb...>
149
+
150
+
151
+ Note: TopHat does not include a "Like" button helper. TopHat's focus is inside the `<head>` tag.
85
152
 
86
153
  Note on Patches/Pull Requests
87
154
  -----------------------------
@@ -52,6 +52,12 @@ module TopHat
52
52
 
53
53
  end
54
54
 
55
+ def html_with_opengraph
56
+ '<html xmlns="http://www.w3.org/1999/xhtml"
57
+ xmlns:og="http://ogp.me/ns#"
58
+ xmlns:fb="https://www.facebook.com/2008/fbml">'
59
+ end
60
+
55
61
  def opengraph(options=nil, &block)
56
62
  if options.kind_of? Hash
57
63
  @tophat_open_graph_defaults = options
data/lib/tophat/title.rb CHANGED
@@ -2,25 +2,46 @@ module TopHat
2
2
  module TitleHelper
3
3
 
4
4
  def title(title=nil, options={})
5
- if title.is_a? String
5
+ if title.is_a?(String) || title.is_a?(Array)
6
6
  save_tophat_title(title, options)
7
7
  else
8
- display_tophat_title(title)
8
+ display_tophat_title(title || options)
9
9
  end
10
10
  end
11
11
 
12
12
  private
13
13
 
14
14
  def save_tophat_title(title, options)
15
- @tophat_title = title.gsub(/<\/?[^>]*>/, '')
15
+ @tophat_title = title
16
16
  @tophat_title_options = options
17
17
  title
18
18
  end
19
19
 
20
- def display_tophat_title(options={})
21
- options ||= {}
20
+ def display_tophat_title(options)
22
21
  options = options.merge(@tophat_title_options) unless @tophat_title_options.nil?
23
22
 
23
+ title_segments = []
24
+ title_segments << options[:site] if options[:site]
25
+ title_segments << (@tophat_title.blank? ? options[:default] : @tophat_title)
26
+
27
+ title_segments.flatten! # flatten out in case the title is an array
28
+ title_segments.compact! # clean out any nils
29
+ title_segments.map! { |t| t.downcase! } if options[:lowercase]
30
+ title_segments.map! { |t| t.upcase! } if options[:uppercase]
31
+ title_segments.map! { |t| strip_tags(t) }
32
+
33
+ reverse = options[:reverse]
34
+ reverse = false if options[:default] && @tophat_title.blank? && options[:reverse_on_default] == false
35
+
36
+ title_segments.reverse! if reverse
37
+
38
+ content_tag :title, title_segments.join(delimiter_from(options)).strip
39
+ end
40
+ alias t title
41
+
42
+ def delimiter_from(options={})
43
+ return "" if options.empty?
44
+
24
45
  # Prefix (leading space)
25
46
  if options[:prefix]
26
47
  prefix = options[:prefix]
@@ -42,48 +63,7 @@ module TopHat
42
63
  suffix = ' '
43
64
  end
44
65
 
45
- # site name
46
- site_name = options[:site] || ''
47
-
48
- # Lowercase title?
49
- if options[:lowercase] == true
50
- @tophat_title.downcase! unless @tophat_title.blank?
51
- site_name.downcase! unless site_name.blank?
52
- end
53
-
54
- # Default page title
55
- if @tophat_title.blank? && options[:default]
56
- @tophat_title = options[:default]
57
- @tophat_title_defaulted = true
58
- end
59
-
60
- # figure out reversing
61
- if options[:reverse] == true
62
- if @tophat_title_defaulted
63
- @tophat_reserve = options[:reverse_on_default] != false
64
- else
65
- @tophat_reverse = true
66
- end
67
- else
68
- @tophat_reverse = false
69
- end
70
-
71
- # Set website/page order
72
- if @tophat_title.blank?
73
- # If title is blank, return only website name
74
- content_tag :title, site_name if options[:site]
75
- else
76
- display_title = if @tophat_reverse == true
77
- # Reverse order => "Page : Website"
78
- @tophat_title + prefix + separator + suffix + site_name
79
- else
80
- # Standard order => "Website : Page"
81
- site_name + prefix + separator + suffix + @tophat_title
82
- end
83
-
84
- return content_tag(:title, display_title.strip)
85
- end
66
+ prefix + separator + suffix
86
67
  end
87
- alias t title
88
68
  end
89
69
  end
@@ -1,3 +1,3 @@
1
1
  module TopHat
2
- VERSION = '1.3.0'
2
+ VERSION = '1.3.1'
3
3
  end
@@ -6,6 +6,14 @@ describe TopHat::OpenGraphHelper do
6
6
  @template = ActionView::Base.new
7
7
  end
8
8
 
9
+ context 'html_with_opengraph' do
10
+ it 'should render an html tag with namespace' do
11
+ @template.html_with_opengraph.should =~ /<html/
12
+ @template.html_with_opengraph.should =~ /xmlns\:og/
13
+ @template.html_with_opengraph.should =~ /xmlns\:fb/
14
+ end
15
+ end
16
+
9
17
  context "site admins when configured" do
10
18
  context "as a string" do
11
19
  it "should generate a site admin tag" do
@@ -46,6 +46,11 @@ describe TopHat::TitleHelper do
46
46
  @template.title(:site => "Miles Davis", :lowercase => true, :separator => '|').should == "<title>miles davis | kind of blue</title>"
47
47
  end
48
48
 
49
+ it "should be uppercase if :uppercase" do
50
+ save_basic_title
51
+ @template.title(:site => "Miles Davis", :uppercase => true, :separator => '|').should == "<title>MILES DAVIS | KIND OF BLUE</title>"
52
+ end
53
+
49
54
  it "should use custom separator if :separator" do
50
55
  save_basic_title
51
56
  @template.title(:site => "Miles Davis", :separator => "-").should == "<title>Miles Davis - Kind of Blue</title>"
@@ -83,6 +88,11 @@ describe TopHat::TitleHelper do
83
88
  save_custom_title
84
89
  @template.title(:site => "Freddie Freeloader", :separator => '|').should == "<title>Kind of Blue | Freddie Freeloader</title>"
85
90
  end
91
+
92
+ it "should accept an array of strings as the title" do
93
+ @template.title(['My', 'Favorite', 'Things'])
94
+ @template.title(:site => "Freddie Freeloader", :separator => '|').should == "<title>Freddie Freeloader | My | Favorite | Things</title>"
95
+ end
86
96
  end
87
97
 
88
98
  def save_basic_title(title='Kind of Blue')
data/tophat.gemspec CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency('simplecov', '~> 0.3')
23
23
  s.add_development_dependency('shoulda', '>= 0')
24
24
  s.add_development_dependency('rails', '>= 3.0.0')
25
+ s.add_development_dependency('guard-rspec', '~> 0.4')
25
26
 
26
27
  s.files = `git ls-files`.split("\n")
27
28
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
metadata CHANGED
@@ -1,131 +1,139 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: tophat
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.1
4
5
  prerelease:
5
- version: 1.3.0
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Steve Agalloco
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-02-19 00:00:00 -05:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
12
+ date: 2011-09-15 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
17
15
  name: actionpack
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2157007300 !ruby/object:Gem::Requirement
20
17
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
24
21
  version: 3.0.0
25
22
  type: :runtime
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
23
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2157007300
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
27
+ requirement: &2157006800 !ruby/object:Gem::Requirement
31
28
  none: false
32
- requirements:
29
+ requirements:
33
30
  - - ~>
34
- - !ruby/object:Gem::Version
35
- version: "1.0"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.0'
36
33
  type: :development
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
39
- name: rake
40
34
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *2157006800
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &2157006340 !ruby/object:Gem::Requirement
42
39
  none: false
43
- requirements:
40
+ requirements:
44
41
  - - ~>
45
- - !ruby/object:Gem::Version
46
- version: "0.8"
42
+ - !ruby/object:Gem::Version
43
+ version: '0.8'
47
44
  type: :development
48
- version_requirements: *id003
49
- - !ruby/object:Gem::Dependency
50
- name: rspec
51
45
  prerelease: false
52
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *2157006340
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: &2157005880 !ruby/object:Gem::Requirement
53
50
  none: false
54
- requirements:
51
+ requirements:
55
52
  - - ~>
56
- - !ruby/object:Gem::Version
53
+ - !ruby/object:Gem::Version
57
54
  version: 2.5.0
58
55
  type: :development
59
- version_requirements: *id004
60
- - !ruby/object:Gem::Dependency
61
- name: yard
62
56
  prerelease: false
63
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ version_requirements: *2157005880
58
+ - !ruby/object:Gem::Dependency
59
+ name: yard
60
+ requirement: &2157005420 !ruby/object:Gem::Requirement
64
61
  none: false
65
- requirements:
62
+ requirements:
66
63
  - - ~>
67
- - !ruby/object:Gem::Version
68
- version: "0.6"
64
+ - !ruby/object:Gem::Version
65
+ version: '0.6'
69
66
  type: :development
70
- version_requirements: *id005
71
- - !ruby/object:Gem::Dependency
72
- name: maruku
73
67
  prerelease: false
74
- requirement: &id006 !ruby/object:Gem::Requirement
68
+ version_requirements: *2157005420
69
+ - !ruby/object:Gem::Dependency
70
+ name: maruku
71
+ requirement: &2157004960 !ruby/object:Gem::Requirement
75
72
  none: false
76
- requirements:
73
+ requirements:
77
74
  - - ~>
78
- - !ruby/object:Gem::Version
79
- version: "0.6"
75
+ - !ruby/object:Gem::Version
76
+ version: '0.6'
80
77
  type: :development
81
- version_requirements: *id006
82
- - !ruby/object:Gem::Dependency
83
- name: simplecov
84
78
  prerelease: false
85
- requirement: &id007 !ruby/object:Gem::Requirement
79
+ version_requirements: *2157004960
80
+ - !ruby/object:Gem::Dependency
81
+ name: simplecov
82
+ requirement: &2157004500 !ruby/object:Gem::Requirement
86
83
  none: false
87
- requirements:
84
+ requirements:
88
85
  - - ~>
89
- - !ruby/object:Gem::Version
90
- version: "0.3"
86
+ - !ruby/object:Gem::Version
87
+ version: '0.3'
91
88
  type: :development
92
- version_requirements: *id007
93
- - !ruby/object:Gem::Dependency
94
- name: shoulda
95
89
  prerelease: false
96
- requirement: &id008 !ruby/object:Gem::Requirement
90
+ version_requirements: *2157004500
91
+ - !ruby/object:Gem::Dependency
92
+ name: shoulda
93
+ requirement: &2157037560 !ruby/object:Gem::Requirement
97
94
  none: false
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- version: "0"
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
102
99
  type: :development
103
- version_requirements: *id008
104
- - !ruby/object:Gem::Dependency
105
- name: rails
106
100
  prerelease: false
107
- requirement: &id009 !ruby/object:Gem::Requirement
101
+ version_requirements: *2157037560
102
+ - !ruby/object:Gem::Dependency
103
+ name: rails
104
+ requirement: &2157037100 !ruby/object:Gem::Requirement
108
105
  none: false
109
- requirements:
110
- - - ">="
111
- - !ruby/object:Gem::Version
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
112
109
  version: 3.0.0
113
110
  type: :development
114
- version_requirements: *id009
111
+ prerelease: false
112
+ version_requirements: *2157037100
113
+ - !ruby/object:Gem::Dependency
114
+ name: guard-rspec
115
+ requirement: &2157036640 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ~>
119
+ - !ruby/object:Gem::Version
120
+ version: '0.4'
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: *2157036640
115
124
  description: simple view helpers for your layouts
116
- email:
125
+ email:
117
126
  - steve.agalloco@gmail.com
118
127
  executables: []
119
-
120
128
  extensions: []
121
-
122
129
  extra_rdoc_files: []
123
-
124
- files:
130
+ files:
125
131
  - .document
126
132
  - .gitignore
127
133
  - .rspec
134
+ - .travis.yml
128
135
  - Gemfile
136
+ - Guardfile
129
137
  - LICENSE
130
138
  - README.md
131
139
  - Rakefile
@@ -144,35 +152,31 @@ files:
144
152
  - spec/tophat/title_helper_spec.rb
145
153
  - spec/tophat_spec.rb
146
154
  - tophat.gemspec
147
- has_rdoc: true
148
155
  homepage: https://github.com/spagalloco/tophat
149
156
  licenses: []
150
-
151
157
  post_install_message:
152
158
  rdoc_options: []
153
-
154
- require_paths:
159
+ require_paths:
155
160
  - lib
156
- required_ruby_version: !ruby/object:Gem::Requirement
161
+ required_ruby_version: !ruby/object:Gem::Requirement
157
162
  none: false
158
- requirements:
159
- - - ">="
160
- - !ruby/object:Gem::Version
161
- version: "0"
162
- required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ! '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
168
  none: false
164
- requirements:
165
- - - ">="
166
- - !ruby/object:Gem::Version
167
- version: "0"
169
+ requirements:
170
+ - - ! '>='
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
168
173
  requirements: []
169
-
170
174
  rubyforge_project:
171
- rubygems_version: 1.5.0
175
+ rubygems_version: 1.8.6
172
176
  signing_key:
173
177
  specification_version: 3
174
178
  summary: simple view helpers for your layouts
175
- test_files:
179
+ test_files:
176
180
  - spec/spec_helper.rb
177
181
  - spec/tophat/meta_helper_spec.rb
178
182
  - spec/tophat/opengraph_helper_spec.rb