currency_select 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +12 -0
- data/Rakefile +2 -3
- data/VERSION +1 -1
- data/currency_select.gemspec +24 -29
- data/lib/currency_select.rb +35 -12
- metadata +35 -38
- data/.gitignore +0 -6
data/.document
ADDED
data/Gemfile
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'money'
|
3
|
+
gem 'money', '~> 5.1.1'
|
data/Gemfile.lock
ADDED
data/Rakefile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "rake"
|
2
2
|
require "bundler"
|
3
3
|
require "rake/testtask"
|
4
|
-
require "
|
4
|
+
require "rdoc/task"
|
5
5
|
|
6
6
|
# Gemcutter/Jeweler configuration
|
7
7
|
# -----------------------------------------------------------------------------
|
@@ -17,8 +17,7 @@ begin
|
|
17
17
|
gem.email = "tanordheim@gmail.com"
|
18
18
|
gem.homepage = "http://github.com/tanordheim/currency_select"
|
19
19
|
gem.authors = [ "Trond Arve Nordheim" ]
|
20
|
-
|
21
|
-
gem.add_bundler_dependencies
|
20
|
+
gem.version = File.read('VERSION').chomp
|
22
21
|
|
23
22
|
end
|
24
23
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/currency_select.gemspec
CHANGED
@@ -1,55 +1,50 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.1.
|
7
|
+
s.name = "currency_select"
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Trond Arve Nordheim"]
|
12
|
-
s.date =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
12
|
+
s.date = "2013-08-03"
|
13
|
+
s.description = "Adds a currency_select helper to Ruby on Rails projects"
|
14
|
+
s.email = "tanordheim@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
|
17
|
+
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
"test/helper.rb",
|
31
|
-
"test/test_currency_select.rb"
|
32
|
-
]
|
33
|
-
s.homepage = %q{http://github.com/tanordheim/currency_select}
|
34
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
35
|
-
s.require_paths = ["lib"]
|
36
|
-
s.rubygems_version = %q{1.7.2}
|
37
|
-
s.summary = %q{Currency Select plugin for Rails}
|
38
|
-
s.test_files = [
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"currency_select.gemspec",
|
28
|
+
"lib/currency_select.rb",
|
29
|
+
"rails/init.rb",
|
39
30
|
"test/helper.rb",
|
40
|
-
|
31
|
+
"test/test_currency_select.rb"
|
41
32
|
]
|
33
|
+
s.homepage = "http://github.com/tanordheim/currency_select"
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = "1.8.23"
|
36
|
+
s.summary = "Currency Select plugin for Rails"
|
42
37
|
|
43
38
|
if s.respond_to? :specification_version then
|
44
39
|
s.specification_version = 3
|
45
40
|
|
46
41
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
-
s.add_runtime_dependency(%q<money>, ["
|
42
|
+
s.add_runtime_dependency(%q<money>, ["~> 5.1.1"])
|
48
43
|
else
|
49
|
-
s.add_dependency(%q<money>, ["
|
44
|
+
s.add_dependency(%q<money>, ["~> 5.1.1"])
|
50
45
|
end
|
51
46
|
else
|
52
|
-
s.add_dependency(%q<money>, ["
|
47
|
+
s.add_dependency(%q<money>, ["~> 5.1.1"])
|
53
48
|
end
|
54
49
|
end
|
55
50
|
|
data/lib/currency_select.rb
CHANGED
@@ -3,7 +3,7 @@ require "money"
|
|
3
3
|
module CurrencySelect
|
4
4
|
class << self
|
5
5
|
|
6
|
-
CURRENCIES = Money::Currency::
|
6
|
+
CURRENCIES = Money::Currency::table.inject([]) do |array, (id, currency)|
|
7
7
|
array << [ "#{currency[:name]} - #{currency[:iso_code]}", id ]
|
8
8
|
end.sort_by { |currency| currency.first.parameterize } unless const_defined?("CURRENCIES")
|
9
9
|
|
@@ -19,7 +19,7 @@ module CurrencySelect
|
|
19
19
|
# priority_currencies_array([ "USD", "NOK" ])
|
20
20
|
# # => [ ['United States Dollar - USD', 'USD' ], ['Norwegian Kroner - NOK', 'NOK'] ]
|
21
21
|
def priority_currencies_array(currency_codes = [])
|
22
|
-
currencies_array.select { |currency| currency_codes.include?(currency.last) }
|
22
|
+
currencies_array.select { |currency| currency_codes.include?(currency.last.to_s) }
|
23
23
|
end
|
24
24
|
|
25
25
|
end
|
@@ -28,13 +28,20 @@ end
|
|
28
28
|
# CurrencySelect
|
29
29
|
module ActionView
|
30
30
|
module Helpers
|
31
|
-
|
32
31
|
module FormOptionsHelper
|
33
32
|
|
34
33
|
# Return select and option tags for the given object and method, using
|
35
34
|
# currency_options_for_select to generate the list of option tags.
|
36
35
|
def currency_select(object, method, priority_currencies = nil, options = {}, html_options = {})
|
37
|
-
|
36
|
+
tag = if defined?(ActionView::Helpers::InstanceTag) &&
|
37
|
+
ActionView::Helpers::InstanceTag.instance_method(:initialize).arity != 0
|
38
|
+
|
39
|
+
InstanceTag.new(object, method, self, options.delete(:object))
|
40
|
+
else
|
41
|
+
CurrencySelectTag.new(object, method, self, options)
|
42
|
+
end
|
43
|
+
|
44
|
+
tag.to_currency_select_tag(priority_currencies, options, html_options)
|
38
45
|
end
|
39
46
|
|
40
47
|
# Returns a string of option tags for all available currencies. Supply
|
@@ -43,24 +50,40 @@ module ActionView
|
|
43
50
|
# +priority_currencies+, so that they will be listed above the rest of
|
44
51
|
# the list.
|
45
52
|
def currency_options_for_select(selected = nil, priority_currencies = nil)
|
53
|
+
currency_options = "".html_safe
|
46
54
|
|
47
|
-
currency_options = ""
|
48
55
|
if priority_currencies
|
49
|
-
currency_options += options_for_select(CurrencySelect::priority_currencies_array(priority_currencies), selected)
|
50
|
-
currency_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
|
56
|
+
currency_options += options_for_select(::CurrencySelect::priority_currencies_array(priority_currencies), selected)
|
57
|
+
currency_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n".html_safe
|
58
|
+
|
59
|
+
# prevents selected from being included twice in the HTML which causes
|
60
|
+
# some browsers to select the second selected option (not priority)
|
61
|
+
# which makes it harder to select an alternative priority country
|
62
|
+
selected = nil if priority_currencies.include?(selected)
|
51
63
|
end
|
52
|
-
return currency_options + options_for_select(CurrencySelect::currencies_array - CurrencySelect::priority_currencies_array(priority_currencies), selected)
|
53
|
-
|
54
|
-
end
|
55
64
|
|
65
|
+
# All the countries included in the country_options output.
|
66
|
+
return currency_options + options_for_select(::CurrencySelect::currencies_array, selected)
|
67
|
+
end
|
56
68
|
end
|
57
69
|
|
58
|
-
|
70
|
+
module ToCurrencySelectTag
|
59
71
|
def to_currency_select_tag(priority_currencies, options, html_options)
|
60
72
|
html_options = html_options.stringify_keys
|
61
73
|
add_default_name_and_id(html_options)
|
62
74
|
value = value(object)
|
63
|
-
content_tag(
|
75
|
+
content_tag('select', add_options(currency_options_for_select(value, priority_currencies), options, value), html_options)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
if defined?(ActionView::Helpers::InstanceTag) &&
|
80
|
+
ActionView::Helpers::InstanceTag.instance_method(:initialize).arity != 0
|
81
|
+
class InstanceTag
|
82
|
+
include ToCurrencySelectTag
|
83
|
+
end
|
84
|
+
else
|
85
|
+
class CurrencySelectTag < Tags::Base
|
86
|
+
include ToCurrencySelectTag
|
64
87
|
end
|
65
88
|
end
|
66
89
|
|
metadata
CHANGED
@@ -1,41 +1,43 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: currency_select
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
4
5
|
prerelease:
|
5
|
-
version: 0.1.2
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Trond Arve Nordheim
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-08-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: money
|
17
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
|
-
requirements:
|
20
|
-
- -
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version:
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 5.1.1
|
23
22
|
type: :runtime
|
24
23
|
prerelease: false
|
25
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 5.1.1
|
26
30
|
description: Adds a currency_select helper to Ruby on Rails projects
|
27
31
|
email: tanordheim@gmail.com
|
28
32
|
executables: []
|
29
|
-
|
30
33
|
extensions: []
|
31
|
-
|
32
|
-
extra_rdoc_files:
|
34
|
+
extra_rdoc_files:
|
33
35
|
- LICENSE
|
34
36
|
- README.rdoc
|
35
|
-
files:
|
37
|
+
files:
|
36
38
|
- .document
|
37
|
-
- .gitignore
|
38
39
|
- Gemfile
|
40
|
+
- Gemfile.lock
|
39
41
|
- LICENSE
|
40
42
|
- README.rdoc
|
41
43
|
- Rakefile
|
@@ -47,31 +49,26 @@ files:
|
|
47
49
|
- test/test_currency_select.rb
|
48
50
|
homepage: http://github.com/tanordheim/currency_select
|
49
51
|
licenses: []
|
50
|
-
|
51
52
|
post_install_message:
|
52
|
-
rdoc_options:
|
53
|
-
|
54
|
-
require_paths:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
55
|
- lib
|
56
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
58
|
-
requirements:
|
59
|
-
- -
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version:
|
62
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
64
|
-
requirements:
|
65
|
-
- -
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version:
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
68
|
requirements: []
|
69
|
-
|
70
69
|
rubyforge_project:
|
71
|
-
rubygems_version: 1.
|
70
|
+
rubygems_version: 1.8.23
|
72
71
|
signing_key:
|
73
72
|
specification_version: 3
|
74
73
|
summary: Currency Select plugin for Rails
|
75
|
-
test_files:
|
76
|
-
- test/helper.rb
|
77
|
-
- test/test_currency_select.rb
|
74
|
+
test_files: []
|