tophat 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  rvm:
2
2
  - 1.8.7
3
3
  - 1.9.2
4
+ - 1.9.3
4
5
  - jruby
5
6
  - rbx
6
7
  - ree
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source "http://rubygems.org"
1
+ source :rubygems
2
2
  gemspec
File without changes
data/README.md CHANGED
@@ -1,21 +1,26 @@
1
- TopHat [![Build Status](https://secure.travis-ci.org/spagalloco/tophat.png)](http://travis-ci.org/spagalloco/tophat)
2
- ====================================================================================================================
1
+ # TopHat
3
2
 
4
3
  TopHat is a set of view helpers to keep your layouts and views DRY.
5
4
 
6
- Layout Usage
7
- ------------
5
+ ## Installation
6
+
7
+ Just add it to your Gemfile:
8
+
9
+ gem 'tophat'
10
+
11
+ Note: TopHat is Rails 3.0+ compatible.
12
+
13
+ ## Layout Usage
8
14
 
9
15
  You'll want to add the relevant TopHat helpers to your layouts:
10
16
 
11
17
  <head>
12
- <%= title :site => "My website" %>
18
+ <%= title :site => "My website", :separator => '|' %>
13
19
  <%= keywords :default => "Some default, keywords, that can be overridden" %>
14
20
  <%= description :default => "A description" %>
15
21
  </head>
16
22
 
17
- View Usage
18
- ----------
23
+ ## View Usage
19
24
 
20
25
  To set the page title, use the title method to each of your views:
21
26
 
@@ -27,13 +32,12 @@ When rendered, the page title will be included in your view.
27
32
  <title>My website | My page title</title>
28
33
  </head>
29
34
 
30
- Usage Options
31
- -------------
35
+ ## Usage Options
32
36
 
33
37
  Use these options to customize the title format:
34
38
 
35
39
  * `:prefix` (text between site name and separator) [default: '']
36
- * `:separator` (text used to separate website name from page title)
40
+ * `:separator` (text used to separate website name from page title, default is '')
37
41
  * `:suffix` (text between separator and page title) [default: ' ']
38
42
  * `:lowercase` (when true, the entire title will be lowercase)
39
43
  * `:uppercase` (when true, the entire title will be uppercase)
@@ -53,8 +57,7 @@ These options can be set as defaults for your layout, or when setting the title
53
57
 
54
58
  <% title "My page title", :lowercase => true, :separator => "~" %>
55
59
 
56
- Meta Tags
57
- ---------
60
+ ## Meta Tags
58
61
 
59
62
  TopHat also works with keywords and descriptions. In your view, simply declare the keywords and description.
60
63
 
@@ -92,8 +95,7 @@ There are also convenience methods for a few common meta tags:
92
95
  <%= nofollow('googlebot') # outputs: <meta content="nofollow" name="googlebot" />
93
96
  <%= canonical('http://mysite.com/somepath/') %> # outputs: <link href="http://mysite.com/somepath/" rel="canonical" />
94
97
 
95
- Browser Conditionals
96
- --------------------
98
+ ## Browser Conditionals
97
99
 
98
100
  TopHat can generate a lot of different browser conditional comments as well:
99
101
 
@@ -118,8 +120,7 @@ You can also pass in conditions via an argument to the conditional:
118
120
 
119
121
  A lot of browsers are supported, check the code for the full listing.
120
122
 
121
- OpenGraph Helpers
122
- -----------------
123
+ ## OpenGraph Helpers
123
124
 
124
125
  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
 
@@ -150,8 +151,17 @@ There's also a helper for the html tag along with the opengraph namespaces:
150
151
 
151
152
  Note: TopHat does not include a "Like" button helper. TopHat's focus is inside the `<head>` tag.
152
153
 
153
- Note on Patches/Pull Requests
154
- -----------------------------
154
+ ## <a name="build"></a>Build Status
155
+ [![Build Status](https://secure.travis-ci.org/spagalloco/tophat.png?branch=master)][travis]
156
+
157
+ [travis]: http://travis-ci.org/spagalloco/tophat
158
+
159
+ ## <a name="dependencies"></a>Dependency Status
160
+ [![Dependency Status](https://gemnasium.com/spagalloco/tophat.png?travis)][gemnasium]
161
+
162
+ [gemnasium]: https://gemnasium.com/spagalloco/tophat
163
+
164
+ ## Contributing
155
165
 
156
166
  * Fork the project.
157
167
  * Make your feature addition or bug fix.
@@ -161,7 +171,6 @@ Note on Patches/Pull Requests
161
171
  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
162
172
  * Send me a pull request. Bonus points for topic branches.
163
173
 
164
- Copyright
165
- ---------
174
+ ## Copyright
166
175
 
167
- Copyright (c) 2011 Steve Agalloco. See LICENSE for details.
176
+ Copyright (c) 2011 Steve Agalloco. See [LICENSE](https://github.com/spagalloco/tophat/blob/master/LICENSE.md) for details.
data/lib/tophat/meta.rb CHANGED
@@ -5,11 +5,11 @@ module TopHat
5
5
  # <meta name="description" content="Description goes here." />
6
6
  def description(options={})
7
7
  if options.is_a? String
8
- @tophat_description = options
8
+ TopHat.current['description'] = options
9
9
 
10
10
  else
11
11
  options[:name] = 'description'
12
- options[:content] = @tophat_description || options.delete(:default)
12
+ options[:content] = TopHat.current['description'] || options.delete(:default)
13
13
 
14
14
  tag(:meta, options) if options[:content]
15
15
  end
@@ -19,15 +19,15 @@ module TopHat
19
19
  # <meta name="keywords" content="Keywords go here." />
20
20
  def keywords(options={})
21
21
  if options.is_a?(String)
22
- @tophat_keywords = options
22
+ TopHat.current['keywords'] = options
23
23
 
24
24
  elsif options.is_a?(Array)
25
- @tophat_keywords = options.join(', ')
25
+ TopHat.current['keywords'] = options.join(', ')
26
26
 
27
27
  else
28
28
  options[:name] = 'keywords'
29
29
  default_keywords = options.delete(:default) || []
30
- display_keywords = @tophat_keywords.blank? ? default_keywords : @tophat_keywords
30
+ display_keywords = TopHat.current['keywords'].blank? ? default_keywords : TopHat.current['keywords']
31
31
 
32
32
  # normalize the keywords
33
33
  default_keywords = default_keywords.is_a?(String) ? default_keywords.split(',') : default_keywords
@@ -41,4 +41,6 @@ module TopHat
41
41
  end
42
42
  end
43
43
  end
44
- end
44
+ end
45
+
46
+ ActionView::Base.send :include, TopHat::MetaHelper
@@ -5,49 +5,49 @@ module TopHat
5
5
  include ActionView::Helpers
6
6
 
7
7
  def initialize(options={})
8
- @app_id = options.delete(:app_id) if options && options.has_key?(:app_id)
9
- @admins = options.delete(:admins) if options && options.has_key?(:admins)
10
- @graph_data = {}
8
+ TopHat.current['app_id'] = options.delete(:app_id) if options && options.has_key?(:app_id)
9
+ TopHat.current['admins'] = options.delete(:admins) if options && options.has_key?(:admins)
10
+ TopHat.current['graph_data'] = {}
11
11
  end
12
12
 
13
13
  def merge(options={})
14
- @app_id = options.delete(:app_id) if options && options.has_key?(:app_id)
15
- @admins = options.delete(:admins) if options && options.has_key?(:admins)
14
+ TopHat.current['app_id'] = options.delete(:app_id) if options && options.has_key?(:app_id)
15
+ TopHat.current['admins'] = options.delete(:admins) if options && options.has_key?(:admins)
16
16
  end
17
17
 
18
18
  def app_id
19
- output = @app_id ? tag(:meta, :property => 'fb:app_id', :content => @app_id) : ""
19
+ output = TopHat.current['app_id'] ? tag(:meta, :property => 'fb:app_id', :content => TopHat.current['app_id']) : ""
20
20
  output << '\n' unless output.blank?
21
21
  output
22
22
  end
23
23
 
24
24
  def admins
25
- output = @admins ? tag(:meta, :property => 'fb:admins', :content => [*@admins].join(',')) : ""
25
+ output = TopHat.current['admins'] ? tag(:meta, :property => 'fb:admins', :content => [*TopHat.current['admins']].join(',')) : ""
26
26
  output << '\n' unless output.blank?
27
27
  output
28
28
  end
29
29
 
30
30
  def render_graph_data
31
31
  output = ""
32
- @graph_data.each_pair do |key, value|
32
+ TopHat.current['graph_data'].each_pair do |key, value|
33
33
  output << tag(:meta, :property => "og:#{key}", :content => value)
34
- output << '\n' if @graph_data.size > 1
34
+ output << '\n' if TopHat.current['graph_data'].size > 1
35
35
  end
36
36
  output
37
37
  end
38
38
 
39
39
  def type(t)
40
- @graph_data ||= {}
41
- @graph_data[:type] = t
40
+ TopHat.current['graph_data'] ||= {}
41
+ TopHat.current['graph_data'][:type] = t
42
42
  end
43
43
 
44
44
  def has_graph_data?
45
- @graph_data
45
+ TopHat.current['graph_data']
46
46
  end
47
47
 
48
48
  def method_missing(method, *args, &block) #:nodoc
49
- @graph_data ||= {}
50
- @graph_data[method] = args.shift
49
+ TopHat.current['graph_data'] ||= {}
50
+ TopHat.current['graph_data'][method] = args.shift
51
51
  end
52
52
 
53
53
  end
@@ -60,21 +60,23 @@ module TopHat
60
60
 
61
61
  def opengraph(options=nil, &block)
62
62
  if options.kind_of? Hash
63
- @tophat_open_graph_defaults = options
63
+ TopHat.current['open_graph_defaults'] = options
64
64
  end
65
65
  if block_given?
66
- @tophat_open_graph_generator = OpenGraphGenerator.new(@tophat_open_graph_defaults)
67
- yield(@tophat_open_graph_generator)
66
+ TopHat.current['open_graph_generator'] = OpenGraphGenerator.new(TopHat.current['open_graph_defaults'])
67
+ yield(TopHat.current['open_graph_generator'])
68
68
  else
69
- @tophat_open_graph_generator ||= OpenGraphGenerator.new
70
- @tophat_open_graph_generator.merge(@tophat_open_graph_defaults)
69
+ TopHat.current['open_graph_generator'] ||= OpenGraphGenerator.new
70
+ TopHat.current['open_graph_generator'].merge(TopHat.current['open_graph_defaults'])
71
71
  output = ""
72
- output << @tophat_open_graph_generator.app_id
73
- output << @tophat_open_graph_generator.admins
74
- output << @tophat_open_graph_generator.render_graph_data if @tophat_open_graph_generator.has_graph_data?
72
+ output << TopHat.current['open_graph_generator'].app_id
73
+ output << TopHat.current['open_graph_generator'].admins
74
+ output << TopHat.current['open_graph_generator'].render_graph_data if TopHat.current['open_graph_generator'].has_graph_data?
75
75
  output
76
76
  end
77
77
  end
78
78
 
79
79
  end
80
80
  end
81
+
82
+ ActionView::Base.send :include, TopHat::OpenGraphHelper
data/lib/tophat/robots.rb CHANGED
@@ -14,4 +14,6 @@ module TopHat
14
14
  end
15
15
 
16
16
  end
17
- end
17
+ end
18
+
19
+ ActionView::Base.send :include, TopHat::RobotsHelper
@@ -83,3 +83,5 @@ module TopHat
83
83
 
84
84
  end
85
85
  end
86
+
87
+ ActionView::Base.send :include, TopHat::StylesheetHelper
data/lib/tophat/title.rb CHANGED
@@ -12,17 +12,17 @@ module TopHat
12
12
  private
13
13
 
14
14
  def save_tophat_title(title, options)
15
- @tophat_title = title
16
- @tophat_title_options = options
15
+ TopHat.current['title'] = title
16
+ TopHat.current['title_options'] = options
17
17
  title
18
18
  end
19
19
 
20
20
  def display_tophat_title(options)
21
- options = options.merge(@tophat_title_options) unless @tophat_title_options.nil?
21
+ options = options.merge(TopHat.current['title_options']) unless TopHat.current['title_options'].nil?
22
22
 
23
23
  title_segments = []
24
24
  title_segments << options[:site] if options[:site]
25
- title_segments << (@tophat_title.blank? ? options[:default] : @tophat_title)
25
+ title_segments << (TopHat.current['title'].blank? ? options[:default] : TopHat.current['title'])
26
26
 
27
27
  title_segments.flatten! # flatten out in case the title is an array
28
28
  title_segments.compact! # clean out any nils
@@ -31,7 +31,7 @@ module TopHat
31
31
  title_segments.map! { |t| strip_tags(t) }
32
32
 
33
33
  reverse = options[:reverse]
34
- reverse = false if options[:default] && @tophat_title.blank? && options[:reverse_on_default] == false
34
+ reverse = false if options[:default] && TopHat.current['title'].blank? && options[:reverse_on_default] == false
35
35
 
36
36
  title_segments.reverse! if reverse
37
37
 
@@ -66,4 +66,6 @@ module TopHat
66
66
  prefix + separator + suffix
67
67
  end
68
68
  end
69
- end
69
+ end
70
+
71
+ ActionView::Base.send :include, TopHat::TitleHelper
@@ -1,3 +1,3 @@
1
1
  module TopHat
2
- VERSION = '1.3.1'
2
+ VERSION = '1.4.0'
3
3
  end
data/lib/tophat.rb CHANGED
@@ -1,15 +1,26 @@
1
1
  require 'action_view'
2
2
 
3
3
  module TopHat
4
- autoload :TitleHelper, 'tophat/title'
5
- autoload :MetaHelper, 'tophat/meta'
6
- autoload :StylesheetHelper, 'tophat/stylesheet'
7
- autoload :RobotsHelper, 'tophat/robots'
8
- autoload :OpenGraphHelper, 'tophat/opengraph'
4
+ extend self
5
+
6
+ def current
7
+ return Thread.current[:tophat] if Thread.current[:tophat]
8
+
9
+ reset
10
+ end
11
+
12
+ def reset
13
+ Thread.current[:tophat] = {}
14
+ end
15
+
9
16
  end
10
17
 
11
- ActionView::Base.send :include, TopHat::TitleHelper
12
- ActionView::Base.send :include, TopHat::MetaHelper
13
- ActionView::Base.send :include, TopHat::StylesheetHelper
14
- ActionView::Base.send :include, TopHat::RobotsHelper
15
- ActionView::Base.send :include, TopHat::OpenGraphHelper
18
+ require 'tophat/title'
19
+ require 'tophat/meta'
20
+ require 'tophat/stylesheet'
21
+ require 'tophat/robots'
22
+ require 'tophat/opengraph'
23
+
24
+
25
+
26
+
data/spec/spec_helper.rb CHANGED
@@ -9,6 +9,13 @@ require File.expand_path('../../lib/tophat', __FILE__)
9
9
  require 'rspec'
10
10
  require 'rails/all'
11
11
 
12
+
13
+ RSpec.configure do |config|
14
+ config.after(:each) do
15
+ TopHat.reset
16
+ end
17
+ end
18
+
12
19
  require 'action_controller/vendor/html-scanner'
13
20
 
14
21
  module HTML
data/spec/tophat_spec.rb CHANGED
@@ -70,4 +70,16 @@ describe TopHat do
70
70
  end
71
71
  end
72
72
 
73
+ describe '.current' do
74
+ it 'returns a hash' do
75
+ TopHat.current.should be_kind_of(Hash)
76
+ end
77
+
78
+ it 'allows the hash to be modified' do
79
+ TopHat.current[:title] = 'foo'
80
+
81
+ TopHat.current[:title].should eq('foo')
82
+ end
83
+ end
84
+
73
85
  end
data/tophat.gemspec CHANGED
@@ -9,20 +9,18 @@ Gem::Specification.new do |s|
9
9
  s.authors = ["Steve Agalloco"]
10
10
  s.email = ['steve.agalloco@gmail.com']
11
11
  s.homepage = "https://github.com/spagalloco/tophat"
12
- s.description = %q{simple view helpers for your layouts}
13
- s.summary = %q{simple view helpers for your layouts}
12
+ s.description = %q{Simple view helpers for your layouts}
13
+ s.summary = %q{Simple view helpers for your layouts}
14
14
 
15
15
  s.add_runtime_dependency('actionpack', '>= 3.0.0')
16
16
 
17
- s.add_development_dependency('bundler', '~> 1.0')
18
- s.add_development_dependency('rake', '~> 0.8')
19
- s.add_development_dependency('rspec', '~> 2.5.0')
20
- s.add_development_dependency('yard', '~> 0.6')
21
- s.add_development_dependency('maruku', '~> 0.6')
22
- s.add_development_dependency('simplecov', '~> 0.3')
23
- s.add_development_dependency('shoulda', '>= 0')
17
+ s.add_development_dependency('rake', '~> 0.9')
18
+ s.add_development_dependency('rspec', '~> 2.7')
19
+ s.add_development_dependency('yard', '~> 0.7')
20
+ s.add_development_dependency('rdiscount', '~> 1.6')
21
+ s.add_development_dependency('simplecov', '~> 0.5')
24
22
  s.add_development_dependency('rails', '>= 3.0.0')
25
- s.add_development_dependency('guard-rspec', '~> 0.4')
23
+ s.add_development_dependency('guard-rspec', '~> 0.5')
26
24
 
27
25
  s.files = `git ls-files`.split("\n")
28
26
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tophat
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-15 00:00:00.000000000Z
12
+ date: 2012-05-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
16
- requirement: &2157007300 !ruby/object:Gem::Requirement
16
+ requirement: &2156386200 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,87 +21,65 @@ dependencies:
21
21
  version: 3.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2157007300
25
- - !ruby/object:Gem::Dependency
26
- name: bundler
27
- requirement: &2157006800 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ~>
31
- - !ruby/object:Gem::Version
32
- version: '1.0'
33
- type: :development
34
- prerelease: false
35
- version_requirements: *2157006800
24
+ version_requirements: *2156386200
36
25
  - !ruby/object:Gem::Dependency
37
26
  name: rake
38
- requirement: &2157006340 !ruby/object:Gem::Requirement
27
+ requirement: &2156385680 !ruby/object:Gem::Requirement
39
28
  none: false
40
29
  requirements:
41
30
  - - ~>
42
31
  - !ruby/object:Gem::Version
43
- version: '0.8'
32
+ version: '0.9'
44
33
  type: :development
45
34
  prerelease: false
46
- version_requirements: *2157006340
35
+ version_requirements: *2156385680
47
36
  - !ruby/object:Gem::Dependency
48
37
  name: rspec
49
- requirement: &2157005880 !ruby/object:Gem::Requirement
38
+ requirement: &2156385220 !ruby/object:Gem::Requirement
50
39
  none: false
51
40
  requirements:
52
41
  - - ~>
53
42
  - !ruby/object:Gem::Version
54
- version: 2.5.0
43
+ version: '2.7'
55
44
  type: :development
56
45
  prerelease: false
57
- version_requirements: *2157005880
46
+ version_requirements: *2156385220
58
47
  - !ruby/object:Gem::Dependency
59
48
  name: yard
60
- requirement: &2157005420 !ruby/object:Gem::Requirement
49
+ requirement: &2156384760 !ruby/object:Gem::Requirement
61
50
  none: false
62
51
  requirements:
63
52
  - - ~>
64
53
  - !ruby/object:Gem::Version
65
- version: '0.6'
54
+ version: '0.7'
66
55
  type: :development
67
56
  prerelease: false
68
- version_requirements: *2157005420
57
+ version_requirements: *2156384760
69
58
  - !ruby/object:Gem::Dependency
70
- name: maruku
71
- requirement: &2157004960 !ruby/object:Gem::Requirement
59
+ name: rdiscount
60
+ requirement: &2156384300 !ruby/object:Gem::Requirement
72
61
  none: false
73
62
  requirements:
74
63
  - - ~>
75
64
  - !ruby/object:Gem::Version
76
- version: '0.6'
65
+ version: '1.6'
77
66
  type: :development
78
67
  prerelease: false
79
- version_requirements: *2157004960
68
+ version_requirements: *2156384300
80
69
  - !ruby/object:Gem::Dependency
81
70
  name: simplecov
82
- requirement: &2157004500 !ruby/object:Gem::Requirement
71
+ requirement: &2156383840 !ruby/object:Gem::Requirement
83
72
  none: false
84
73
  requirements:
85
74
  - - ~>
86
75
  - !ruby/object:Gem::Version
87
- version: '0.3'
88
- type: :development
89
- prerelease: false
90
- version_requirements: *2157004500
91
- - !ruby/object:Gem::Dependency
92
- name: shoulda
93
- requirement: &2157037560 !ruby/object:Gem::Requirement
94
- none: false
95
- requirements:
96
- - - ! '>='
97
- - !ruby/object:Gem::Version
98
- version: '0'
76
+ version: '0.5'
99
77
  type: :development
100
78
  prerelease: false
101
- version_requirements: *2157037560
79
+ version_requirements: *2156383840
102
80
  - !ruby/object:Gem::Dependency
103
81
  name: rails
104
- requirement: &2157037100 !ruby/object:Gem::Requirement
82
+ requirement: &2156383380 !ruby/object:Gem::Requirement
105
83
  none: false
106
84
  requirements:
107
85
  - - ! '>='
@@ -109,19 +87,19 @@ dependencies:
109
87
  version: 3.0.0
110
88
  type: :development
111
89
  prerelease: false
112
- version_requirements: *2157037100
90
+ version_requirements: *2156383380
113
91
  - !ruby/object:Gem::Dependency
114
92
  name: guard-rspec
115
- requirement: &2157036640 !ruby/object:Gem::Requirement
93
+ requirement: &2156382920 !ruby/object:Gem::Requirement
116
94
  none: false
117
95
  requirements:
118
96
  - - ~>
119
97
  - !ruby/object:Gem::Version
120
- version: '0.4'
98
+ version: '0.5'
121
99
  type: :development
122
100
  prerelease: false
123
- version_requirements: *2157036640
124
- description: simple view helpers for your layouts
101
+ version_requirements: *2156382920
102
+ description: Simple view helpers for your layouts
125
103
  email:
126
104
  - steve.agalloco@gmail.com
127
105
  executables: []
@@ -134,7 +112,7 @@ files:
134
112
  - .travis.yml
135
113
  - Gemfile
136
114
  - Guardfile
137
- - LICENSE
115
+ - LICENSE.md
138
116
  - README.md
139
117
  - Rakefile
140
118
  - lib/tophat.rb
@@ -172,10 +150,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
150
  version: '0'
173
151
  requirements: []
174
152
  rubyforge_project:
175
- rubygems_version: 1.8.6
153
+ rubygems_version: 1.8.10
176
154
  signing_key:
177
155
  specification_version: 3
178
- summary: simple view helpers for your layouts
156
+ summary: Simple view helpers for your layouts
179
157
  test_files:
180
158
  - spec/spec_helper.rb
181
159
  - spec/tophat/meta_helper_spec.rb
@@ -184,3 +162,4 @@ test_files:
184
162
  - spec/tophat/stylesheet_helper_spec.rb
185
163
  - spec/tophat/title_helper_spec.rb
186
164
  - spec/tophat_spec.rb
165
+ has_rdoc: