Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use <hr> as divider #229

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ Pre-selecting a particular country:
country_select("user", "country", selected: "GB")
```

Changing the divider when priority_countries is active.
```ruby
country_select("user", "country", priority_countries: ["AR", "US"], priority_countries_divider: "~~~~~~")
```

Using existing `select` options:
```ruby
country_select("user", "country", include_blank: true)
Expand Down Expand Up @@ -126,7 +121,7 @@ country_select("user", "country", format: :with_data_attrs)
### Using customized defaults

You can configure overridable defaults for `except`, `format`, `locale`,
`only`, `priority_countries` and `priority_countries_divider` in an initializer.
`only` and `priority_countries` in an initializer.

````ruby
# config/initializers/country_select.rb
Expand Down
1 change: 0 additions & 1 deletion lib/country_select/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module CountrySelect
locale: nil,
only: nil,
priority_countries: nil,
priority_countries_divider: '-' * 15,
sort_provided: true
}
end
8 changes: 1 addition & 7 deletions lib/country_select/tag_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ def priority_countries
@options.fetch(:priority_countries, ::CountrySelect::DEFAULTS[:priority_countries])
end

def priority_countries_divider
@options.fetch(:priority_countries_divider, ::CountrySelect::DEFAULTS[:priority_countries_divider])
end

def only_country_codes
@options.fetch(:only, ::CountrySelect::DEFAULTS[:only])
end
Expand Down Expand Up @@ -98,9 +94,7 @@ def options_for_select_with_priority_countries(country_options, tags_options)
end

def priority_options_for_select(priority_countries_options, tags_options)
option_tags = options_for_select(priority_countries_options, tags_options)
option_tags += "\n".html_safe +
options_for_select([priority_countries_divider], disabled: priority_countries_divider)
options_for_select(priority_countries_options, tags_options) + "\n<hr>".html_safe
end

def get_formatted_country(code_or_name)
Expand Down
31 changes: 13 additions & 18 deletions spec/country_select_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,10 @@ class Walrus
[
['Denmark', 'DK'],
['Latvia', 'LV'],
['United States', 'US'],
['-' * 15, '-' * 15]
['United States', 'US']
],
selected: 'US',
disabled: '-' * 15
)
selected: 'US'
) + "\n<hr>".html_safe

walrus.country_code = 'US'
t = builder.country_select(:country_code, priority_countries: %w[LV US DK])
Expand All @@ -112,12 +110,10 @@ class Walrus
[
['Denmark', 'DK'],
['Latvia', 'LV'],
['United States', 'US'],
['-' * 15, '-' * 15]
['United States', 'US']
],
selected: 'US',
disabled: '-' * 15
)
selected: 'US'
) + "\n<hr>".html_safe

walrus.country_code = 'US'
t = builder.country_select(:country_code, priority_countries: %w[LV US DK])
Expand All @@ -129,12 +125,10 @@ class Walrus
[
['Latvia', 'LV'],
['United States', 'US'],
['Denmark', 'DK'],
['-' * 15, '-' * 15]
['Denmark', 'DK']
],
selected: 'US',
disabled: '-' * 15
)
) + "\n<hr>".html_safe

walrus.country_code = 'US'
t = builder.country_select(:country_code, priority_countries: %w[LV US DK], sort_provided: false)
Expand All @@ -146,12 +140,13 @@ class Walrus
[
['Latvia', 'LV'],
['United States', 'US'],
['Denmark', 'DK'],
['-' * 15, '-' * 15],
['Denmark', 'DK']
]
) + "\n<hr>\n".html_safe + options_for_select(
[
['Afghanistan', 'AF']
],
selected: 'AF',
disabled: '-' * 15
selected: 'AF'
)

walrus.country_code = 'AF'
Expand Down