currency_select 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +6 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.rdoc +14 -0
- data/Rakefile +77 -0
- data/VERSION +1 -0
- data/currency_select.gemspec +56 -0
- data/lib/currency_select.rb +74 -0
- data/rails/init.rb +1 -0
- data/test/helper.rb +10 -0
- data/test/test_currency_select.rb +7 -0
- metadata +91 -0
data/.document
ADDED
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Trond Arve Nordheim
|
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,14 @@
|
|
1
|
+
= CurrencySelect
|
2
|
+
|
3
|
+
Adds a currency_select helper to Ruby on Rails projects, allowing you to get
|
4
|
+
a HTML select list of available currencies.
|
5
|
+
|
6
|
+
The list of currencies are provided by the {Money}[http://money.rubyforge.org/] gem.
|
7
|
+
|
8
|
+
= Example
|
9
|
+
|
10
|
+
currency_select("user", "currency")
|
11
|
+
|
12
|
+
== Copyright
|
13
|
+
|
14
|
+
Copyright (c) 2010 Trond Arve Nordheim. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require "rake"
|
2
|
+
require "bundler"
|
3
|
+
require "rake/testtask"
|
4
|
+
require "rake/rdoctask"
|
5
|
+
|
6
|
+
# Gemcutter/Jeweler configuration
|
7
|
+
# -----------------------------------------------------------------------------
|
8
|
+
begin
|
9
|
+
|
10
|
+
require "jeweler"
|
11
|
+
|
12
|
+
Jeweler::Tasks.new do |gem|
|
13
|
+
|
14
|
+
gem.name = "currency_select"
|
15
|
+
gem.summary = "Currency Select plugin for Rails"
|
16
|
+
gem.description = "Adds a currency_select helper to Ruby on Rails projects"
|
17
|
+
gem.email = "tanordheim@gmail.com"
|
18
|
+
gem.homepage = "http://github.com/tanordheim/currency_select"
|
19
|
+
gem.authors = [ "Trond Arve Nordheim" ]
|
20
|
+
|
21
|
+
gem.add_bundler_dependencies
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
Jeweler::GemcutterTasks.new
|
26
|
+
|
27
|
+
rescue LoadError
|
28
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
# Test setup
|
33
|
+
# -----------------------------------------------------------------------------
|
34
|
+
Rake::TestTask.new(:test) do |t|
|
35
|
+
t.libs << "lib" << "test"
|
36
|
+
t.ruby_opts << "-rubygems"
|
37
|
+
t.pattern = "test/**/*_test.rb"
|
38
|
+
t.verbose = true
|
39
|
+
end
|
40
|
+
|
41
|
+
# RDoc setup
|
42
|
+
# ----------------------------------------------------------------------------
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
|
45
|
+
version = File.exists?("VERSION") ? File.read("VERSION") : ""
|
46
|
+
|
47
|
+
rdoc.rdoc_dir = "rdoc"
|
48
|
+
rdoc.title = "currency_select #{version}"
|
49
|
+
rdoc.rdoc_files.include("README.rdoc")
|
50
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
# Rcov setup
|
55
|
+
# ----------------------------------------------------------------------------
|
56
|
+
begin
|
57
|
+
|
58
|
+
require "rcov/rcovtask"
|
59
|
+
|
60
|
+
Rcov::RcovTask.new do |test|
|
61
|
+
|
62
|
+
test.libs << "test"
|
63
|
+
test.pattern = "test/**/*_test.rb"
|
64
|
+
test.verbose = "true"
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
rescue LoadError
|
69
|
+
task :rcov do
|
70
|
+
abort "Rcov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Task setups
|
75
|
+
# -----------------------------------------------------------------------------
|
76
|
+
task :test => :check_dependencies
|
77
|
+
task :default => :test
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{currency_select}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Trond Arve Nordheim"]
|
12
|
+
s.date = %q{2010-10-29}
|
13
|
+
s.description = %q{Adds a currency_select helper to Ruby on Rails projects}
|
14
|
+
s.email = %q{tanordheim@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"Gemfile",
|
23
|
+
"LICENSE",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"currency_select.gemspec",
|
28
|
+
"lib/currency_select.rb",
|
29
|
+
"rails/init.rb",
|
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.3.7}
|
37
|
+
s.summary = %q{Currency Select plugin for Rails}
|
38
|
+
s.test_files = [
|
39
|
+
"test/helper.rb",
|
40
|
+
"test/test_currency_select.rb"
|
41
|
+
]
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_runtime_dependency(%q<money>, ["~> 3.1.5"])
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<money>, ["~> 3.1.5"])
|
51
|
+
end
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<money>, ["~> 3.1.5"])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require "money"
|
2
|
+
|
3
|
+
module CurrencySelect
|
4
|
+
class << self
|
5
|
+
|
6
|
+
CURRENCIES = Money::Currency::TABLE.inject([]) do |array, (id, currency)|
|
7
|
+
array << [ "#{currency[:name]} - #{currency[:iso_code]}", currency[:iso_code] ]
|
8
|
+
end.sort_by { |currency| currency.first.parameterize } unless const_defined?("CURRENCIES")
|
9
|
+
|
10
|
+
# Returns an array with ISO codes and currency names for <tt>option</tt>
|
11
|
+
# tags.
|
12
|
+
def currencies_array
|
13
|
+
CURRENCIES
|
14
|
+
end
|
15
|
+
|
16
|
+
# Return an array with ISO codes and currency names for currency ISO codes
|
17
|
+
# passed as an argument
|
18
|
+
# == Example
|
19
|
+
# priority_currencies_array([ "USD", "NOK" ])
|
20
|
+
# # => [ ['United States Dollar - USD', 'USD' ], ['Norwegian Kroner - NOK', 'NOK'] ]
|
21
|
+
def priority_currencies_array(currency_codes = [])
|
22
|
+
currencies_array.select { |currency| currency_codes.include?(currency.last) }
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# CurrencySelect
|
29
|
+
module ActionView
|
30
|
+
module Helpers
|
31
|
+
|
32
|
+
module FormOptionsHelper
|
33
|
+
|
34
|
+
# Return select and option tags for the given object and method, using
|
35
|
+
# currency_options_for_select to generate the list of option tags.
|
36
|
+
def currency_select(object, method, priority_currencies = nil, options = {}, html_options = {})
|
37
|
+
InstanceTag.new(object, method, self, options.delete(:object)).to_currency_select_tag(priority_currencies, options, html_options)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Returns a string of option tags for all available currencies. Supply
|
41
|
+
# a currency ISO code as +selected+ to have it marked as the selected
|
42
|
+
# option tag. You can also supply an array of currencies as
|
43
|
+
# +priority_currencies+, so that they will be listed above the rest of
|
44
|
+
# the list.
|
45
|
+
def currency_options_for_select(selected = nil, priority_currencies = nil)
|
46
|
+
|
47
|
+
currency_options = ""
|
48
|
+
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"
|
51
|
+
end
|
52
|
+
return currency_options + options_for_select(CurrencySelect::currencies_array - CurrencySelect::priority_currencies_array(priority_currencies), selected)
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
class InstanceTag
|
59
|
+
def to_currency_select_tag(priority_currencies, options, html_options)
|
60
|
+
html_options = html_options.stringify_keys
|
61
|
+
add_default_name_and_id(html_options)
|
62
|
+
value = value(object)
|
63
|
+
content_tag("select", add_options(currency_options_for_select(value, priority_currencies), options, value), html_options)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class FormBuilder
|
68
|
+
def currency_select(method, priority_currencies = nil, options = {}, html_options = {})
|
69
|
+
@template.currency_select(@object_name, method, priority_currencies, options.merge(:object => @object), html_options)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "currency_select"
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: currency_select
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Trond Arve Nordheim
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-10-29 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: money
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 3
|
29
|
+
- 1
|
30
|
+
- 5
|
31
|
+
version: 3.1.5
|
32
|
+
type: :runtime
|
33
|
+
prerelease: false
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Adds a currency_select helper to Ruby on Rails projects
|
36
|
+
email: tanordheim@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .document
|
46
|
+
- .gitignore
|
47
|
+
- Gemfile
|
48
|
+
- LICENSE
|
49
|
+
- README.rdoc
|
50
|
+
- Rakefile
|
51
|
+
- VERSION
|
52
|
+
- currency_select.gemspec
|
53
|
+
- lib/currency_select.rb
|
54
|
+
- rails/init.rb
|
55
|
+
- test/helper.rb
|
56
|
+
- test/test_currency_select.rb
|
57
|
+
has_rdoc: true
|
58
|
+
homepage: http://github.com/tanordheim/currency_select
|
59
|
+
licenses: []
|
60
|
+
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options:
|
63
|
+
- --charset=UTF-8
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
requirements: []
|
83
|
+
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.3.7
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Currency Select plugin for Rails
|
89
|
+
test_files:
|
90
|
+
- test/helper.rb
|
91
|
+
- test/test_currency_select.rb
|