icon_link 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/.rspec +1 -0
- data/.travis.yml +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +7 -0
- data/icon_link.gemspec +23 -0
- data/lib/icon_link/railtie.rb +9 -0
- data/lib/icon_link/version.rb +3 -0
- data/lib/icon_link/view_helpers.rb +41 -0
- data/lib/icon_link.rb +3 -0
- data/spec/icon_link/icon_link_spec.rb +80 -0
- data/spec/spec_helper.rb +13 -0
- metadata +126 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 NorOddSto
|
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,45 @@
|
|
1
|
+
# IconLink [](https://travis-ci.org/noroddsto/icon_link)
|
2
|
+
|
3
|
+
View helper methods that makes it easy to add the html that is needed to display icons (from Font Awesome or Twitter Bootstrap) within links, or buttons.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'icon_link', git: 'git://github.com/noroddsto/icon_link.git'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
Link with icon:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
icon_link_to("Example", "http://www.example.com", icon: "comment-icon")
|
21
|
+
# => <a href="http://www.example.com" class="btn"><i class="icon-comment"></i> Title</a>
|
22
|
+
```
|
23
|
+
Button with icon:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
icon_button_tag("Example", icon: "comment-icon")
|
27
|
+
# => <button class="btn" type="submit"><i class="icon-comment"></i> Create model</button>
|
28
|
+
```
|
29
|
+
|
30
|
+
Text with icon:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
iconize("Example", icon: "comment-icon")
|
34
|
+
# => <i class="icon-comment"></i> Title
|
35
|
+
```
|
36
|
+
|
37
|
+
See documentation: [rubydoc](http://rubydoc.info/github/noroddsto/icon_link/master/frames)
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/icon_link.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'icon_link/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "icon_link"
|
8
|
+
gem.version = IconLink::VERSION
|
9
|
+
gem.authors = ["NorOddSto"]
|
10
|
+
gem.email = ["oddgeir@kjorren.com"]
|
11
|
+
gem.description = %q{ View helper methods that makes it easy adding icons to links and buttons. Meant to be used with Font Awesome or Twitter Bootstrap.}
|
12
|
+
gem.summary = %q{ Helper methods for adding icon to links and submit buttons }
|
13
|
+
gem.homepage = ""
|
14
|
+
gem.files = `git ls-files`.split($/)
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
|
19
|
+
gem.add_development_dependency "rspec"
|
20
|
+
gem.add_development_dependency "rake"
|
21
|
+
gem.add_development_dependency "capybara"
|
22
|
+
gem.add_development_dependency('actionpack', '~> 3.0')
|
23
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module IconLink
|
2
|
+
module ViewHelpers
|
3
|
+
|
4
|
+
# Creates a button tag with the given +title+ to the given +url+. Works like button_tag,
|
5
|
+
# but takes an additional :icon option. Type is set to submit by default.
|
6
|
+
#
|
7
|
+
# ==== Examples
|
8
|
+
# icon_button_tag("Example", icon: "comment-icon")
|
9
|
+
# # => <button class="btn" type="submit"><i class="icon-comment"></i> Create model</button>
|
10
|
+
def icon_button_tag(title, options={})
|
11
|
+
options[:type] ||= 'submit'
|
12
|
+
button_tag options.merge(icon: nil) do
|
13
|
+
iconize(title, options[:icon])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Creates a link tag with the given +title+ to the given +url+. Works like link_to,
|
18
|
+
# but takes an additional :icon option.
|
19
|
+
#
|
20
|
+
# ==== Examples
|
21
|
+
# icon_link_to("Example", "http://www.example.com", icon: "comment-icon")
|
22
|
+
# # => <a href="http://www.example.com" class="btn"><i class="icon-comment"></i> Title</a>
|
23
|
+
def icon_link_to(title, url, options = {})
|
24
|
+
link = link_to(iconize(title, options[:icon]), url, options.merge(icon: nil))
|
25
|
+
end
|
26
|
+
|
27
|
+
# Adds icon to a given text
|
28
|
+
#
|
29
|
+
# ==== Examples
|
30
|
+
# iconize("Example", icon: "comment-icon")
|
31
|
+
# # => <i class="icon-comment"></i> Title
|
32
|
+
def iconize(text, icon = nil)
|
33
|
+
if icon.to_s.empty?
|
34
|
+
text
|
35
|
+
else
|
36
|
+
content_tag(:i, nil, class: icon) + " " + text
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
data/lib/icon_link.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe IconLink::ViewHelpers do
|
5
|
+
describe "iconize" do
|
6
|
+
let(:title){ "Title" }
|
7
|
+
|
8
|
+
describe "when icon present" do
|
9
|
+
let(:icon){ "icon-comment" }
|
10
|
+
let(:result){ iconize(title, icon) }
|
11
|
+
|
12
|
+
it "should have the right title" do
|
13
|
+
result.should =~ /\s#{title}/
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have the right html" do
|
17
|
+
result.should have_xpath("//i[@class='#{icon}']")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "when icon not present" do
|
22
|
+
let(:result){ iconize(title) }
|
23
|
+
|
24
|
+
it "should have the right title" do
|
25
|
+
result.should =~ /\A#{title}/
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should have the right html" do
|
29
|
+
result.should_not have_xpath("//i")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "icon_button_tag" do
|
35
|
+
let(:title){ "Create model"}
|
36
|
+
let(:options){ {icon: "icon-comment", class: "btn"} }
|
37
|
+
let(:result){ icon_button_tag(title, options) }
|
38
|
+
|
39
|
+
it "should have the right title" do
|
40
|
+
result.should have_xpath("//button[text()=' #{title}']")
|
41
|
+
end
|
42
|
+
it "should have the right class" do
|
43
|
+
result.should have_xpath("//button[@class='btn']")
|
44
|
+
end
|
45
|
+
it "should have the right icon" do
|
46
|
+
result.should have_xpath("//button/i[@class='icon-comment']")
|
47
|
+
end
|
48
|
+
it "should be a submit button by default" do
|
49
|
+
result.should have_xpath("//button[@type='submit']")
|
50
|
+
end
|
51
|
+
it "should handle when icon is nil" do
|
52
|
+
result_when_icon_nil = icon_button_tag(title)
|
53
|
+
result_when_icon_nil.should have_xpath("//button[text()='#{title}']")
|
54
|
+
result_when_icon_nil.should_not have_xpath("//button/i")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "icon_link_to" do
|
59
|
+
let(:title){ "Title"}
|
60
|
+
let(:url){ "http://www.example.com"}
|
61
|
+
let(:options){ {icon: "icon-comment", class: "btn"} }
|
62
|
+
let(:result){ icon_link_to(title, url, options) }
|
63
|
+
|
64
|
+
it "should have the right title" do
|
65
|
+
result.should have_xpath("//a[text()=' #{title}' and @href='#{url}']")
|
66
|
+
end
|
67
|
+
it "should have the right class" do
|
68
|
+
result.should have_xpath("//a[@class='btn']")
|
69
|
+
end
|
70
|
+
it "should have the right icon" do
|
71
|
+
result.should have_xpath("//a/i[@class='icon-comment']")
|
72
|
+
end
|
73
|
+
it "should handle when icon is nil" do
|
74
|
+
result_when_icon_nil = icon_link_to(title, url)
|
75
|
+
result_when_icon_nil.should have_xpath("//a[text()='#{title}' and @href='#{url}']")
|
76
|
+
result_when_icon_nil.should_not have_xpath("//button/i")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'action_view'
|
2
|
+
require 'icon_link'
|
3
|
+
require 'capybara/rspec'
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
include ActionView::Helpers::UrlHelper
|
7
|
+
include ActionView::Helpers::FormTagHelper
|
8
|
+
include ActionView::Context
|
9
|
+
include IconLink::ViewHelpers
|
10
|
+
|
11
|
+
config.include Capybara::RSpecMatchers, example_group: {file_path: %r{spec/icon_link}}
|
12
|
+
end
|
13
|
+
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: icon_link
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- NorOddSto
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
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: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
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: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: capybara
|
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: actionpack
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.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: '3.0'
|
78
|
+
description: ! ' View helper methods that makes it easy adding icons to links and
|
79
|
+
buttons. Meant to be used with Font Awesome or Twitter Bootstrap.'
|
80
|
+
email:
|
81
|
+
- oddgeir@kjorren.com
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- .rspec
|
88
|
+
- .travis.yml
|
89
|
+
- Gemfile
|
90
|
+
- LICENSE.txt
|
91
|
+
- README.md
|
92
|
+
- Rakefile
|
93
|
+
- icon_link.gemspec
|
94
|
+
- lib/icon_link.rb
|
95
|
+
- lib/icon_link/railtie.rb
|
96
|
+
- lib/icon_link/version.rb
|
97
|
+
- lib/icon_link/view_helpers.rb
|
98
|
+
- spec/icon_link/icon_link_spec.rb
|
99
|
+
- spec/spec_helper.rb
|
100
|
+
homepage: ''
|
101
|
+
licenses: []
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 1.8.23
|
121
|
+
signing_key:
|
122
|
+
specification_version: 3
|
123
|
+
summary: Helper methods for adding icon to links and submit buttons
|
124
|
+
test_files:
|
125
|
+
- spec/icon_link/icon_link_spec.rb
|
126
|
+
- spec/spec_helper.rb
|