Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added Rails 3 support back

  • Loading branch information...
commit c80e4249d65c334424c2a2ac29309ebf272156cb 1 parent 231fb81
@scudco scudco authored
View
4 Appraisals
@@ -1,3 +1,7 @@
+appraise 'actionpack3.2' do
+ gem 'actionpack', '~> 3.2.17'
+end
+
appraise 'actionpack4.0' do
gem 'actionpack', '~> 4.0.0'
end
View
5 UPGRADING.md
@@ -55,8 +55,3 @@ to
## Ruby 1.9+
`country_select` will no longer be tested in Ruby `< 1.9`.
-
-## Rails 4+
-
-`country_select` will no longer be tested in Rails `< 4`.
-
View
14 gemfiles/actionpack3.2.gemfile
@@ -0,0 +1,14 @@
+# This file was generated by Appraisal
+
+source "https://rubygems.org"
+
+gem "appraisal", "~> 1.0.0.beta3"
+gem "actionpack", "~> 3.2.17"
+
+platforms :rbx do
+ gem "racc"
+ gem "rubysl", "~> 2.0"
+ gem "psych"
+end
+
+gemspec :path=>".././"
View
285 gemfiles/actionpack3.2.gemfile.lock
@@ -0,0 +1,285 @@
+PATH
+ remote: .././
+ specs:
+ country_select (2.0.0.beta1)
+ countries (~> 0.9.3)
+
+GEM
+ remote: https://rubygems.org/
+ specs:
+ actionpack (3.2.17)
+ activemodel (= 3.2.17)
+ activesupport (= 3.2.17)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ journey (~> 1.0.4)
+ rack (~> 1.4.5)
+ rack-cache (~> 1.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.2.1)
+ activemodel (3.2.17)
+ activesupport (= 3.2.17)
+ builder (~> 3.0.0)
+ activesupport (3.2.17)
+ i18n (~> 0.6, >= 0.6.4)
+ multi_json (~> 1.0)
+ appraisal (1.0.0.beta3)
+ bundler
+ rake
+ thor (>= 0.14.0)
+ builder (3.0.4)
+ coderay (1.1.0)
+ countries (0.9.3)
+ currencies (~> 0.4.2)
+ currencies (0.4.2)
+ diff-lcs (1.2.5)
+ erubis (2.7.0)
+ ffi2-generators (0.1.1)
+ hike (1.2.3)
+ i18n (0.6.9)
+ journey (1.0.4)
+ method_source (0.8.2)
+ multi_json (1.8.4)
+ pry (0.9.12.6)
+ coderay (~> 1.0)
+ method_source (~> 0.8)
+ slop (~> 3.4)
+ psych (2.0.4)
+ racc (1.4.11)
+ rack (1.4.5)
+ rack-cache (1.2)
+ rack (>= 0.4)
+ rack-test (0.6.2)
+ rack (>= 1.0)
+ rake (10.1.1)
+ rspec (2.14.1)
+ rspec-core (~> 2.14.0)
+ rspec-expectations (~> 2.14.0)
+ rspec-mocks (~> 2.14.0)
+ rspec-core (2.14.8)
+ rspec-expectations (2.14.5)
+ diff-lcs (>= 1.1.3, < 2.0)
+ rspec-mocks (2.14.6)
+ rubysl (2.0.15)
+ rubysl-abbrev (~> 2.0)
+ rubysl-base64 (~> 2.0)
+ rubysl-benchmark (~> 2.0)
+ rubysl-bigdecimal (~> 2.0)
+ rubysl-cgi (~> 2.0)
+ rubysl-cgi-session (~> 2.0)
+ rubysl-cmath (~> 2.0)
+ rubysl-complex (~> 2.0)
+ rubysl-continuation (~> 2.0)
+ rubysl-coverage (~> 2.0)
+ rubysl-csv (~> 2.0)
+ rubysl-curses (~> 2.0)
+ rubysl-date (~> 2.0)
+ rubysl-delegate (~> 2.0)
+ rubysl-digest (~> 2.0)
+ rubysl-drb (~> 2.0)
+ rubysl-e2mmap (~> 2.0)
+ rubysl-english (~> 2.0)
+ rubysl-enumerator (~> 2.0)
+ rubysl-erb (~> 2.0)
+ rubysl-etc (~> 2.0)
+ rubysl-expect (~> 2.0)
+ rubysl-fcntl (~> 2.0)
+ rubysl-fiber (~> 2.0)
+ rubysl-fileutils (~> 2.0)
+ rubysl-find (~> 2.0)
+ rubysl-forwardable (~> 2.0)
+ rubysl-getoptlong (~> 2.0)
+ rubysl-gserver (~> 2.0)
+ rubysl-io-console (~> 2.0)
+ rubysl-io-nonblock (~> 2.0)
+ rubysl-io-wait (~> 2.0)
+ rubysl-ipaddr (~> 2.0)
+ rubysl-irb (~> 2.0)
+ rubysl-logger (~> 2.0)
+ rubysl-mathn (~> 2.0)
+ rubysl-matrix (~> 2.0)
+ rubysl-mkmf (~> 2.0)
+ rubysl-monitor (~> 2.0)
+ rubysl-mutex_m (~> 2.0)
+ rubysl-net-ftp (~> 2.0)
+ rubysl-net-http (~> 2.0)
+ rubysl-net-imap (~> 2.0)
+ rubysl-net-pop (~> 2.0)
+ rubysl-net-protocol (~> 2.0)
+ rubysl-net-smtp (~> 2.0)
+ rubysl-net-telnet (~> 2.0)
+ rubysl-nkf (~> 2.0)
+ rubysl-observer (~> 2.0)
+ rubysl-open-uri (~> 2.0)
+ rubysl-open3 (~> 2.0)
+ rubysl-openssl (~> 2.0)
+ rubysl-optparse (~> 2.0)
+ rubysl-ostruct (~> 2.0)
+ rubysl-pathname (~> 2.0)
+ rubysl-prettyprint (~> 2.0)
+ rubysl-prime (~> 2.0)
+ rubysl-profile (~> 2.0)
+ rubysl-profiler (~> 2.0)
+ rubysl-pstore (~> 2.0)
+ rubysl-pty (~> 2.0)
+ rubysl-rational (~> 2.0)
+ rubysl-readline (~> 2.0)
+ rubysl-resolv (~> 2.0)
+ rubysl-rexml (~> 2.0)
+ rubysl-rinda (~> 2.0)
+ rubysl-rss (~> 2.0)
+ rubysl-scanf (~> 2.0)
+ rubysl-securerandom (~> 2.0)
+ rubysl-set (~> 2.0)
+ rubysl-shellwords (~> 2.0)
+ rubysl-singleton (~> 2.0)
+ rubysl-socket (~> 2.0)
+ rubysl-stringio (~> 2.0)
+ rubysl-strscan (~> 2.0)
+ rubysl-sync (~> 2.0)
+ rubysl-syslog (~> 2.0)
+ rubysl-tempfile (~> 2.0)
+ rubysl-thread (~> 2.0)
+ rubysl-thwait (~> 2.0)
+ rubysl-time (~> 2.0)
+ rubysl-timeout (~> 2.0)
+ rubysl-tmpdir (~> 2.0)
+ rubysl-tsort (~> 2.0)
+ rubysl-un (~> 2.0)
+ rubysl-uri (~> 2.0)
+ rubysl-weakref (~> 2.0)
+ rubysl-webrick (~> 2.0)
+ rubysl-xmlrpc (~> 2.0)
+ rubysl-yaml (~> 2.0)
+ rubysl-zlib (~> 2.0)
+ rubysl-abbrev (2.0.4)
+ rubysl-base64 (2.0.0)
+ rubysl-benchmark (2.0.1)
+ rubysl-bigdecimal (2.0.2)
+ rubysl-cgi (2.0.1)
+ rubysl-cgi-session (2.0.1)
+ rubysl-cmath (2.0.0)
+ rubysl-complex (2.0.0)
+ rubysl-continuation (2.0.0)
+ rubysl-coverage (2.0.3)
+ rubysl-csv (2.0.2)
+ rubysl-english (~> 2.0)
+ rubysl-curses (2.0.1)
+ rubysl-date (2.0.6)
+ rubysl-delegate (2.0.1)
+ rubysl-digest (2.0.3)
+ rubysl-drb (2.0.1)
+ rubysl-e2mmap (2.0.0)
+ rubysl-english (2.0.0)
+ rubysl-enumerator (2.0.0)
+ rubysl-erb (2.0.1)
+ rubysl-etc (2.0.3)
+ ffi2-generators (~> 0.1)
+ rubysl-expect (2.0.0)
+ rubysl-fcntl (2.0.4)
+ ffi2-generators (~> 0.1)
+ rubysl-fiber (2.0.0)
+ rubysl-fileutils (2.0.3)
+ rubysl-find (2.0.1)
+ rubysl-forwardable (2.0.1)
+ rubysl-getoptlong (2.0.0)
+ rubysl-gserver (2.0.0)
+ rubysl-socket (~> 2.0)
+ rubysl-thread (~> 2.0)
+ rubysl-io-console (2.0.0)
+ rubysl-io-nonblock (2.0.0)
+ rubysl-io-wait (2.0.0)
+ rubysl-ipaddr (2.0.0)
+ rubysl-irb (2.0.4)
+ rubysl-e2mmap (~> 2.0)
+ rubysl-mathn (~> 2.0)
+ rubysl-readline (~> 2.0)
+ rubysl-thread (~> 2.0)
+ rubysl-logger (2.0.0)
+ rubysl-mathn (2.0.0)
+ rubysl-matrix (2.1.0)
+ rubysl-e2mmap (~> 2.0)
+ rubysl-mkmf (2.0.1)
+ rubysl-fileutils (~> 2.0)
+ rubysl-shellwords (~> 2.0)
+ rubysl-monitor (2.0.0)
+ rubysl-mutex_m (2.0.0)
+ rubysl-net-ftp (2.0.1)
+ rubysl-net-http (2.0.4)
+ rubysl-cgi (~> 2.0)
+ rubysl-erb (~> 2.0)
+ rubysl-singleton (~> 2.0)
+ rubysl-net-imap (2.0.1)
+ rubysl-net-pop (2.0.1)
+ rubysl-net-protocol (2.0.1)
+ rubysl-net-smtp (2.0.1)
+ rubysl-net-telnet (2.0.0)
+ rubysl-nkf (2.0.1)
+ rubysl-observer (2.0.0)
+ rubysl-open-uri (2.0.0)
+ rubysl-open3 (2.0.0)
+ rubysl-openssl (2.1.0)
+ rubysl-optparse (2.0.1)
+ rubysl-shellwords (~> 2.0)
+ rubysl-ostruct (2.0.4)
+ rubysl-pathname (2.0.0)
+ rubysl-prettyprint (2.0.2)
+ rubysl-prime (2.0.1)
+ rubysl-profile (2.0.0)
+ rubysl-profiler (2.0.1)
+ rubysl-pstore (2.0.0)
+ rubysl-pty (2.0.2)
+ rubysl-rational (2.0.1)
+ rubysl-readline (2.0.2)
+ rubysl-resolv (2.1.0)
+ rubysl-rexml (2.0.2)
+ rubysl-rinda (2.0.1)
+ rubysl-rss (2.0.0)
+ rubysl-scanf (2.0.0)
+ rubysl-securerandom (2.0.0)
+ rubysl-set (2.0.1)
+ rubysl-shellwords (2.0.0)
+ rubysl-singleton (2.0.0)
+ rubysl-socket (2.0.1)
+ rubysl-stringio (2.0.0)
+ rubysl-strscan (2.0.0)
+ rubysl-sync (2.0.0)
+ rubysl-syslog (2.0.1)
+ ffi2-generators (~> 0.1)
+ rubysl-tempfile (2.0.1)
+ rubysl-thread (2.0.2)
+ rubysl-thwait (2.0.0)
+ rubysl-time (2.0.3)
+ rubysl-timeout (2.0.0)
+ rubysl-tmpdir (2.0.0)
+ rubysl-tsort (2.0.1)
+ rubysl-un (2.0.0)
+ rubysl-fileutils (~> 2.0)
+ rubysl-optparse (~> 2.0)
+ rubysl-uri (2.0.0)
+ rubysl-weakref (2.0.0)
+ rubysl-webrick (2.0.0)
+ rubysl-xmlrpc (2.0.0)
+ rubysl-yaml (2.0.4)
+ rubysl-zlib (2.0.1)
+ slop (3.4.7)
+ sprockets (2.2.2)
+ hike (~> 1.2)
+ multi_json (~> 1.0)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ thor (0.18.1)
+ tilt (1.4.1)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ actionpack (~> 3.2.17)
+ appraisal (~> 1.0.0.beta3)
+ country_select!
+ pry (~> 0)
+ psych
+ racc
+ rspec (~> 2)
+ rubysl (~> 2.0)
View
109 lib/country_select.rb
@@ -1,107 +1,10 @@
-# encoding: utf-8
-
-require 'country_select/version'
require 'iso3166'
-module ActionView
- module Helpers
- class FormBuilder
- def country_select(method, options = {}, html_options = {})
- @template.country_select(@object_name, method, objectify_options(options), @default_options.merge(html_options))
- end
- end
-
- module FormOptionsHelper
- def country_select(object, method, options = {}, html_options = {})
- Tags::CountrySelect.new(object, method, self, options, html_options).render
- end
- end
-
- module Tags
- class CountrySelect < Base
- def initialize(object_name, method_name, template_object, options, html_options)
- @html_options = html_options
-
- super(object_name, method_name, template_object, options)
- end
-
- def render
- select_content_tag(country_option_tags, @options, @html_options)
- end
-
- def country_option_tags
- option_tags_options = {
- :selected => @options.fetch(:selected) { value(@object) },
- :disabled => @options[:disabled]
- }
-
- if priority_countries.present?
- priority_countries_options = country_options_for(priority_countries)
-
- option_tags = options_for_select(priority_countries_options, option_tags_options)
- option_tags += html_safe_newline + options_for_select([priority_countries_divider], disabled: priority_countries_divider)
-
- if priority_countries.include?(option_tags_options[:selected])
- option_tags_options[:selected] = nil
- end
-
- option_tags += html_safe_newline + options_for_select(country_options, option_tags_options)
- else
- option_tags = options_for_select(country_options, option_tags_options)
- end
- end
-
- private
- def locale
- @options[:locale]
- end
-
- def priority_countries
- @options[:priority_countries]
- end
-
- def priority_countries_divider
- @options[:priority_countries_divider] || "-"*15
- end
-
- def only_country_codes
- @options[:only]
- end
-
- def country_options
- country_options_for(all_country_codes)
- end
-
- def all_country_codes
- codes = ISO3166::Country.all.map(&:last)
-
- if only_country_codes.present?
- codes & only_country_codes
- else
- codes
- end
- end
-
- def country_options_for(country_codes)
- I18n.with_locale(locale) do
- country_codes.map do |code|
- code = code.to_s.upcase
- country = ISO3166::Country.new(code)
-
- default_name = country.name
- localized_name = country.translations[I18n.locale.to_s]
-
- name = localized_name || default_name
-
- [name,code]
- end.sort
- end
- end
+require 'country_select/version'
+require 'country_select/tag_helper'
- def html_safe_newline
- "\n".html_safe
- end
- end
- end
- end
+if defined?(ActionView::Helpers::Tags::Base)
+ require 'country_select/country_select_helper'
+else
+ require 'country_select/rails3/country_select_helper'
end
View
31 lib/country_select/country_select_helper.rb
@@ -0,0 +1,31 @@
+module ActionView
+ module Helpers
+ class FormBuilder
+ def country_select(method, options = {}, html_options = {})
+ @template.country_select(@object_name, method, objectify_options(options), @default_options.merge(html_options))
+ end
+ end
+
+ module FormOptionsHelper
+ def country_select(object, method, options = {}, html_options = {})
+ Tags::CountrySelect.new(object, method, self, options, html_options).render
+ end
+ end
+
+ module Tags
+ class CountrySelect < Base
+ include ::CountrySelect::TagHelper
+
+ def initialize(object_name, method_name, template_object, options, html_options)
+ @html_options = html_options
+
+ super(object_name, method_name, template_object, options)
+ end
+
+ def render
+ select_content_tag(country_option_tags, @options, @html_options)
+ end
+ end
+ end
+ end
+end
View
26 lib/country_select/rails3/country_select_helper.rb
@@ -0,0 +1,26 @@
+module ActionView
+ module Helpers
+ class FormBuilder
+ def country_select(method, options = {}, html_options = {})
+ @template.country_select(@object_name, method, objectify_options(options), @default_options.merge(html_options))
+ end
+ end
+
+ module FormOptionsHelper
+ def country_select(object, method, options = {}, html_options = {})
+ CountrySelect.new(object, method, self, options.delete(:object)).render(options, html_options)
+ end
+ end
+
+ class CountrySelect < InstanceTag
+ include ::CountrySelect::TagHelper
+
+ def render(options, html_options)
+ @options = options
+ @html_options = html_options
+
+ select_content_tag(country_option_tags, @options, @html_options)
+ end
+ end
+ end
+end
View
77 lib/country_select/tag_helper.rb
@@ -0,0 +1,77 @@
+module CountrySelect
+ module TagHelper
+ def country_option_tags
+ option_tags_options = {
+ :selected => @options.fetch(:selected) { value(@object) },
+ :disabled => @options[:disabled]
+ }
+
+ if priority_countries.present?
+ priority_countries_options = country_options_for(priority_countries)
+
+ option_tags = options_for_select(priority_countries_options, option_tags_options)
+ option_tags += html_safe_newline + options_for_select([priority_countries_divider], disabled: priority_countries_divider)
+
+ if priority_countries.include?(option_tags_options[:selected])
+ option_tags_options[:selected] = nil
+ end
+
+ option_tags += html_safe_newline + options_for_select(country_options, option_tags_options)
+ else
+ option_tags = options_for_select(country_options, option_tags_options)
+ end
+ end
+
+ private
+ def locale
+ @options[:locale]
+ end
+
+ def priority_countries
+ @options[:priority_countries]
+ end
+
+ def priority_countries_divider
+ @options[:priority_countries_divider] || "-"*15
+ end
+
+ def only_country_codes
+ @options[:only]
+ end
+
+ def country_options
+ country_options_for(all_country_codes)
+ end
+
+ def all_country_codes
+ codes = ISO3166::Country.all.map(&:last)
+
+ if only_country_codes.present?
+ codes & only_country_codes
+ else
+ codes
+ end
+ end
+
+ def country_options_for(country_codes)
+ I18n.with_locale(locale) do
+ country_codes.map do |code|
+ code = code.to_s.upcase
+ country = ISO3166::Country.new(code)
+
+ default_name = country.name
+ localized_name = country.translations[I18n.locale.to_s]
+
+ name = localized_name || default_name
+
+ [name,code]
+ end.sort
+ end
+ end
+
+ def html_safe_newline
+ "\n".html_safe
+ end
+ end
+end
+
View
27 spec/country_select_spec.rb
@@ -3,7 +3,7 @@
require 'action_view'
require 'country_select'
-describe ActionView::Helpers::Tags::CountrySelect do
+describe "CountrySelect" do
include ActionView::Helpers::TagHelper
include ActionView::Helpers::FormOptionsHelper
@@ -15,31 +15,29 @@ class Walrus
let!(:template) { ActionView::Base.new }
let(:builder) do
- ActionView::Helpers::FormBuilder.new(:walrus, walrus, template, {})
+ if defined?(ActionView::Helpers::Tags::Base)
+ ActionView::Helpers::FormBuilder.new(:walrus, walrus, template, {})
+ else
+ ActionView::Helpers::FormBuilder.new(:walrus, walrus, template, {}, Proc.new { })
+ end
end
let(:select_tag) do
<<-EOS.chomp.strip
- <select id="walrus_country_code" name="walrus[country_code]">
+ <select id="walrus_country_code" name="walrus[country_code]">
EOS
end
it "selects the value of country_code" do
- tag = content_tag(:option,
- 'United States of America',
- selected: true,
- value: "US")
+ tag = options_for_select([['United States of America', 'US']], 'US')
walrus.country_code = 'US'
t = builder.country_select(:country_code)
expect(t).to include(tag)
end
- it "uses the I18n.locale" do
- tag = content_tag(:option,
- 'Estados Unidos',
- selected: true,
- value: "US")
+ it "uses the locale specified by I18n.locale" do
+ tag = options_for_select([['Estados Unidos', 'US']], 'US')
walrus.country_code = 'US'
original_locale = I18n.locale
@@ -53,10 +51,7 @@ class Walrus
end
it "accepts a locale option" do
- tag = content_tag(:option,
- 'États-Unis',
- selected: true,
- value: "US")
+ tag = options_for_select([['États-Unis', 'US']], 'US')
walrus.country_code = 'US'
t = builder.country_select(:country_code, locale: :fr)
Please sign in to comment.
Something went wrong with that request. Please try again.