rails_join 1.0.0
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/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +30 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +37 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/lib/rails_join.rb +16 -0
- data/spec/perf.rb +6 -0
- data/spec/rails_join_spec.rb +39 -0
- data/spec/spec_helper.rb +12 -0
- metadata +106 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
gem "activesupport", ">= 3.0.0"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.3.0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.6.4"
|
12
|
+
# gem "rcov", ">= 0"
|
13
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.1.3)
|
5
|
+
multi_json (~> 1.0)
|
6
|
+
diff-lcs (1.1.3)
|
7
|
+
git (1.2.5)
|
8
|
+
jeweler (1.6.4)
|
9
|
+
bundler (~> 1.0)
|
10
|
+
git (>= 1.2.5)
|
11
|
+
rake
|
12
|
+
multi_json (1.0.4)
|
13
|
+
rake (0.9.2.2)
|
14
|
+
rspec (2.3.0)
|
15
|
+
rspec-core (~> 2.3.0)
|
16
|
+
rspec-expectations (~> 2.3.0)
|
17
|
+
rspec-mocks (~> 2.3.0)
|
18
|
+
rspec-core (2.3.1)
|
19
|
+
rspec-expectations (2.3.0)
|
20
|
+
diff-lcs (~> 1.1.2)
|
21
|
+
rspec-mocks (2.3.0)
|
22
|
+
|
23
|
+
PLATFORMS
|
24
|
+
ruby
|
25
|
+
|
26
|
+
DEPENDENCIES
|
27
|
+
activesupport (>= 3.0.0)
|
28
|
+
bundler (~> 1.0.0)
|
29
|
+
jeweler (~> 1.6.4)
|
30
|
+
rspec (~> 2.3.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Marc-Andre Lafortune
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
= rails_join
|
2
|
+
|
3
|
+
Doing a `join` on an array containing html safe strings will produce an html unsafe string.
|
4
|
+
|
5
|
+
Rails provides a helper called `safe_join` that will always produce an html safe string.
|
6
|
+
|
7
|
+
This gem modifies `Array#join` so that it returns an html safe string when the first element is an html safe string. This is similar to `s1 + s2` returning an html safe string if and only if `s1` is html safe. If the first element is not an html safe string (or does not exist), then `Array#join` returns a normal string, as was previously the case. Again, this is similar to `s1 + s2` returning a normal string if `s1` is a normal string, even if `s2` is an html safe string.
|
8
|
+
|
9
|
+
links = [link_to("Home", "/"), link_to("Profile", "/profile")]
|
10
|
+
desired = links[0] + " > " + links[1]
|
11
|
+
joined = links.join(" > ")
|
12
|
+
joined == desired # => false
|
13
|
+
joined.html_safe? # => false
|
14
|
+
require 'rails_join'
|
15
|
+
joined = links.join(" > ")
|
16
|
+
joined == desired # => true
|
17
|
+
joined.html_safe? # => true
|
18
|
+
|
19
|
+
== Installation
|
20
|
+
|
21
|
+
Simply add to your Gemfile:
|
22
|
+
|
23
|
+
gem "rails_join"
|
24
|
+
|
25
|
+
Run `bundle install` and you're done.
|
26
|
+
|
27
|
+
Runs on all versions of Ruby and all versions of Rails >= 3.0
|
28
|
+
|
29
|
+
== Why?
|
30
|
+
|
31
|
+
See: https://github.com/rails/rails/pull/3716
|
32
|
+
|
33
|
+
== Copyright
|
34
|
+
|
35
|
+
Copyright (c) 2012 Marc-Andre Lafortune. See LICENSE.txt for
|
36
|
+
further details.
|
37
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "rails_join"
|
18
|
+
gem.homepage = "http://github.com/marcandre/rails_join"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Make Array#join be html_safe aware}
|
21
|
+
gem.description = %Q{Use [...].join without worrying}
|
22
|
+
gem.email = "github@marc-andre.ca"
|
23
|
+
gem.authors = ["Marc-Andre Lafortune"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rake/rdoctask'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "rails_join #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/lib/rails_join.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'active_support/core_ext/string/output_safety'
|
2
|
+
require 'active_support/core_ext/module/aliasing.rb'
|
3
|
+
|
4
|
+
unless ["<br/>".html_safe, ">"].join("<") == "<br/><>"
|
5
|
+
class Array
|
6
|
+
def join_with_safe_buffer_awareness(sep = $,)
|
7
|
+
f = first
|
8
|
+
if f.is_a?(ActiveSupport::SafeBuffer) && f.html_safe?
|
9
|
+
map { |i| ERB::Util.html_escape(i) }.join_without_safe_buffer_awareness(ERB::Util.html_escape(sep)).html_safe
|
10
|
+
else
|
11
|
+
join_without_safe_buffer_awareness(sep)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
alias_method_chain :join, :safe_buffer_awareness
|
15
|
+
end
|
16
|
+
end
|
data/spec/perf.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Array#join" do
|
4
|
+
it "is not affected if the array is empty" do
|
5
|
+
r = [].join
|
6
|
+
r.should == ""
|
7
|
+
r.should_not be_html_safe
|
8
|
+
|
9
|
+
r = [].join("x".html_safe)
|
10
|
+
r.should == ""
|
11
|
+
r.should_not be_html_safe
|
12
|
+
end
|
13
|
+
|
14
|
+
it "is not affected if the first element is not an html safe buffer" do
|
15
|
+
r = [1, 2, 3].join
|
16
|
+
r.should == "123"
|
17
|
+
r.should_not be_html_safe
|
18
|
+
|
19
|
+
r = ["", "<>".html_safe].join("x".html_safe)
|
20
|
+
r.should == "x<>"
|
21
|
+
r.should_not be_html_safe
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns an html_safe string if the first element is an html safe buffer" do
|
25
|
+
r = ["<br/>".html_safe, 2, "<p/>"].join(" & ")
|
26
|
+
r.should == "<br/> & 2 & <p/>"
|
27
|
+
r.should be_html_safe
|
28
|
+
end
|
29
|
+
|
30
|
+
it "returns a string if the first element is a non html safe buffer" do
|
31
|
+
first = "<br/>".html_safe.upcase!
|
32
|
+
first.should_not be_html_safe # sanity check
|
33
|
+
first.class.should_not == String # sanity check
|
34
|
+
r = [first, 2, "<p/>"].join(" & ")
|
35
|
+
r.should == "<BR/> & 2 & <p/>"
|
36
|
+
r.should_not be_html_safe
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'rails_join'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_join
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Marc-Andre Lafortune
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: &2165002120 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2165002120
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &2165001600 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.3.0
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2165001600
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: bundler
|
38
|
+
requirement: &2165000800 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.0.0
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2165000800
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: jeweler
|
49
|
+
requirement: &2165000040 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.6.4
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2165000040
|
58
|
+
description: Use [...].join without worrying
|
59
|
+
email: github@marc-andre.ca
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files:
|
63
|
+
- LICENSE.txt
|
64
|
+
- README.rdoc
|
65
|
+
files:
|
66
|
+
- .document
|
67
|
+
- .rspec
|
68
|
+
- Gemfile
|
69
|
+
- Gemfile.lock
|
70
|
+
- LICENSE.txt
|
71
|
+
- README.rdoc
|
72
|
+
- Rakefile
|
73
|
+
- VERSION
|
74
|
+
- lib/rails_join.rb
|
75
|
+
- spec/perf.rb
|
76
|
+
- spec/rails_join_spec.rb
|
77
|
+
- spec/spec_helper.rb
|
78
|
+
homepage: http://github.com/marcandre/rails_join
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
hash: -2340820225422058680
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.8.10
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Make Array#join be html_safe aware
|
106
|
+
test_files: []
|