list_select 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +106 -0
- data/Rakefile +3 -0
- data/init.rb +1 -0
- data/lib/generators/USAGE +15 -0
- data/lib/generators/list_select_generator.rb +7 -0
- data/lib/generators/templates/countries_cldr.en.rb +280 -0
- data/lib/generators/templates/countries_iso3166_1_alpha_2.en.rb +259 -0
- data/lib/generators/templates/google_adwords_countries.en.rb +246 -0
- data/lib/generators/templates/google_adwords_languages.en.rb +47 -0
- data/lib/generators/templates/google_interface_languages.en.rb +130 -0
- data/lib/generators/templates/google_search_languages.en.rb +51 -0
- data/lib/generators/templates/languages_cldr.en.rb +516 -0
- data/lib/list_select.rb +68 -0
- data/lib/list_select/version.rb +3 -0
- data/list_select.gemspec +25 -0
- metadata +74 -0
data/lib/list_select.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
module ActionView
|
2
|
+
module Helpers
|
3
|
+
|
4
|
+
module FormOptionsHelper
|
5
|
+
def list_select(object, method, list, options = {}, html_options = {})
|
6
|
+
InstanceTag.new(object, method, self, options.delete(:object)).to_list_select_tag(list, options, html_options)
|
7
|
+
end
|
8
|
+
|
9
|
+
def list_select_tag(name, list, options={}, html_options = {})
|
10
|
+
content_tag :select,
|
11
|
+
list_options_for_select(list, options[:default], options[:priority_items]),
|
12
|
+
{ "name" => name, "id" => name }.update(html_options.stringify_keys)
|
13
|
+
end
|
14
|
+
|
15
|
+
def list_options_for_select(list, selected = nil, priority_items = nil)
|
16
|
+
list_options = ""
|
17
|
+
items = I18n.translate(list)
|
18
|
+
unless priority_items.blank?
|
19
|
+
list_options += options_for_select(priority_items.map{|key| [items[key], key.to_s]}, selected)
|
20
|
+
list_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
|
21
|
+
end
|
22
|
+
return list_options + options_for_select(items.map{|k, v| [v, k.to_s]}.sort, selected)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class InstanceTag
|
27
|
+
def to_list_select_tag(list, options, html_options)
|
28
|
+
html_options = html_options.stringify_keys
|
29
|
+
add_default_name_and_id(html_options)
|
30
|
+
value = value(object)
|
31
|
+
content_tag("select",
|
32
|
+
add_options(
|
33
|
+
list_options_for_select(list, value || options[:default], options[:priority_items] || []),
|
34
|
+
options, value
|
35
|
+
), html_options
|
36
|
+
)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class FormBuilder
|
41
|
+
def list_select(method, list, options = {}, html_options = {})
|
42
|
+
@template.list_select(@object_name, method, list, objectify_options(options), @default_options.merge(html_options))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# country_select helper for integration with SimpleForm and Formtastic
|
50
|
+
module ActionView
|
51
|
+
module Helpers
|
52
|
+
module FormOptionsHelper
|
53
|
+
def country_select(object, method, priority_countries = nil, options = {}, html_options = {})
|
54
|
+
options = options.merge(:priority_items => priority_countries) if priority_countries
|
55
|
+
list = options.delete(:list) || :countries_cldr
|
56
|
+
list_select(object, method, list, options, html_options)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
class FormBuilder
|
60
|
+
def country_select(method, priority_countries = nil, options = {}, html_options = {})
|
61
|
+
options = options.merge(:priority_items => priority_countries) if priority_countries
|
62
|
+
list = options.delete(:list) || :countries_cldr
|
63
|
+
list_select(method, list, options, html_options)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
data/list_select.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "list_select/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "list_select"
|
7
|
+
s.version = ListSelect::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Dmitry Naumov"]
|
10
|
+
s.email = ["naumovmail@gmail.com"]
|
11
|
+
s.homepage = "http://github.com/bitzesty/list_select"
|
12
|
+
s.summary = %q{Localiazed select lists helper.}
|
13
|
+
s.description = %Q{
|
14
|
+
Provides a simple helper to get an HTML select list of any lists defined in your locales files.
|
15
|
+
Has builtin lists for selecting countries, languages and more.
|
16
|
+
Adds country_select helper to integrate with SimpleForm and Formtastic.
|
17
|
+
}
|
18
|
+
|
19
|
+
s.rubyforge_project = "list_select"
|
20
|
+
|
21
|
+
s.files = `git ls-files`.split("\n")
|
22
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: list_select
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dmitry Naumov
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-11-01 00:00:00 +03:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: "\n Provides a simple helper to get an HTML select list of any lists defined in your locales files.\n Has builtin lists for selecting countries, languages and more.\n Adds country_select helper to integrate with SimpleForm and Formtastic.\n "
|
18
|
+
email:
|
19
|
+
- naumovmail@gmail.com
|
20
|
+
executables: []
|
21
|
+
|
22
|
+
extensions: []
|
23
|
+
|
24
|
+
extra_rdoc_files: []
|
25
|
+
|
26
|
+
files:
|
27
|
+
- .gitignore
|
28
|
+
- Gemfile
|
29
|
+
- MIT-LICENSE
|
30
|
+
- README.rdoc
|
31
|
+
- Rakefile
|
32
|
+
- init.rb
|
33
|
+
- lib/generators/USAGE
|
34
|
+
- lib/generators/list_select_generator.rb
|
35
|
+
- lib/generators/templates/countries_cldr.en.rb
|
36
|
+
- lib/generators/templates/countries_iso3166_1_alpha_2.en.rb
|
37
|
+
- lib/generators/templates/google_adwords_countries.en.rb
|
38
|
+
- lib/generators/templates/google_adwords_languages.en.rb
|
39
|
+
- lib/generators/templates/google_interface_languages.en.rb
|
40
|
+
- lib/generators/templates/google_search_languages.en.rb
|
41
|
+
- lib/generators/templates/languages_cldr.en.rb
|
42
|
+
- lib/list_select.rb
|
43
|
+
- lib/list_select/version.rb
|
44
|
+
- list_select.gemspec
|
45
|
+
has_rdoc: true
|
46
|
+
homepage: http://github.com/bitzesty/list_select
|
47
|
+
licenses: []
|
48
|
+
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project: list_select
|
69
|
+
rubygems_version: 1.6.2
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Localiazed select lists helper.
|
73
|
+
test_files: []
|
74
|
+
|