actionview-link_to_block 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.travis.yml +26 -0
- data/Appraisals +35 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +104 -0
- data/Rakefile +11 -0
- data/actionview-link_to_block.gemspec +23 -0
- data/changelog.md +5 -0
- data/gemfiles/actionpack_3_2.gemfile +12 -0
- data/gemfiles/actionpack_4_0.gemfile +10 -0
- data/gemfiles/actionview_4_1.gemfile +11 -0
- data/gemfiles/actionview_4_2.gemfile +12 -0
- data/gemfiles/actionview_5_0.gemfile +12 -0
- data/gemfiles/actionview_master.gemfile +12 -0
- data/lib/action_view/link_to_block/link_to_block.rb +39 -0
- data/lib/action_view/link_to_block/railtie.rb +11 -0
- data/lib/action_view/link_to_block/version.rb +5 -0
- data/lib/actionview-link_to_block.rb +2 -0
- data/test/test_actionview-link_to_block.rb +206 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 78513d3b247df49b25a51365953d46b6976d554f
|
4
|
+
data.tar.gz: 7ccc189debb210808b8fe0cffef4ee69acec2389
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 35b48cac53b2fc2c5f81947b9db468c34a240c4fefbbe367390865449c28c36e14df12f906852b1f188cc77172c6de0a848b6716f6027a115cd084f8028a7199
|
7
|
+
data.tar.gz: 0467a62c5db856a0865dc9bd24db1c8142cee1cb78ce9351efd69095684e7582f2309720e8e9f4ab250bea15a5914d131020c0fae2a89f82fa4fd42aaa5e4efb
|
data/.gitignore
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
|
19
|
+
# Ignore generated gemfile.lock by appraisal
|
20
|
+
/gemfiles/*.gemfile.lock
|
data/.travis.yml
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
language: ruby
|
2
|
+
sudo: false
|
3
|
+
rvm:
|
4
|
+
- 2.0.0
|
5
|
+
- 2.1.8
|
6
|
+
- 2.2.4
|
7
|
+
- 2.3.0
|
8
|
+
before_install:
|
9
|
+
- gem update bundler
|
10
|
+
gemfile:
|
11
|
+
- gemfiles/actionpack_3_2.gemfile
|
12
|
+
- gemfiles/actionpack_4_0.gemfile
|
13
|
+
- gemfiles/actionview_4_1.gemfile
|
14
|
+
- gemfiles/actionview_4_2.gemfile
|
15
|
+
- gemfiles/actionview_5_0.gemfile
|
16
|
+
- gemfiles/actionview_master.gemfile
|
17
|
+
matrix:
|
18
|
+
exclude:
|
19
|
+
- rvm: 2.0.0
|
20
|
+
gemfile: gemfiles/actionview_5_0.gemfile
|
21
|
+
- rvm: 2.0.0
|
22
|
+
gemfile: gemfiles/actionview_master.gemfile
|
23
|
+
- rvm: 2.1.8
|
24
|
+
gemfile: gemfiles/actionview_5_0.gemfile
|
25
|
+
- rvm: 2.1.8
|
26
|
+
gemfile: gemfiles/actionview_master.gemfile
|
data/Appraisals
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
appraise 'actionview_master' do
|
2
|
+
gem 'actionview', github: 'rails', branch: 'master'
|
3
|
+
gem 'actionpack', github: 'rails', branch: 'master'
|
4
|
+
gem 'rails-dom-testing'
|
5
|
+
end
|
6
|
+
|
7
|
+
appraise 'actionview_5_0' do
|
8
|
+
version = '~> 5.0.0.beta'
|
9
|
+
gem 'actionview', version
|
10
|
+
gem 'actionpack', version
|
11
|
+
gem 'rails-dom-testing'
|
12
|
+
end
|
13
|
+
|
14
|
+
appraise 'actionview_4_2' do
|
15
|
+
version = '~> 4.2.0'
|
16
|
+
gem 'actionview', version
|
17
|
+
gem 'actionpack', version
|
18
|
+
gem 'rails-dom-testing'
|
19
|
+
end
|
20
|
+
|
21
|
+
appraise 'actionview_4_1' do
|
22
|
+
version = '~> 4.1.0'
|
23
|
+
gem 'actionview', version
|
24
|
+
gem 'actionpack', version
|
25
|
+
end
|
26
|
+
|
27
|
+
appraise 'actionpack_4_0' do
|
28
|
+
gem 'actionpack', '>= 4.0', '< 4.1'
|
29
|
+
end
|
30
|
+
|
31
|
+
appraise 'actionpack_3_2' do
|
32
|
+
gem 'actionpack', '>= 3.2', '< 4.0'
|
33
|
+
gem 'minitest', '~> 4.7.5'
|
34
|
+
gem 'test-unit', '~> 3.0'
|
35
|
+
end
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 sanemat
|
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,104 @@
|
|
1
|
+
# Actionview::LinkToBlock
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/actionview-link_to_block.png)](http://badge.fury.io/rb/actionview-link_to_block)
|
4
|
+
[![Build Status](https://api.travis-ci.org/sanemat/actionview-link_to_block.png?branch=master)](https://travis-ci.org/sanemat/actionview-link_to_block)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/sanemat/actionview-link_to_block.png)](https://codeclimate.com/github/sanemat/actionview-link_to_block)
|
6
|
+
[![Coverage Status](https://coveralls.io/repos/sanemat/actionview-link_to_block/badge.png?branch=master)](https://coveralls.io/r/sanemat/actionview-link_to_block)
|
7
|
+
|
8
|
+
Add helper method, `link_to_block`, `link_to_block_if`, `link_to_block_unless`, `link_to_block_unless_current`.
|
9
|
+
This is symmetrical to `link_to`, `link_to_if`, `link_to_unless`, `link_to_unless_current`.
|
10
|
+
|
11
|
+
`link_to_block*` always accepts block.
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
`link_to` accepts complex html as block, like below:
|
16
|
+
|
17
|
+
<%= link_to user_path(@user) do %>
|
18
|
+
<i class="icon-ok icon-white"></i> Do it@
|
19
|
+
<% end %>
|
20
|
+
# http://stackoverflow.com/questions/9401942/using-link-to-with-embedded-html
|
21
|
+
|
22
|
+
But `link_to_if` with block behavior is below:
|
23
|
+
|
24
|
+
<%= link_to_if condition, user_path(@user) do %>
|
25
|
+
Appear if condition falsy
|
26
|
+
<% end %>
|
27
|
+
|
28
|
+
Then use `link_to_block_if` below:
|
29
|
+
|
30
|
+
<%= link_to_block_if condition, user_path(@user) do %>
|
31
|
+
<i class="icon-ok icon-white"></i> Do it@
|
32
|
+
<% end %>
|
33
|
+
|
34
|
+
#=> if condition truthy, then shows html and link, else if condition falsy, then show only html.
|
35
|
+
|
36
|
+
## Installation
|
37
|
+
|
38
|
+
Add this line to your application's Gemfile:
|
39
|
+
|
40
|
+
gem 'actionview-link_to_block'
|
41
|
+
|
42
|
+
And then execute:
|
43
|
+
|
44
|
+
$ bundle
|
45
|
+
|
46
|
+
Or install it yourself as:
|
47
|
+
|
48
|
+
$ gem install actionview-link_to_block
|
49
|
+
|
50
|
+
## Requirement
|
51
|
+
|
52
|
+
`actionview-link_to_block` has no gem dependency in gemspec, but this is not correctly.
|
53
|
+
`actionview` extracts from `actionpack` on rails4.1.
|
54
|
+
You can see `Appraisals` file and `/gemfiles` directory.
|
55
|
+
|
56
|
+
actionview master(rails master)
|
57
|
+
|
58
|
+
gem 'actionview', github: 'rails', branch: 'master'
|
59
|
+
gem 'actionpack', github: 'rails', branch: 'master'
|
60
|
+
|
61
|
+
actionview v5.0(rails v5.0)
|
62
|
+
|
63
|
+
gem 'actionview', '~> 5.0.0.beta'
|
64
|
+
gem 'actionpack', '~> 5.0.0.beta'
|
65
|
+
|
66
|
+
actionview v4.2(rails v4.2)
|
67
|
+
|
68
|
+
gem 'actionview', '~> 4.2.0'
|
69
|
+
gem 'actionpack', '~> 4.2.0'
|
70
|
+
|
71
|
+
actionview v4.1(rails v4.1)
|
72
|
+
|
73
|
+
gem 'actionpack', '~> 4.1.0'
|
74
|
+
|
75
|
+
actionpack v4.0(rails v4.0)
|
76
|
+
|
77
|
+
gem 'actionpack', '~> 4.0.0'
|
78
|
+
|
79
|
+
actionpack v3.2(rails v3.2)
|
80
|
+
|
81
|
+
gem 'actionpack', '~> 3.2.0'
|
82
|
+
|
83
|
+
## Testing
|
84
|
+
|
85
|
+
Test against actionpack v3.2, v4.0, v4.1, v4.2, v5.0, master run below:
|
86
|
+
|
87
|
+
$ bundle
|
88
|
+
$ bundle exec appraisal install
|
89
|
+
$ bundle exec appraisal rake
|
90
|
+
|
91
|
+
Test for specific version:
|
92
|
+
|
93
|
+
$ bundle exec appraisal install
|
94
|
+
$ bundle exec appraisal actionpack_4_0 rake
|
95
|
+
|
96
|
+
Prepare actionpack_3_2(gem), actionpack_4_0(gem), actionview_4_1(gem), actionview_4_2(gem), actionview_5_0(gem), actionview_master(github)
|
97
|
+
|
98
|
+
## Contributing
|
99
|
+
|
100
|
+
1. Fork it
|
101
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
102
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
103
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
104
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'action_view/link_to_block/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "actionview-link_to_block"
|
8
|
+
spec.version = ActionView::LinkToBlock::VERSION
|
9
|
+
spec.authors = ["sanemat"]
|
10
|
+
spec.email = ["o.gata.ken@gmail.com"]
|
11
|
+
spec.description = %q{Link to with block}
|
12
|
+
spec.summary = %q{Link to with block}
|
13
|
+
spec.homepage = "https://github.com/sanemat/actionview-link_to_block"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", '>= 1.3'
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "coveralls", :require=>false
|
6
|
+
gem "pry"
|
7
|
+
gem "appraisal", :github=>"thoughtbot/appraisal"
|
8
|
+
gem "actionpack", ">= 3.2", "< 4.0"
|
9
|
+
gem "minitest", "~> 4.7.5"
|
10
|
+
gem "test-unit", "~> 3.0"
|
11
|
+
|
12
|
+
gemspec :path=>".././"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "coveralls", :require=>false
|
6
|
+
gem "pry"
|
7
|
+
gem "appraisal", :github=>"thoughtbot/appraisal"
|
8
|
+
gem "actionview", "~> 4.1.0"
|
9
|
+
gem "actionpack", "~> 4.1.0"
|
10
|
+
|
11
|
+
gemspec :path=>".././"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "coveralls", :require=>false
|
6
|
+
gem "pry"
|
7
|
+
gem "appraisal", :github=>"thoughtbot/appraisal"
|
8
|
+
gem "actionview", "~> 4.2.0"
|
9
|
+
gem "actionpack", "~> 4.2.0"
|
10
|
+
gem "rails-dom-testing"
|
11
|
+
|
12
|
+
gemspec :path=>".././"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "coveralls", :require=>false
|
6
|
+
gem "pry"
|
7
|
+
gem "appraisal", :github=>"thoughtbot/appraisal"
|
8
|
+
gem "actionview", "~> 5.0.0.beta"
|
9
|
+
gem "actionpack", "~> 5.0.0.beta"
|
10
|
+
gem "rails-dom-testing"
|
11
|
+
|
12
|
+
gemspec :path=>".././"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "coveralls", :require=>false
|
6
|
+
gem "pry"
|
7
|
+
gem "appraisal", :github=>"thoughtbot/appraisal"
|
8
|
+
gem "actionview", :github=>"rails", :branch=>"master"
|
9
|
+
gem "actionpack", :github=>"rails", :branch=>"master"
|
10
|
+
gem "rails-dom-testing"
|
11
|
+
|
12
|
+
gemspec :path=>".././"
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module LinkToBlock
|
2
|
+
module ::ActionView
|
3
|
+
module Helpers
|
4
|
+
module UrlHelper
|
5
|
+
alias_method :link_to_block, :link_to
|
6
|
+
|
7
|
+
def link_to_block_unless(condition, name = nil, options = {}, html_options = {}, &block)
|
8
|
+
if condition
|
9
|
+
if block_given?
|
10
|
+
capture(&block)
|
11
|
+
else
|
12
|
+
ERB::Util.html_escape(name)
|
13
|
+
end
|
14
|
+
else
|
15
|
+
if block_given?
|
16
|
+
html_options, options = options, name
|
17
|
+
link_to capture(&block), options, html_options
|
18
|
+
else
|
19
|
+
link_to name, options, html_options
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def link_to_block_if(condition, name = nil, options = {}, html_options = {}, &block)
|
25
|
+
link_to_block_unless !condition, name, options, html_options, &block
|
26
|
+
end
|
27
|
+
|
28
|
+
def link_to_block_unless_current(name = nil, options = {}, html_options = {}, &block)
|
29
|
+
if block_given?
|
30
|
+
html_options, options = options, name
|
31
|
+
link_to_block_unless current_page?(options), options, html_options, &block
|
32
|
+
else
|
33
|
+
link_to_block_unless current_page?(options), name, options, html_options
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module ActionView
|
2
|
+
module LinkToBlock
|
3
|
+
class Railtie < ::Rails::Railtie
|
4
|
+
initializer 'actionview-link_to_block' do |app|
|
5
|
+
ActiveSupport.on_load(:action_view) do
|
6
|
+
require 'action_view/link_to_block/actionview-link_to_block'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,206 @@
|
|
1
|
+
#coding: utf-8
|
2
|
+
require 'coveralls'
|
3
|
+
Coveralls.wear!
|
4
|
+
|
5
|
+
require 'active_support/version'
|
6
|
+
autorun_path = Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("4.0")\
|
7
|
+
? 'minitest/autorun'
|
8
|
+
: 'active_support/testing/autorun'
|
9
|
+
require autorun_path
|
10
|
+
require 'action_controller'
|
11
|
+
require 'action_view'
|
12
|
+
require 'action_view/link_to_block/link_to_block'
|
13
|
+
require 'action_dispatch'
|
14
|
+
require 'rails-dom-testing' if Gem::Version.new(ActionPack::VERSION::STRING) >= Gem::Version.new("4.2")
|
15
|
+
|
16
|
+
# copy from action_view/test/abstract_unit.rb
|
17
|
+
module RenderERBUtils
|
18
|
+
def view
|
19
|
+
@view ||= begin
|
20
|
+
path = ActionView::FileSystemResolver.new(FIXTURE_LOAD_PATH)
|
21
|
+
view_paths = ActionView::PathSet.new([path])
|
22
|
+
ActionView::Base.new(view_paths)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def render_erb(string)
|
27
|
+
@virtual_path = nil
|
28
|
+
|
29
|
+
template = ActionView::Template.new(
|
30
|
+
string.strip,
|
31
|
+
"test template",
|
32
|
+
ActionView::Template::Handlers::ERB,
|
33
|
+
{})
|
34
|
+
|
35
|
+
template.render(self, {}).strip
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class LinkToBlockTest < ActiveSupport::TestCase
|
40
|
+
attr_accessor :controller, :request
|
41
|
+
|
42
|
+
routes = ActionDispatch::Routing::RouteSet.new
|
43
|
+
routes.draw do
|
44
|
+
get "/" => "foo#bar"
|
45
|
+
get "/other" => "foo#other"
|
46
|
+
get "/article/:id" => "foo#article", :as => :article
|
47
|
+
end
|
48
|
+
|
49
|
+
include ActionView::Helpers::UrlHelper
|
50
|
+
include routes.url_helpers
|
51
|
+
|
52
|
+
dom_assertion = Gem::Version.new(ActionPack::VERSION::STRING) < Gem::Version.new("4.2")\
|
53
|
+
? ActionDispatch::Assertions::DomAssertions
|
54
|
+
: Rails::Dom::Testing::Assertions::DomAssertions
|
55
|
+
|
56
|
+
include dom_assertion
|
57
|
+
include ActionView::Context
|
58
|
+
include RenderERBUtils
|
59
|
+
|
60
|
+
def hash_for(options = {})
|
61
|
+
{ controller: "foo", action: "bar" }.merge!(options)
|
62
|
+
end
|
63
|
+
alias url_hash hash_for
|
64
|
+
|
65
|
+
def test_initialization
|
66
|
+
[:link_to_block].each do |method|
|
67
|
+
assert_includes ActionView::Helpers::UrlHelper.instance_methods, method
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_link_tag_with_straight_url
|
72
|
+
assert_dom_equal %{<a href="http://www.example.com">Hello</a>}, link_to_block("Hello", "http://www.example.com")
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_link_tag_without_host_option
|
76
|
+
assert_dom_equal(%{<a href="/">Test Link</a>}, link_to_block('Test Link', url_hash))
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_link_tag_with_host_option
|
80
|
+
hash = hash_for(host: "www.example.com")
|
81
|
+
expected = %{<a href="http://www.example.com/">Test Link</a>}
|
82
|
+
assert_dom_equal(expected, link_to_block('Test Link', hash))
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_link_tag_with_query
|
86
|
+
expected = %{<a href="http://www.example.com?q1=v1&q2=v2">Hello</a>}
|
87
|
+
assert_dom_equal expected, link_to_block("Hello", "http://www.example.com?q1=v1&q2=v2")
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_link_tag_with_query_and_no_name
|
91
|
+
expected = %{<a href="http://www.example.com?q1=v1&q2=v2">http://www.example.com?q1=v1&q2=v2</a>}
|
92
|
+
assert_dom_equal expected, link_to_block(nil, "http://www.example.com?q1=v1&q2=v2")
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_link_tag_with_block
|
96
|
+
assert_dom_equal %{<a href="/"><span>Example site</span></a>},
|
97
|
+
link_to_block('/') { content_tag(:span, 'Example site') }
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_link_tag_with_block_and_html_options
|
101
|
+
assert_dom_equal %{<a class="special" href="/"><span>Example site</span></a>},
|
102
|
+
link_to_block('/', class: "special") { content_tag(:span, 'Example site') }
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_link_tag_using_block_in_erb
|
106
|
+
out = render_erb %{<%= link_to_block('/') do %>Example site<% end %>}
|
107
|
+
assert_equal '<a href="/">Example site</a>', out
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_link_tag_with_html_safe_string
|
111
|
+
assert_dom_equal(
|
112
|
+
%{<a href="/article/Gerd_M%C3%BCller">Gerd Müller</a>},
|
113
|
+
link_to_block("Gerd Müller", article_path("Gerd_Müller".html_safe))
|
114
|
+
)
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_link_tag_escapes_content
|
118
|
+
assert_dom_equal %{<a href="/">Malicious <script>content</script></a>},
|
119
|
+
link_to_block("Malicious <script>content</script>", "/")
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_link_tag_does_not_escape_html_safe_content
|
123
|
+
assert_dom_equal %{<a href="/">Malicious <script>content</script></a>},
|
124
|
+
link_to_block("Malicious <script>content</script>".html_safe, "/")
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_link_to_unless
|
128
|
+
assert_equal "Showing", link_to_block_unless(true, "Showing", url_hash)
|
129
|
+
|
130
|
+
assert_dom_equal %{<a href="/">Listing</a>},
|
131
|
+
link_to_block_unless(false, "Listing", url_hash)
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_link_tag_unless_with_block
|
135
|
+
assert_dom_equal %{<a href="/"><span>Example site</span></a>},
|
136
|
+
link_to_block_unless(false, '/') { content_tag(:span, 'Example site') }
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_link_tag_unless_with_block_and_html_options
|
140
|
+
assert_dom_equal %{<a class="special" href="/"><span>Example site</span></a>},
|
141
|
+
link_to_block_unless(false, '/', class: "special") { content_tag(:span, 'Example site') }
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_link_tag_unless_using_block_in_erb
|
145
|
+
out = render_erb %{<%= link_to_block_unless(false, '/') do %>Example site<% end %>}
|
146
|
+
assert_equal '<a href="/">Example site</a>', out
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_link_to_block_if
|
150
|
+
assert_equal "Showing", link_to_block_if(false, "Showing", url_hash)
|
151
|
+
assert_dom_equal %{<a href="/">Listing</a>}, link_to_block_if(true, "Listing", url_hash)
|
152
|
+
end
|
153
|
+
|
154
|
+
def request_for_url(url, opts = {})
|
155
|
+
env = Rack::MockRequest.env_for("http://www.example.com#{url}", opts)
|
156
|
+
ActionDispatch::Request.new(env)
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_link_unless_current
|
160
|
+
@request = request_for_url("/")
|
161
|
+
|
162
|
+
assert_equal "Showing",
|
163
|
+
link_to_block_unless_current("Showing", url_hash)
|
164
|
+
assert_equal "Showing",
|
165
|
+
link_to_block_unless_current("Showing", "http://www.example.com/")
|
166
|
+
assert_equal %{<span>Example site</span>},
|
167
|
+
link_to_block_unless_current(url_hash) { content_tag(:span, 'Example site') }
|
168
|
+
|
169
|
+
@request = request_for_url("/?order=desc")
|
170
|
+
|
171
|
+
assert_equal "Showing",
|
172
|
+
link_to_block_unless_current("Showing", url_hash)
|
173
|
+
assert_equal "Showing",
|
174
|
+
link_to_block_unless_current("Showing", "http://www.example.com/")
|
175
|
+
|
176
|
+
@request = request_for_url("/?order=desc&page=1")
|
177
|
+
|
178
|
+
assert_equal "Showing",
|
179
|
+
link_to_block_unless_current("Showing", hash_for(order: 'desc', page: '1'))
|
180
|
+
assert_equal "Showing",
|
181
|
+
link_to_block_unless_current("Showing", "http://www.example.com/?order=desc&page=1")
|
182
|
+
|
183
|
+
@request = request_for_url("/?order=desc")
|
184
|
+
|
185
|
+
assert_equal %{<a href="/?order=asc">Showing</a>},
|
186
|
+
link_to_block_unless_current("Showing", hash_for(order: :asc))
|
187
|
+
assert_equal %{<a href="http://www.example.com/?order=asc">Showing</a>},
|
188
|
+
link_to_block_unless_current("Showing", "http://www.example.com/?order=asc")
|
189
|
+
|
190
|
+
@request = request_for_url("/?order=desc")
|
191
|
+
assert_equal %{<a href="/?order=desc&page=2\">Showing</a>},
|
192
|
+
link_to_block_unless_current("Showing", hash_for(order: "desc", page: 2))
|
193
|
+
assert_equal %{<a href="http://www.example.com/?order=desc&page=2">Showing</a>},
|
194
|
+
link_to_block_unless_current("Showing", "http://www.example.com/?order=desc&page=2")
|
195
|
+
|
196
|
+
@request = request_for_url("/show")
|
197
|
+
|
198
|
+
assert_equal %{<a href="/">Listing</a>},
|
199
|
+
link_to_block_unless_current("Listing", url_hash)
|
200
|
+
assert_equal %{<a href="http://www.example.com/">Listing</a>},
|
201
|
+
link_to_block_unless_current("Listing", "http://www.example.com/")
|
202
|
+
assert_equal %{<a href="/"><span>Example site</span></a>},
|
203
|
+
link_to_block_unless_current(url_hash) { content_tag(:span, 'Example site') }
|
204
|
+
end
|
205
|
+
|
206
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: actionview-link_to_block
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- sanemat
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Link to with block
|
42
|
+
email:
|
43
|
+
- o.gata.ken@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".travis.yml"
|
50
|
+
- Appraisals
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- actionview-link_to_block.gemspec
|
56
|
+
- changelog.md
|
57
|
+
- gemfiles/actionpack_3_2.gemfile
|
58
|
+
- gemfiles/actionpack_4_0.gemfile
|
59
|
+
- gemfiles/actionview_4_1.gemfile
|
60
|
+
- gemfiles/actionview_4_2.gemfile
|
61
|
+
- gemfiles/actionview_5_0.gemfile
|
62
|
+
- gemfiles/actionview_master.gemfile
|
63
|
+
- lib/action_view/link_to_block/link_to_block.rb
|
64
|
+
- lib/action_view/link_to_block/railtie.rb
|
65
|
+
- lib/action_view/link_to_block/version.rb
|
66
|
+
- lib/actionview-link_to_block.rb
|
67
|
+
- test/test_actionview-link_to_block.rb
|
68
|
+
homepage: https://github.com/sanemat/actionview-link_to_block
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata: {}
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 2.5.1
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: Link to with block
|
92
|
+
test_files:
|
93
|
+
- test/test_actionview-link_to_block.rb
|