country_select-11.0.0/0000755000004100000410000000000015146070065014667 5ustar www-datawww-datacountry_select-11.0.0/country_select.gemspec0000644000004100000410000000275215146070065021304 0ustar www-datawww-data# frozen_string_literal: true $LOAD_PATH.push File.expand_path('lib', __dir__) require 'country_select/version' Gem::Specification.new do |s| s.name = 'country_select' s.version = CountrySelect::VERSION s.licenses = ['MIT'] s.authors = ['Stefan Penner'] s.email = ['stefan.penner@gmail.com'] s.homepage = 'https://github.com/countries/country_select' s.summary = 'Country Select Plugin' s.description = 'Provides a simple helper to get an HTML select list of countries. \ The list of countries comes from the ISO 3166 standard. \ While it is a relatively neutral source of country names, it will still offend some users.' s.metadata = { 'bug_tracker_uri' => 'http://github.com/countries/country_select/issues', 'changelog_uri' => 'https://github.com/countries/country_select/blob/master/CHANGELOG.md', 'source_code_uri' => 'https://github.com/countries/country_select', 'rubygems_mfa_required' => 'true' } s.files = `git ls-files`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } s.require_paths = ['lib'] s.required_ruby_version = '>= 3.2' s.add_development_dependency 'pry', '~> 0' s.add_development_dependency 'rake', '~> 13' s.add_development_dependency 'rspec', '~> 3' s.add_development_dependency 'simplecov', '~> 0.22' s.add_dependency 'countries', '> 6.0', '< 9.0' end country_select-11.0.0/Gemfile.lock0000644000004100000410000000663715146070065017125 0ustar www-datawww-dataPATH remote: . specs: country_select (10.0.1) countries (> 6.0, < 9.0) GEM remote: https://rubygems.org/ specs: actionpack (8.0.2) actionview (= 8.0.2) activesupport (= 8.0.2) nokogiri (>= 1.8.5) rack (>= 2.2.4) rack-session (>= 1.0.1) rack-test (>= 0.6.3) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) useragent (~> 0.16) actionview (8.0.2) activesupport (= 8.0.2) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) activesupport (8.0.2) base64 benchmark (>= 0.3) bigdecimal concurrent-ruby (~> 1.0, >= 1.3.1) connection_pool (>= 2.2.5) drb i18n (>= 1.6, < 2) logger (>= 1.4.2) minitest (>= 5.1) securerandom (>= 0.3) tzinfo (~> 2.0, >= 2.0.5) uri (>= 0.13.1) base64 (0.3.0) benchmark (0.4.1) bigdecimal (3.2.1) builder (3.3.0) coderay (1.1.3) concurrent-ruby (1.3.5) connection_pool (2.5.3) countries (8.0.0) unaccent (~> 0.3) crass (1.0.6) diff-lcs (1.6.2) docile (1.4.1) drb (2.2.3) erubi (1.13.1) i18n (1.14.7) concurrent-ruby (~> 1.0) logger (1.7.0) loofah (2.24.1) crass (~> 1.0.2) nokogiri (>= 1.12.0) method_source (1.1.0) mini_portile2 (2.8.9) minitest (5.25.5) nokogiri (1.18.8) mini_portile2 (~> 2.8.2) racc (~> 1.4) nokogiri (1.18.8-aarch64-linux-gnu) racc (~> 1.4) nokogiri (1.18.8-aarch64-linux-musl) racc (~> 1.4) nokogiri (1.18.8-arm-linux-gnu) racc (~> 1.4) nokogiri (1.18.8-arm-linux-musl) racc (~> 1.4) nokogiri (1.18.8-arm64-darwin) racc (~> 1.4) nokogiri (1.18.8-x86_64-darwin) racc (~> 1.4) nokogiri (1.18.8-x86_64-linux-gnu) racc (~> 1.4) nokogiri (1.18.8-x86_64-linux-musl) racc (~> 1.4) pry (0.15.2) coderay (~> 1.1) method_source (~> 1.0) racc (1.8.1) rack (3.1.15) rack-session (2.1.1) base64 (>= 0.1.0) rack (>= 3.0.0) rack-test (2.2.0) rack (>= 1.3) rails-dom-testing (2.3.0) activesupport (>= 5.0.0) minitest nokogiri (>= 1.6) rails-html-sanitizer (1.6.2) loofah (~> 2.21) nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) rake (13.3.0) rspec (3.13.1) rspec-core (~> 3.13.0) rspec-expectations (~> 3.13.0) rspec-mocks (~> 3.13.0) rspec-core (3.13.4) rspec-support (~> 3.13.0) rspec-expectations (3.13.5) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) rspec-mocks (3.13.5) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) rspec-support (3.13.4) securerandom (0.4.1) simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) simplecov_json_formatter (~> 0.1) simplecov-html (0.13.1) simplecov_json_formatter (0.1.4) tzinfo (2.0.6) concurrent-ruby (~> 1.0) unaccent (0.4.0) uri (1.0.3) useragent (0.16.11) PLATFORMS aarch64-linux-gnu aarch64-linux-musl arm-linux-gnu arm-linux-musl arm64-darwin ruby x86_64-darwin x86_64-linux x86_64-linux-gnu x86_64-linux-musl DEPENDENCIES actionpack (> 7.0) country_select! pry (~> 0) rake (~> 13) rspec (~> 3) simplecov (~> 0.22) BUNDLED WITH 2.6.2 country_select-11.0.0/.gitignore0000644000004100000410000000010215146070065016650 0ustar www-datawww-data*.gem *.sqlite .bundle pkg/* .ruby-version vendor/bundle coverage country_select-11.0.0/.codeclimate.yml0000644000004100000410000000174115146070065017744 0ustar www-datawww-dataversion: "2" checks: argument-count: enabled: true config: threshold: 4 complex-logic: enabled: true config: threshold: 4 file-lines: enabled: true config: threshold: 250 method-complexity: enabled: true config: threshold: 5 method-count: enabled: true config: threshold: 20 method-lines: enabled: true config: threshold: 25 nested-control-flow: enabled: true config: threshold: 4 return-statements: enabled: true config: threshold: 4 plugins: rubocop: enabled: true channel: rubocop-1-48-1 reek: enabled: true checks: IrresponsibleModule: enabled: false TooManyStatements: max_statements: 7 flog: enabled: true bundler-audit: enabled: true exclude_patterns: - "config/" - "db/" - "dist/" - "features/" - "**/node_modules/" - "script/" - "**/spec/" - "**/test/" - "**/tests/" - "**/vendor/" - "**/*.d.ts" country_select-11.0.0/.github/0000755000004100000410000000000015146070065016227 5ustar www-datawww-datacountry_select-11.0.0/.github/workflows/0000755000004100000410000000000015146070065020264 5ustar www-datawww-datacountry_select-11.0.0/.github/workflows/test.yml0000644000004100000410000000170015146070065021764 0ustar www-datawww-dataname: Tests on: pull_request: paths-ignore: - 'README.md' - 'CHANGELOG.md' push: paths-ignore: - 'README.md' - 'CHANGELOG.md' jobs: build: runs-on: ubuntu-latest strategy: fail-fast: false matrix: ruby: [3.2, 3.3, 3.4] gemfile: [7.1, 7.2, '8.0'] env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/actionpack-${{ matrix.gemfile }}.gemfile CC_TEST_REPORTER_ID: 0d09e6611c01dedd75511b1c60f62329d01729289e06375cfe67cefe67013d9f steps: - uses: actions/checkout@v4 - name: Set up Ruby ${{ matrix.ruby-version }} uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} bundler-cache: true cache-version: 10 - name: Run tests run: bundle exec rake - name: Publish code coverage uses: paambaati/codeclimate-action@v5.0.0 country_select-11.0.0/.github/workflows/codeql-analysis.yml0000644000004100000410000000443715146070065024107 0ustar www-datawww-data# For most projects, this workflow file will not need changing; you simply need # to commit it to your repository. # # You may wish to alter this file to override the set of languages analyzed, # or to provide custom queries or build logic. # # ******** NOTE ******** # We have attempted to detect the languages in your repository. Please check # the `language` matrix defined below to confirm you have the correct set of # supported CodeQL languages. # name: "CodeQL" on: push: branches: [ master ] pull_request: # The branches below must be a subset of the branches above branches: [ master ] schedule: - cron: '21 7 * * 5' jobs: analyze: name: Analyze runs-on: ubuntu-latest permissions: actions: read contents: read security-events: write strategy: fail-fast: false matrix: language: [ 'ruby' ] # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] # Learn more about CodeQL language support at https://git.io/codeql-language-support steps: - name: Checkout repository uses: actions/checkout@v4 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. # By default, queries listed here will override any specified in a config file. # Prefix the list here with "+" to use these queries and those in the config file. # queries: ./path/to/local/query, your-org/your-repo/queries@main # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild uses: github/codeql-action/autobuild@v2 # ℹ️ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines # and modify them (or add more) to build your code if your project # uses a compiled language #- run: | # make bootstrap # make release - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 country_select-11.0.0/lib/0000755000004100000410000000000015146070065015435 5ustar www-datawww-datacountry_select-11.0.0/lib/country_select/0000755000004100000410000000000015146070065020477 5ustar www-datawww-datacountry_select-11.0.0/lib/country_select/tag_helper.rb0000644000004100000410000000764715146070065023154 0ustar www-datawww-data# frozen_string_literal: true module CountrySelect class CountryNotFoundError < StandardError; end module TagHelper unless respond_to?(:options_for_select) include ActionView::Helpers::FormOptionsHelper include ActionView::Helpers::Tags::SelectRenderer if defined?(ActionView::Helpers::Tags::SelectRenderer) end def country_option_tags # In Rails 5.2+, `value` accepts no arguments and must also be called # with parens to avoid the local variable of the same name # https://github.com/rails/rails/pull/29791 selected_option = @options.fetch(:selected) do if self.method(:value).arity.zero? value() else value(@object) end end option_tags_options = { selected: selected_option, disabled: @options[:disabled] } if priority_countries.present? options_for_select_with_priority_countries(country_options, option_tags_options) else options_for_select(country_options, option_tags_options) end end private def locale @options.fetch(:locale, ::CountrySelect::DEFAULTS[:locale]) end def priority_countries @options.fetch(:priority_countries, ::CountrySelect::DEFAULTS[:priority_countries]) end def only_country_codes @options.fetch(:only, ::CountrySelect::DEFAULTS[:only]) end def except_country_codes @options.fetch(:except, ::CountrySelect::DEFAULTS[:except]) end def format @options.fetch(:format, ::CountrySelect::DEFAULTS[:format]) end def country_options codes = ISO3166::Country.codes if only_country_codes.present? codes = only_country_codes & codes sort = @options.fetch(:sort_provided, ::CountrySelect::DEFAULTS[:sort_provided]) else codes -= except_country_codes if except_country_codes.present? sort = true end country_options_for(codes, sorted: sort) end def country_options_for(country_codes, sorted: true) I18n.with_locale(locale) do country_list = country_codes.map { |code_or_name| get_formatted_country(code_or_name) } country_list.sort_by! { |name, _| transliterated_name = I18n.transliterate(name.to_s) if transliterated_name.include?('?') # For languages that cannot be transliterated (e.g. languages with non-Latin scripts) [name, name] # If transliteration fails, duplicate the original name to maintain a consistent two-element array structure. else [transliterated_name, name] end } if sorted country_list end end def options_for_select_with_priority_countries(country_options, tags_options) sorted = @options.fetch(:sort_provided, ::CountrySelect::DEFAULTS[:sort_provided]) priority_countries_options = country_options_for(priority_countries, sorted:) option_tags = priority_options_for_select(priority_countries_options, tags_options) tags_options[:selected] = Array(tags_options[:selected]).delete_if do |selected| priority_countries_options.map(&:second).include?(selected) end option_tags += "\n".html_safe + options_for_select(country_options, tags_options) option_tags end def priority_options_for_select(priority_countries_options, tags_options) options_for_select(priority_countries_options, tags_options) + "\n
".html_safe end def get_formatted_country(code_or_name) country = ISO3166::Country.new(code_or_name) || ISO3166::Country.find_country_by_any_name(code_or_name) raise(CountryNotFoundError, "Could not find Country with string '#{code_or_name}'") unless country.present? code = country.alpha2 formatted_country = ::CountrySelect::FORMATS[format].call(country) if formatted_country.is_a?(Array) formatted_country else [formatted_country, code] end end end end country_select-11.0.0/lib/country_select/formats.rb0000644000004100000410000000061015146070065022474 0ustar www-datawww-data# frozen_string_literal: true module CountrySelect FORMATS = {} FORMATS[:default] = lambda do |country| # Need to use :[] specifically, not :dig, because country.translations is a # ISO3166::Translations object, which overrides :[] to support i18n locale fallbacks country.translations&.send(:[], I18n.locale.to_s) || country.common_name || country.iso_short_name end end country_select-11.0.0/lib/country_select/defaults.rb0000644000004100000410000000030715146070065022633 0ustar www-datawww-data# frozen_string_literal: true module CountrySelect DEFAULTS = { except: nil, format: :default, locale: nil, only: nil, priority_countries: nil, sort_provided: true } end country_select-11.0.0/lib/country_select/version.rb0000644000004100000410000000011515146070065022506 0ustar www-datawww-data# frozen_string_literal: true module CountrySelect VERSION = '11.0.0' end country_select-11.0.0/lib/country_select/country_select_helper.rb0000644000004100000410000000207315146070065025427 0ustar www-datawww-data# frozen_string_literal: true module ActionView module Helpers class FormBuilder def country_select(method, options = {}, html_options = {}) unless options.is_a?(Hash) raise ArgumentError, 'Invalid syntax for country_select method. options must be a hash' end @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 country_select-11.0.0/lib/country_select.rb0000644000004100000410000000035315146070065021025 0ustar www-datawww-data# frozen_string_literal: true require 'countries' require 'country_select/version' require 'country_select/defaults' require 'country_select/formats' require 'country_select/tag_helper' require 'country_select/country_select_helper' country_select-11.0.0/spec/0000755000004100000410000000000015146070065015621 5ustar www-datawww-datacountry_select-11.0.0/spec/spec_helper.rb0000644000004100000410000001055115146070065020441 0ustar www-datawww-data# frozen_string_literal: true require 'pry' require 'simplecov' SimpleCov.start # This file was generated by the `rspec --init` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # The generated `.rspec` file contains `--require spec_helper` which will cause this # file to always be loaded, without a need to explicitly require it in any files. # # Given that it is always loaded, you are encouraged to keep this file as # light-weight as possible. Requiring heavyweight dependencies from this file # will add to the boot time of your test suite on EVERY test run, even for an # individual file that may not need all of that loaded. Instead, consider making # a separate helper file that requires the additional dependencies and performs # the additional setup, and require it from the spec files that actually need it. # # The `.rspec` file also contains a few flags that are not defaults but that # users commonly want. # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| # rspec-expectations config goes here. You can use an alternate # assertion/expectation library such as wrong or the stdlib/minitest # assertions if you prefer. config.expect_with :rspec do |expectations| # This option will default to `true` in RSpec 4. It makes the `description` # and `failure_message` of custom matchers include text for helper methods # defined using `chain`, e.g.: # be_bigger_than(2).and_smaller_than(4).description # # => "be bigger than 2 and smaller than 4" # ...rather than: # # => "be bigger than 2" expectations.include_chain_clauses_in_custom_matcher_descriptions = true end # rspec-mocks config goes here. You can use an alternate test double # library (such as bogus or mocha) by changing the `mock_with` option here. config.mock_with :rspec do |mocks| # Prevents you from mocking or stubbing a method that does not exist on # a real object. This is generally recommended, and will default to # `true` in RSpec 4. mocks.verify_partial_doubles = true end # The settings below are suggested to provide a good initial experience # with RSpec, but feel free to customize to your heart's content. #=begin # These two settings work together to allow you to limit a spec run # to individual examples or groups you care about by tagging them with # `:focus` metadata. When nothing is tagged with `:focus`, all examples # get run. config.filter_run :focus config.run_all_when_everything_filtered = true # Limits the available syntax to the non-monkey patched syntax that is recommended. # For more details, see: # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching # config.disable_monkey_patching! # This setting enables warnings. It's recommended, but in some cases may # be too noisy due to issues in dependencies. # config.warnings = true # Many RSpec users commonly either run the entire suite or an individual # file, and it's useful to allow more verbose output when running an # individual spec file. if config.files_to_run.one? # Use the documentation formatter for detailed output, # unless a formatter has already been configured # (e.g. via a command-line flag). config.default_formatter = 'doc' end # Print the 10 slowest examples and example groups at the # end of the spec run, to help surface which specs are running # particularly slow. # config.profile_examples = 10 # Run specs in random order to surface order dependencies. If you find an # order dependency and want to debug it, you can fix the order by providing # the seed, which is printed after each run. # --seed 1234 config.order = :random # Seed global randomization in this process using the `--seed` CLI option. # Setting this allows you to use `--seed` to deterministically reproduce # test failures related to randomization by passing the same `--seed` value # as the one that triggered the failure. Kernel.srand config.seed #=end # non-default settings config.raise_errors_for_deprecations! config.before do I18n.config.enforce_available_locales = false end end country_select-11.0.0/spec/country_select_spec.rb0000644000004100000410000002117615146070065022231 0ustar www-datawww-data# frozen_string_literal: true require 'spec_helper' require 'uri' require 'action_view' require 'country_select' class Walrus attr_accessor :country_code end describe 'CountrySelect' do include ActionView::Helpers::TagHelper include ActionView::Helpers::FormOptionsHelper before do I18n.available_locales = [:en] I18n.locale = :en ISO3166.reset end let(:walrus) { Walrus.new } let!(:template) { ActionView::Base.new(ActionView::LookupContext.new([]), {}, nil) } let(:builder) do if defined?(ActionView::Helpers::Tags::Base) ActionView::Helpers::FormBuilder.new(:walrus, walrus, template, {}) else ActionView::Helpers::FormBuilder.new(:walrus, walrus, template, {}, proc {}) end end let(:select_tag) do <<-HTML.chomp.strip