link_to_only_valid_path 0.9.3
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.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +57 -0
- data/Rakefile +1 -0
- data/lib/link_to_only_valid_path.rb +9 -0
- data/lib/link_to_only_valid_path/helper.rb +33 -0
- data/lib/link_to_only_valid_path/version.rb +3 -0
- data/link_to_only_valid_path.gemspec +21 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ec049b3be58bf9f19a8cfd3217b7b09d4029b010
|
4
|
+
data.tar.gz: cf43778f30af53390a4ed519a3183ea4b6aa8bd2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 15f7990c52522eed9be4b13ddef55e5f389619d5b87ca4177e12b8590ee27405c417b959f19f2c5eea7dfc057547949fdb5770dc0b0cde05b37a0010ee0a366b
|
7
|
+
data.tar.gz: 3f459d44697fc42d61502b9fb89fd088a20951c153c543c102e3610c0be994394b4259177fcfe14d181550e4dfc39dff93446b9fe5c45c3af84ffb8f75656cb6
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 shimada
|
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,57 @@
|
|
1
|
+
# LinkToOnlyValidPath
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
gem 'link_to_only_valid_path'
|
8
|
+
|
9
|
+
And then execute:
|
10
|
+
|
11
|
+
$ bundle install
|
12
|
+
|
13
|
+
Or install it yourself as:
|
14
|
+
|
15
|
+
$ gem install link_to_only_valid_path
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
In your views, you can use 'link_to_only_valid_path' helper. This helper is similar to 'link_to' helper.
|
20
|
+
|
21
|
+
<%= link_to_only_valid_path name, url, options %>
|
22
|
+
|
23
|
+
This helper return a link tag if url is "http://...", "https://...", or valid routings (by default), otherwise this helper return name.
|
24
|
+
|
25
|
+
:examples
|
26
|
+
|
27
|
+
<%= link_to_only_valid_path "Example1", "http://example.com" %>
|
28
|
+
#=> <a href="http://example.com">Example1</a>
|
29
|
+
<%= link_to_only_valid_path "Example2", "http://example.com" { :class => "btn" } %>
|
30
|
+
#=> <a href="http://example.com" class="btn">Example2</a>
|
31
|
+
<%= link_to_only_valid_path "Example3", disable_routing_path %>
|
32
|
+
#=> "Example3"
|
33
|
+
<%= link_to_only_valid_path enable_routing_path do %>
|
34
|
+
<div>innert element</div>
|
35
|
+
<% end %>
|
36
|
+
#=> <a href="[enable_routing_path]"><div>inner element</div></a>
|
37
|
+
<%= link_to_only_valid_path disable_routing_path %>
|
38
|
+
<div>inner element</div>
|
39
|
+
<% end %>
|
40
|
+
#=> <div>inner element</div> # If the url disable, ignore a link tag.
|
41
|
+
|
42
|
+
If you want to enable other protocols, you set a :accepts_protocols option.
|
43
|
+
|
44
|
+
:examples
|
45
|
+
|
46
|
+
<%= link_to_only_valid_path "FTP Example1", "ftp://example.com" %>
|
47
|
+
#=> "FTP Example1"
|
48
|
+
<%= link_to_only_valid_path "FTP Example2", "ftp://example.com", { :accept_protocols => [:ftp] } %>
|
49
|
+
#=> <a href="ftp://example.com">FTP Example2</a>
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
1. Fork it
|
54
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
55
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
56
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
57
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module LinkToOnlyValidPath
|
2
|
+
module Helper
|
3
|
+
def link_to_only_valid_path(*args, &block)
|
4
|
+
if block_given?
|
5
|
+
options = args.first || {}
|
6
|
+
html_options = args.second
|
7
|
+
link_to_only_valid_path(capture(&block), options, html_options)
|
8
|
+
else
|
9
|
+
accepts = ['http', 'https']
|
10
|
+
if args[2]
|
11
|
+
args[2].stringify_keys!
|
12
|
+
if args[2].key?('accept_protocols')
|
13
|
+
accepts = args[2]['accept_protocols'].map{ |protocol| protocol.to_s }
|
14
|
+
args[2].delete('accept_protocols')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
return link_to_if(valid_path?(args.second, accepts), *args)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def valid_path?(path, accept_protocols)
|
23
|
+
accept_protocols.each do |protocol|
|
24
|
+
if path =~ /^#{protocol}:\/\//
|
25
|
+
return true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
all_routes = eval(Rails.application.class.parent_name)::Application.routes.routes
|
30
|
+
return all_routes.map{ |route| route.path.match(path).present? }.include?(true)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'link_to_only_valid_path/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "link_to_only_valid_path"
|
8
|
+
gem.version = LinkToOnlyValidPath::VERSION
|
9
|
+
gem.authors = ["kyohei shimada"]
|
10
|
+
gem.email = ["fl95to03pj30sq12@gmail.com"]
|
11
|
+
gem.description = %q{link to only valid path}
|
12
|
+
gem.summary = %q{link to only valid path}
|
13
|
+
gem.homepage = "https://github.com/wishid/link_to_only_valid_path"
|
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
|
+
|
20
|
+
gem.add_dependency "rails", "~> 3.2.9"
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: link_to_only_valid_path
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kyohei shimada
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.2.9
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.2.9
|
27
|
+
description: link to only valid path
|
28
|
+
email:
|
29
|
+
- fl95to03pj30sq12@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- Gemfile
|
36
|
+
- LICENSE.txt
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- lib/link_to_only_valid_path.rb
|
40
|
+
- lib/link_to_only_valid_path/helper.rb
|
41
|
+
- lib/link_to_only_valid_path/version.rb
|
42
|
+
- link_to_only_valid_path.gemspec
|
43
|
+
homepage: https://github.com/wishid/link_to_only_valid_path
|
44
|
+
licenses: []
|
45
|
+
metadata: {}
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 2.2.2
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: link to only valid path
|
66
|
+
test_files: []
|