braintree_country_select 1.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 +4 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.md +35 -0
- data/Rakefile +1 -0
- data/braintree_country_select.gemspec +21 -0
- data/lib/braintree_country_select.rb +52 -0
- data/lib/braintree_country_select/version.rb +3 -0
- metadata +76 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Michael Koziarski
|
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.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
## braintree_country_select
|
2
|
+
|
3
|
+
Provides a simple Rails form helper to generate an HTML select list of countries.
|
4
|
+
|
5
|
+
The country list is sourced from the braintree gem. This helper is intended for use in payment forms that submit to the Braintree payment processing gateway.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Install as a gem using
|
10
|
+
|
11
|
+
gem install braintree_country_select
|
12
|
+
|
13
|
+
Or put the following in your Gemfile
|
14
|
+
|
15
|
+
gem 'braintree_country_select'
|
16
|
+
|
17
|
+
## Example
|
18
|
+
|
19
|
+
Simple use supplying model and attribute as parameters:
|
20
|
+
|
21
|
+
braintree_country_select(:billing, :country_code_alpha3)
|
22
|
+
|
23
|
+
Supplying priority countries to be placed at the top of the list:
|
24
|
+
|
25
|
+
braintree_country_select(:billing, :country_code_alpha3, ["United States", "United Kingdom", "France", "Germany"])
|
26
|
+
|
27
|
+
## Copyright
|
28
|
+
|
29
|
+
Original country_select plugin by:
|
30
|
+
|
31
|
+
Copyright (c) 2008 Michael Koziarski, released under the MIT license.
|
32
|
+
|
33
|
+
Braintree-based fork by:
|
34
|
+
|
35
|
+
Copyright (c) 2012 Lukas Fittl, released under the MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "braintree_country_select/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "braintree_country_select"
|
7
|
+
s.version = BraintreeCountrySelect::VERSION
|
8
|
+
s.authors = ["Lukas Fittl"]
|
9
|
+
s.email = ["lukas@fittl.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Braintree Country Select Plugin}
|
12
|
+
s.description = %q{Rails Helper to get an HTML select list of countries. Uses country data from the braintree gem.}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.add_development_dependency "braintree"
|
20
|
+
s.add_runtime_dependency "braintree"
|
21
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'braintree_country_select/version'
|
2
|
+
|
3
|
+
module ActionView
|
4
|
+
module Helpers
|
5
|
+
module FormOptionsHelper
|
6
|
+
# Return select and option tags for the given object and method, using country_options_for_select to generate the list of option tags.
|
7
|
+
def braintree_country_select(object, method, priority_countries = nil, options = {}, html_options = {})
|
8
|
+
InstanceTag.new(object, method, self, options.delete(:object)).to_braintree_country_select_tag(priority_countries, options, html_options)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Returns a string of option tags for pretty much any country in the world. Supply a country name as +selected+ to
|
12
|
+
# have it marked as the selected option tag. You can also supply an array of countries as +priority_countries+, so
|
13
|
+
# that they will be listed above the rest of the (long) list.
|
14
|
+
#
|
15
|
+
# NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.
|
16
|
+
def braintree_country_options_for_select(selected = nil, priority_countries = nil)
|
17
|
+
country_options = "".html_safe
|
18
|
+
|
19
|
+
if priority_countries
|
20
|
+
country_options += options_for_select(priority_countries, selected)
|
21
|
+
country_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n".html_safe
|
22
|
+
# prevents selected from being included twice in the HTML which causes
|
23
|
+
# some browsers to select the second selected option (not priority)
|
24
|
+
# which makes it harder to select an alternative priority country
|
25
|
+
selected=nil if priority_countries.include?(selected)
|
26
|
+
end
|
27
|
+
|
28
|
+
return country_options + options_for_select(Braintree::Address::CountryNames.map {|c| [c[0], c[2]] }, selected)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class InstanceTag
|
33
|
+
def to_braintree_country_select_tag(priority_countries, options, html_options)
|
34
|
+
html_options = html_options.stringify_keys
|
35
|
+
add_default_name_and_id(html_options)
|
36
|
+
value = value(object)
|
37
|
+
content_tag("select",
|
38
|
+
add_options(
|
39
|
+
braintree_country_options_for_select(value, priority_countries),
|
40
|
+
options, value
|
41
|
+
), html_options
|
42
|
+
)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class FormBuilder
|
47
|
+
def braintree_country_select(method, priority_countries = nil, options = {}, html_options = {})
|
48
|
+
@template.braintree_country_select(@object_name, method, priority_countries, options.merge(:object => @object), html_options)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: braintree_country_select
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Lukas Fittl
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-27 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: braintree
|
16
|
+
requirement: &2153023120 !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: *2153023120
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: braintree
|
27
|
+
requirement: &2153022700 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2153022700
|
36
|
+
description: Rails Helper to get an HTML select list of countries. Uses country data
|
37
|
+
from the braintree gem.
|
38
|
+
email:
|
39
|
+
- lukas@fittl.com
|
40
|
+
executables: []
|
41
|
+
extensions: []
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- Gemfile
|
46
|
+
- MIT-LICENSE
|
47
|
+
- README.md
|
48
|
+
- Rakefile
|
49
|
+
- braintree_country_select.gemspec
|
50
|
+
- lib/braintree_country_select.rb
|
51
|
+
- lib/braintree_country_select/version.rb
|
52
|
+
homepage: ''
|
53
|
+
licenses: []
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.8.15
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: Braintree Country Select Plugin
|
76
|
+
test_files: []
|