clear_helper 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rvmrc +1 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +9 -0
- data/clear_helper.gemspec +19 -0
- data/lib/clear_helper.rb +33 -0
- data/lib/clear_helper/version.rb +3 -0
- data/test/test_clear_helper.rb +22 -0
- metadata +65 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use @rubygems
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Philip Hallstrom
|
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,47 @@
|
|
1
|
+
# ClearHelper
|
2
|
+
|
3
|
+
ClearHelper is a simple method helper to make creating a "cleared" div
|
4
|
+
simple and consistent across platforms. You can specify whether you want to
|
5
|
+
clear 'both', 'left', or 'right' and set the height of the div in any unit you
|
6
|
+
want (defaults to pixels).
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'clear_helper'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install clear_helper
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
<%= clear %>
|
25
|
+
<div style="clear:both; height: 0; max-height: 0; line-height: 0;"> </div>
|
26
|
+
|
27
|
+
<%= clear(:left) %>
|
28
|
+
<div style="clear:left; height: 0px; max-height: 0px; line-height: 0px;"> </div>
|
29
|
+
|
30
|
+
Failure to specify the unit for the height will default to 'px'.
|
31
|
+
|
32
|
+
<%= clear(:right, 10) %>
|
33
|
+
<div style="clear:left; height: 10px; max-height: 10px; line-height: 10px;"> </div>
|
34
|
+
|
35
|
+
If the first value is not one of 'both', 'left', or 'right' it will be assumed to be the height
|
36
|
+
and will default to 'both'.
|
37
|
+
|
38
|
+
<%= clear('2.5em') %>
|
39
|
+
<div style="clear:both; height: 2.5em; max-height: 2.5em; line-height: 2.5em;"> </div>
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'clear_helper/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "clear_helper"
|
8
|
+
gem.version = ClearHelper::VERSION
|
9
|
+
gem.authors = ["Philip Hallstrom"]
|
10
|
+
gem.email = ["philip@pjkh.com"]
|
11
|
+
gem.description = %q{A Rails helper method to simplify generation of "clear" divs}
|
12
|
+
gem.summary = %q{ClearHelper is a simple method helper to make creating a "cleared" div simple and consistent across platforms. You can specify whether you want to clear 'both', 'left', or 'right' and set the height of the div in any unit you want (defaults to pixels)}
|
13
|
+
gem.homepage = "https://github.com/phallstrom/clear_helper"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
data/lib/clear_helper.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "clear_helper/version"
|
2
|
+
|
3
|
+
module ClearHelper
|
4
|
+
module TagHelper
|
5
|
+
|
6
|
+
def clear(clear = 'both', height = '0')
|
7
|
+
options = {}
|
8
|
+
if clear.is_a?(Hash)
|
9
|
+
options = clear.stringify_keys.reverse_merge!('clear' => 'both', 'height' => '0')
|
10
|
+
else
|
11
|
+
unless %w[left right both].include?(clear.to_s)
|
12
|
+
height = clear
|
13
|
+
clear = 'both'
|
14
|
+
end
|
15
|
+
options['height'] = height
|
16
|
+
options['clear'] = clear
|
17
|
+
end
|
18
|
+
if options['height'].to_i.to_s == options['height'].to_s
|
19
|
+
options['height'] = "#{options['height']}px" unless options['height'].to_s == '0'
|
20
|
+
end
|
21
|
+
|
22
|
+
options.reverse_merge!('max-height' => options['height'],
|
23
|
+
'font-size' => options['height'],
|
24
|
+
'line-height' => options['height'])
|
25
|
+
|
26
|
+
# the sort is really just so the tests pass easily
|
27
|
+
%Q{<div style="#{options.map {|e| "#{e.first}: #{e.last}" }.sort.join('; ')}"> </div>}.try(:html_safe)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
ActionView::Base.send :include, ClearHelper::TagHelper
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'action_controller'
|
4
|
+
require 'clear_helper'
|
5
|
+
|
6
|
+
class ClearHelperTest < Test::Unit::TestCase
|
7
|
+
include ActionView::Helpers::TagHelper
|
8
|
+
include ClearHelper::TagHelper
|
9
|
+
|
10
|
+
def test_clear_helper
|
11
|
+
assert_equal '<div style="clear: both; font-size: 0; height: 0; line-height: 0; max-height: 0"> </div>', clear
|
12
|
+
assert_equal '<div style="clear: left; font-size: 0; height: 0; line-height: 0; max-height: 0"> </div>', clear(:left)
|
13
|
+
assert_equal '<div style="clear: left; font-size: 0; height: 0; line-height: 0; max-height: 0"> </div>', clear('left')
|
14
|
+
assert_equal '<div style="clear: right; font-size: 10px; height: 10px; line-height: 10px; max-height: 10px"> </div>', clear(:right, 10)
|
15
|
+
assert_equal '<div style="clear: both; font-size: 2.5em; height: 2.5em; line-height: 2.5em; max-height: 2.5em"> </div>', clear('2.5em')
|
16
|
+
assert_equal '<div style="clear: both; font-size: 5px; height: 5px; line-height: 5px; max-height: 5px"> </div>', clear(5)
|
17
|
+
assert_equal '<div style="clear: both; font-size: 0; height: 0; line-height: 0; max-height: 0"> </div>', clear(:clear => :both)
|
18
|
+
assert_equal '<div style="clear: both; font-size: 0; height: 0; line-height: 0; max-height: 0"> </div>', clear(:clear => :both)
|
19
|
+
assert_equal '<div style="clear: both; font-size: 5px; height: 5px; line-height: 5px; max-height: 5px; width: 99%"> </div>', clear(:clear => :both, :height => 5, :width => '99%')
|
20
|
+
assert_equal '<div style="clear: both; font-size: 0; height: 0; line-height: 0; max-height: 0; width: 99%"> </div>', clear(:width => '99%')
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: clear_helper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Philip Hallstrom
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-09 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A Rails helper method to simplify generation of "clear" divs
|
15
|
+
email:
|
16
|
+
- philip@pjkh.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- .rvmrc
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- clear_helper.gemspec
|
28
|
+
- lib/clear_helper.rb
|
29
|
+
- lib/clear_helper/version.rb
|
30
|
+
- test/test_clear_helper.rb
|
31
|
+
homepage: https://github.com/phallstrom/clear_helper
|
32
|
+
licenses: []
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
hash: -3985196232265350545
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
segments:
|
53
|
+
- 0
|
54
|
+
hash: -3985196232265350545
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.8.24
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: ClearHelper is a simple method helper to make creating a "cleared" div simple
|
61
|
+
and consistent across platforms. You can specify whether you want to clear 'both',
|
62
|
+
'left', or 'right' and set the height of the div in any unit you want (defaults
|
63
|
+
to pixels)
|
64
|
+
test_files:
|
65
|
+
- test/test_clear_helper.rb
|