language_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/Appraisals +15 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +62 -0
- data/MIT-LICENSE +20 -0
- data/README.md +63 -0
- data/Rakefile +24 -0
- data/gemfiles/actionpack3.0.gemfile +7 -0
- data/gemfiles/actionpack3.0.gemfile.lock +64 -0
- data/gemfiles/actionpack3.1.gemfile +7 -0
- data/gemfiles/actionpack3.1.gemfile.lock +72 -0
- data/gemfiles/actionpack3.2.gemfile +7 -0
- data/gemfiles/actionpack3.2.gemfile.lock +71 -0
- data/gemfiles/actionpack4.0.gemfile +7 -0
- data/gemfiles/actionpack4.0.gemfile.lock +62 -0
- data/language_select.gemspec +30 -0
- data/lib/language_select/languages.rb +60 -0
- data/lib/language_select/version.rb +3 -0
- data/lib/language_select.rb +105 -0
- data/spec/language_select_spec.rb +87 -0
- data/spec/spec_helper.rb +20 -0
- metadata +137 -0
data/Appraisals
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
appraise 'actionpack3.0' do
|
|
2
|
+
gem 'actionpack', '~> 3.0.0'
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
appraise 'actionpack3.1' do
|
|
6
|
+
gem 'actionpack', '~> 3.1.0'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
appraise 'actionpack3.2' do
|
|
10
|
+
gem 'actionpack', '~> 3.2.0'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
appraise 'actionpack4.0' do
|
|
14
|
+
gem 'actionpack', '~> 4.0.0'
|
|
15
|
+
end
|
data/CHANGELOG.md
ADDED
|
File without changes
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
language_select (0.0.1)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
actionpack (4.0.2)
|
|
10
|
+
activesupport (= 4.0.2)
|
|
11
|
+
builder (~> 3.1.0)
|
|
12
|
+
erubis (~> 2.7.0)
|
|
13
|
+
rack (~> 1.5.2)
|
|
14
|
+
rack-test (~> 0.6.2)
|
|
15
|
+
activesupport (4.0.2)
|
|
16
|
+
i18n (~> 0.6, >= 0.6.4)
|
|
17
|
+
minitest (~> 4.2)
|
|
18
|
+
multi_json (~> 1.3)
|
|
19
|
+
thread_safe (~> 0.1)
|
|
20
|
+
tzinfo (~> 0.3.37)
|
|
21
|
+
appraisal (0.5.2)
|
|
22
|
+
bundler
|
|
23
|
+
rake
|
|
24
|
+
atomic (1.1.14)
|
|
25
|
+
builder (3.1.4)
|
|
26
|
+
coderay (1.1.0)
|
|
27
|
+
diff-lcs (1.2.5)
|
|
28
|
+
erubis (2.7.0)
|
|
29
|
+
i18n (0.6.9)
|
|
30
|
+
method_source (0.8.2)
|
|
31
|
+
minitest (4.7.5)
|
|
32
|
+
multi_json (1.8.2)
|
|
33
|
+
pry (0.9.12.4)
|
|
34
|
+
coderay (~> 1.0)
|
|
35
|
+
method_source (~> 0.8)
|
|
36
|
+
slop (~> 3.4)
|
|
37
|
+
rack (1.5.2)
|
|
38
|
+
rack-test (0.6.2)
|
|
39
|
+
rack (>= 1.0)
|
|
40
|
+
rake (10.1.1)
|
|
41
|
+
rspec (2.14.1)
|
|
42
|
+
rspec-core (~> 2.14.0)
|
|
43
|
+
rspec-expectations (~> 2.14.0)
|
|
44
|
+
rspec-mocks (~> 2.14.0)
|
|
45
|
+
rspec-core (2.14.7)
|
|
46
|
+
rspec-expectations (2.14.4)
|
|
47
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
|
48
|
+
rspec-mocks (2.14.4)
|
|
49
|
+
slop (3.4.7)
|
|
50
|
+
thread_safe (0.1.3)
|
|
51
|
+
atomic
|
|
52
|
+
tzinfo (0.3.38)
|
|
53
|
+
|
|
54
|
+
PLATFORMS
|
|
55
|
+
ruby
|
|
56
|
+
|
|
57
|
+
DEPENDENCIES
|
|
58
|
+
actionpack
|
|
59
|
+
appraisal
|
|
60
|
+
language_select!
|
|
61
|
+
pry
|
|
62
|
+
rspec
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2008 Michael Koziarski
|
|
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.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Rails – Language Select
|
|
2
|
+
[](https://travis-ci.org/apide/language_select)
|
|
3
|
+
|
|
4
|
+
Provides a simple helper to get an HTML select list of languages using the
|
|
5
|
+
[ISO 639-1 standard](https://en.wikipedia.org/wiki/ISO_639-1).
|
|
6
|
+
|
|
7
|
+
Uses the two letter alpha codes to identify the language.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
Install as a gem using
|
|
12
|
+
|
|
13
|
+
```shell
|
|
14
|
+
gem install language_select
|
|
15
|
+
```
|
|
16
|
+
Or put the following in your Gemfile
|
|
17
|
+
|
|
18
|
+
```ruby
|
|
19
|
+
gem 'language_select'
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Example
|
|
23
|
+
|
|
24
|
+
Simple use supplying model and attribute as parameters:
|
|
25
|
+
|
|
26
|
+
```ruby
|
|
27
|
+
language_select("user", "language")
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Supplying priority languages to be placed at the top of the list:
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
language_select("user", "language", [ "English", "French", "German" ])
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The language is stored using the ISO-639-1 two letter codes.
|
|
37
|
+
|
|
38
|
+
#### Getting the Language from ISO codes
|
|
39
|
+
|
|
40
|
+
```ruby
|
|
41
|
+
class User < ActiveRecord::Base
|
|
42
|
+
|
|
43
|
+
def language_name
|
|
44
|
+
::LanguageSelect::LANGUAGES[language]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Tests
|
|
51
|
+
|
|
52
|
+
```shell
|
|
53
|
+
bundle
|
|
54
|
+
bundle exec rspec
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Running with multiple versions of actionpack
|
|
58
|
+
|
|
59
|
+
```shell
|
|
60
|
+
bundle exec appraisal
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Copyright (c) 2013 Apide ApS, released under the MIT license
|
data/Rakefile
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'bundler/setup'
|
|
3
|
+
require 'bundler/gem_tasks'
|
|
4
|
+
|
|
5
|
+
require 'appraisal'
|
|
6
|
+
|
|
7
|
+
require 'rspec/core/rake_task'
|
|
8
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
9
|
+
|
|
10
|
+
task :default => :spec
|
|
11
|
+
|
|
12
|
+
namespace :appraisal do
|
|
13
|
+
desc "Run the given task for a particular integration's appraisals"
|
|
14
|
+
task :integration do
|
|
15
|
+
Appraisal::File.each do |appraisal|
|
|
16
|
+
if RUBY_VERSION < '1.9.3' and appraisal.name == 'actionpack4.0'
|
|
17
|
+
# skip rails 4 for ruby < 1.9.3
|
|
18
|
+
else
|
|
19
|
+
appraisal.install
|
|
20
|
+
Appraisal::Command.from_args(appraisal.gemfile_path).run
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: /home/eiler/Documents/apide/apide-language_select
|
|
3
|
+
specs:
|
|
4
|
+
language_select (0.0.1)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
abstract (1.0.0)
|
|
10
|
+
actionpack (3.0.20)
|
|
11
|
+
activemodel (= 3.0.20)
|
|
12
|
+
activesupport (= 3.0.20)
|
|
13
|
+
builder (~> 2.1.2)
|
|
14
|
+
erubis (~> 2.6.6)
|
|
15
|
+
i18n (~> 0.5.0)
|
|
16
|
+
rack (~> 1.2.5)
|
|
17
|
+
rack-mount (~> 0.6.14)
|
|
18
|
+
rack-test (~> 0.5.7)
|
|
19
|
+
tzinfo (~> 0.3.23)
|
|
20
|
+
activemodel (3.0.20)
|
|
21
|
+
activesupport (= 3.0.20)
|
|
22
|
+
builder (~> 2.1.2)
|
|
23
|
+
i18n (~> 0.5.0)
|
|
24
|
+
activesupport (3.0.20)
|
|
25
|
+
appraisal (0.5.2)
|
|
26
|
+
bundler
|
|
27
|
+
rake
|
|
28
|
+
builder (2.1.2)
|
|
29
|
+
coderay (1.0.9)
|
|
30
|
+
diff-lcs (1.2.4)
|
|
31
|
+
erubis (2.6.6)
|
|
32
|
+
abstract (>= 1.0.0)
|
|
33
|
+
i18n (0.5.0)
|
|
34
|
+
method_source (0.8.1)
|
|
35
|
+
pry (0.9.12.2)
|
|
36
|
+
coderay (~> 1.0.5)
|
|
37
|
+
method_source (~> 0.8)
|
|
38
|
+
slop (~> 3.4)
|
|
39
|
+
rack (1.2.8)
|
|
40
|
+
rack-mount (0.6.14)
|
|
41
|
+
rack (>= 1.0.0)
|
|
42
|
+
rack-test (0.5.7)
|
|
43
|
+
rack (>= 1.0)
|
|
44
|
+
rake (10.0.4)
|
|
45
|
+
rspec (2.13.0)
|
|
46
|
+
rspec-core (~> 2.13.0)
|
|
47
|
+
rspec-expectations (~> 2.13.0)
|
|
48
|
+
rspec-mocks (~> 2.13.0)
|
|
49
|
+
rspec-core (2.13.1)
|
|
50
|
+
rspec-expectations (2.13.0)
|
|
51
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
|
52
|
+
rspec-mocks (2.13.1)
|
|
53
|
+
slop (3.4.5)
|
|
54
|
+
tzinfo (0.3.37)
|
|
55
|
+
|
|
56
|
+
PLATFORMS
|
|
57
|
+
ruby
|
|
58
|
+
|
|
59
|
+
DEPENDENCIES
|
|
60
|
+
actionpack (~> 3.0.0)
|
|
61
|
+
appraisal
|
|
62
|
+
country_select!
|
|
63
|
+
pry
|
|
64
|
+
rspec
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: /home/eiler/Documents/apide/apide-language_select
|
|
3
|
+
specs:
|
|
4
|
+
language_select (0.0.1)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
actionpack (3.1.12)
|
|
10
|
+
activemodel (= 3.1.12)
|
|
11
|
+
activesupport (= 3.1.12)
|
|
12
|
+
builder (~> 3.0.0)
|
|
13
|
+
erubis (~> 2.7.0)
|
|
14
|
+
i18n (~> 0.6)
|
|
15
|
+
rack (~> 1.3.6)
|
|
16
|
+
rack-cache (~> 1.2)
|
|
17
|
+
rack-mount (~> 0.8.2)
|
|
18
|
+
rack-test (~> 0.6.1)
|
|
19
|
+
sprockets (~> 2.0.4)
|
|
20
|
+
activemodel (3.1.12)
|
|
21
|
+
activesupport (= 3.1.12)
|
|
22
|
+
builder (~> 3.0.0)
|
|
23
|
+
i18n (~> 0.6)
|
|
24
|
+
activesupport (3.1.12)
|
|
25
|
+
multi_json (~> 1.0)
|
|
26
|
+
appraisal (0.5.2)
|
|
27
|
+
bundler
|
|
28
|
+
rake
|
|
29
|
+
builder (3.0.4)
|
|
30
|
+
coderay (1.0.9)
|
|
31
|
+
diff-lcs (1.2.4)
|
|
32
|
+
erubis (2.7.0)
|
|
33
|
+
hike (1.2.2)
|
|
34
|
+
i18n (0.6.4)
|
|
35
|
+
method_source (0.8.1)
|
|
36
|
+
multi_json (1.7.3)
|
|
37
|
+
pry (0.9.12.2)
|
|
38
|
+
coderay (~> 1.0.5)
|
|
39
|
+
method_source (~> 0.8)
|
|
40
|
+
slop (~> 3.4)
|
|
41
|
+
rack (1.3.10)
|
|
42
|
+
rack-cache (1.2)
|
|
43
|
+
rack (>= 0.4)
|
|
44
|
+
rack-mount (0.8.3)
|
|
45
|
+
rack (>= 1.0.0)
|
|
46
|
+
rack-test (0.6.2)
|
|
47
|
+
rack (>= 1.0)
|
|
48
|
+
rake (10.0.4)
|
|
49
|
+
rspec (2.13.0)
|
|
50
|
+
rspec-core (~> 2.13.0)
|
|
51
|
+
rspec-expectations (~> 2.13.0)
|
|
52
|
+
rspec-mocks (~> 2.13.0)
|
|
53
|
+
rspec-core (2.13.1)
|
|
54
|
+
rspec-expectations (2.13.0)
|
|
55
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
|
56
|
+
rspec-mocks (2.13.1)
|
|
57
|
+
slop (3.4.5)
|
|
58
|
+
sprockets (2.0.4)
|
|
59
|
+
hike (~> 1.2)
|
|
60
|
+
rack (~> 1.0)
|
|
61
|
+
tilt (~> 1.1, != 1.3.0)
|
|
62
|
+
tilt (1.4.1)
|
|
63
|
+
|
|
64
|
+
PLATFORMS
|
|
65
|
+
ruby
|
|
66
|
+
|
|
67
|
+
DEPENDENCIES
|
|
68
|
+
actionpack (~> 3.1.0)
|
|
69
|
+
appraisal
|
|
70
|
+
country_select!
|
|
71
|
+
pry
|
|
72
|
+
rspec
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: /home/eiler/Documents/apide/apide-language_select
|
|
3
|
+
specs:
|
|
4
|
+
language_select (0.0.1)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
actionpack (3.2.13)
|
|
10
|
+
activemodel (= 3.2.13)
|
|
11
|
+
activesupport (= 3.2.13)
|
|
12
|
+
builder (~> 3.0.0)
|
|
13
|
+
erubis (~> 2.7.0)
|
|
14
|
+
journey (~> 1.0.4)
|
|
15
|
+
rack (~> 1.4.5)
|
|
16
|
+
rack-cache (~> 1.2)
|
|
17
|
+
rack-test (~> 0.6.1)
|
|
18
|
+
sprockets (~> 2.2.1)
|
|
19
|
+
activemodel (3.2.13)
|
|
20
|
+
activesupport (= 3.2.13)
|
|
21
|
+
builder (~> 3.0.0)
|
|
22
|
+
activesupport (3.2.13)
|
|
23
|
+
i18n (= 0.6.1)
|
|
24
|
+
multi_json (~> 1.0)
|
|
25
|
+
appraisal (0.5.2)
|
|
26
|
+
bundler
|
|
27
|
+
rake
|
|
28
|
+
builder (3.0.4)
|
|
29
|
+
coderay (1.0.9)
|
|
30
|
+
diff-lcs (1.2.4)
|
|
31
|
+
erubis (2.7.0)
|
|
32
|
+
hike (1.2.2)
|
|
33
|
+
i18n (0.6.1)
|
|
34
|
+
journey (1.0.4)
|
|
35
|
+
method_source (0.8.1)
|
|
36
|
+
multi_json (1.7.3)
|
|
37
|
+
pry (0.9.12.2)
|
|
38
|
+
coderay (~> 1.0.5)
|
|
39
|
+
method_source (~> 0.8)
|
|
40
|
+
slop (~> 3.4)
|
|
41
|
+
rack (1.4.5)
|
|
42
|
+
rack-cache (1.2)
|
|
43
|
+
rack (>= 0.4)
|
|
44
|
+
rack-test (0.6.2)
|
|
45
|
+
rack (>= 1.0)
|
|
46
|
+
rake (10.0.4)
|
|
47
|
+
rspec (2.13.0)
|
|
48
|
+
rspec-core (~> 2.13.0)
|
|
49
|
+
rspec-expectations (~> 2.13.0)
|
|
50
|
+
rspec-mocks (~> 2.13.0)
|
|
51
|
+
rspec-core (2.13.1)
|
|
52
|
+
rspec-expectations (2.13.0)
|
|
53
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
|
54
|
+
rspec-mocks (2.13.1)
|
|
55
|
+
slop (3.4.5)
|
|
56
|
+
sprockets (2.2.2)
|
|
57
|
+
hike (~> 1.2)
|
|
58
|
+
multi_json (~> 1.0)
|
|
59
|
+
rack (~> 1.0)
|
|
60
|
+
tilt (~> 1.1, != 1.3.0)
|
|
61
|
+
tilt (1.4.1)
|
|
62
|
+
|
|
63
|
+
PLATFORMS
|
|
64
|
+
ruby
|
|
65
|
+
|
|
66
|
+
DEPENDENCIES
|
|
67
|
+
actionpack (~> 3.2.0)
|
|
68
|
+
appraisal
|
|
69
|
+
country_select!
|
|
70
|
+
pry
|
|
71
|
+
rspec
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: /home/eiler/Documents/apide/apide-language_select
|
|
3
|
+
specs:
|
|
4
|
+
language_select (0.0.1)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
actionpack (4.0.0)
|
|
10
|
+
activesupport (= 4.0.0)
|
|
11
|
+
builder (~> 3.1.0)
|
|
12
|
+
erubis (~> 2.7.0)
|
|
13
|
+
rack (~> 1.5.2)
|
|
14
|
+
rack-test (~> 0.6.2)
|
|
15
|
+
activesupport (4.0.0)
|
|
16
|
+
i18n (~> 0.6, >= 0.6.4)
|
|
17
|
+
minitest (~> 4.2)
|
|
18
|
+
multi_json (~> 1.3)
|
|
19
|
+
thread_safe (~> 0.1)
|
|
20
|
+
tzinfo (~> 0.3.37)
|
|
21
|
+
appraisal (0.5.2)
|
|
22
|
+
bundler
|
|
23
|
+
rake
|
|
24
|
+
atomic (1.1.10)
|
|
25
|
+
builder (3.1.4)
|
|
26
|
+
coderay (1.0.9)
|
|
27
|
+
diff-lcs (1.2.4)
|
|
28
|
+
erubis (2.7.0)
|
|
29
|
+
i18n (0.6.4)
|
|
30
|
+
method_source (0.8.1)
|
|
31
|
+
minitest (4.7.5)
|
|
32
|
+
multi_json (1.7.7)
|
|
33
|
+
pry (0.9.12.2)
|
|
34
|
+
coderay (~> 1.0.5)
|
|
35
|
+
method_source (~> 0.8)
|
|
36
|
+
slop (~> 3.4)
|
|
37
|
+
rack (1.5.2)
|
|
38
|
+
rack-test (0.6.2)
|
|
39
|
+
rack (>= 1.0)
|
|
40
|
+
rake (10.1.0)
|
|
41
|
+
rspec (2.13.0)
|
|
42
|
+
rspec-core (~> 2.13.0)
|
|
43
|
+
rspec-expectations (~> 2.13.0)
|
|
44
|
+
rspec-mocks (~> 2.13.0)
|
|
45
|
+
rspec-core (2.13.1)
|
|
46
|
+
rspec-expectations (2.13.0)
|
|
47
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
|
48
|
+
rspec-mocks (2.13.1)
|
|
49
|
+
slop (3.4.5)
|
|
50
|
+
thread_safe (0.1.0)
|
|
51
|
+
atomic
|
|
52
|
+
tzinfo (0.3.37)
|
|
53
|
+
|
|
54
|
+
PLATFORMS
|
|
55
|
+
ruby
|
|
56
|
+
|
|
57
|
+
DEPENDENCIES
|
|
58
|
+
actionpack (~> 4.0.0)
|
|
59
|
+
appraisal
|
|
60
|
+
country_select!
|
|
61
|
+
pry
|
|
62
|
+
rspec
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
|
3
|
+
require 'language_select/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = 'language_select'
|
|
7
|
+
s.version = LanguageSelect::VERSION
|
|
8
|
+
s.authors = ['Jacob Eiler']
|
|
9
|
+
s.email = ['jacob.eiler@apide.com']
|
|
10
|
+
s.homepage = 'https://github.com/apide/language_select'
|
|
11
|
+
s.summary = %q{Language Select Plugin}
|
|
12
|
+
s.description = %q{Provides a simple helper to get an HTML select list of ISO-639-1 languages. The list of languages is obtained from Wikipedia (http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes).}
|
|
13
|
+
|
|
14
|
+
s.rubyforge_project = 'language_select'
|
|
15
|
+
|
|
16
|
+
s.files = `git ls-files`.split("\n")
|
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
19
|
+
s.require_paths = ['lib']
|
|
20
|
+
|
|
21
|
+
# specify any dependencies here; for example:
|
|
22
|
+
s.add_development_dependency 'rspec'
|
|
23
|
+
if RUBY_VERSION < '1.9.3'
|
|
24
|
+
s.add_development_dependency 'actionpack', '~> 3.2.13'
|
|
25
|
+
else
|
|
26
|
+
s.add_development_dependency 'actionpack'
|
|
27
|
+
end
|
|
28
|
+
s.add_development_dependency 'appraisal'
|
|
29
|
+
s.add_development_dependency 'pry'
|
|
30
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module LanguageSelect
|
|
4
|
+
|
|
5
|
+
LANGUAGES = {
|
|
6
|
+
"ab" => "Abkhaz",
|
|
7
|
+
"ar" => "Arabic",
|
|
8
|
+
"be" => "Belarusian",
|
|
9
|
+
"bs" => "Bosnian",
|
|
10
|
+
"bg" => "Bulgarian",
|
|
11
|
+
"da" => "Danish",
|
|
12
|
+
"el" => "Greek",
|
|
13
|
+
"en" => "English",
|
|
14
|
+
"es" => "Spanish",
|
|
15
|
+
"et" => "Estonian",
|
|
16
|
+
"fa" => "Persian (Farsi)",
|
|
17
|
+
"fi" => "Finnish",
|
|
18
|
+
"fr" => "French",
|
|
19
|
+
"ga" => "Irish",
|
|
20
|
+
"he" => "Hebrew",
|
|
21
|
+
"hi" => "Hindi",
|
|
22
|
+
"hr" => "Croatian",
|
|
23
|
+
"hu" => "Hungarian",
|
|
24
|
+
"hy" => "Armenian",
|
|
25
|
+
"id" => "Indonesian",
|
|
26
|
+
"is" => "Icelandic",
|
|
27
|
+
"it" => "Italian",
|
|
28
|
+
"ja" => "Janapese",
|
|
29
|
+
"ko" => "Korean",
|
|
30
|
+
"ku" => "Kurdish",
|
|
31
|
+
"lo" => "Lao",
|
|
32
|
+
"lt" => "Lithuanian",
|
|
33
|
+
"lv" => "Latvian",
|
|
34
|
+
"mk" => "Macedonian",
|
|
35
|
+
"ms" => "Malay",
|
|
36
|
+
"nl" => "Dutch",
|
|
37
|
+
"no" => "Norwegian",
|
|
38
|
+
"pa" => "Panjabi",
|
|
39
|
+
"pl" => "Polish",
|
|
40
|
+
"ps" => "Pashto",
|
|
41
|
+
"pt" => "Portuguese",
|
|
42
|
+
"ro" => "Romanian",
|
|
43
|
+
"ru" => "Russian",
|
|
44
|
+
"se" => "Swedish",
|
|
45
|
+
"sk" => "Slovak",
|
|
46
|
+
"sl" => "Slovene",
|
|
47
|
+
"sr" => "Serbian",
|
|
48
|
+
"sq" => "Albanian",
|
|
49
|
+
"th" => "Thai",
|
|
50
|
+
"tr" => "Turkish",
|
|
51
|
+
"uk" => "Ukranian",
|
|
52
|
+
"ur" => "Urdu",
|
|
53
|
+
"vi" => "Vietnamese",
|
|
54
|
+
"zh" => "Chinese",
|
|
55
|
+
"zu" => "Zulu"
|
|
56
|
+
} unless const_defined?("LANGUAGES")
|
|
57
|
+
|
|
58
|
+
LANGUAGES_FOR_SELECT = LANGUAGES.invert unless const_defined?("LANGUAGES_FOR_SELECT")
|
|
59
|
+
|
|
60
|
+
end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# LanguageSelect
|
|
2
|
+
#
|
|
3
|
+
# Adds #language_select method to
|
|
4
|
+
# ActionView::FormBuilder
|
|
5
|
+
#
|
|
6
|
+
require 'language_select/version'
|
|
7
|
+
require 'language_select/languages'
|
|
8
|
+
|
|
9
|
+
module ActionView
|
|
10
|
+
module Helpers
|
|
11
|
+
module FormOptionsHelper
|
|
12
|
+
#
|
|
13
|
+
# Return select and option tags for the given object and method,
|
|
14
|
+
# using language_options_for_select to generate the list of option tags.
|
|
15
|
+
#
|
|
16
|
+
def language_select(object, method, priority_languages = nil,
|
|
17
|
+
options = {},
|
|
18
|
+
html_options = {})
|
|
19
|
+
|
|
20
|
+
tag = if defined?(ActionView::Helpers::InstanceTag) &&
|
|
21
|
+
ActionView::Helpers::InstanceTag.instance_method(:initialize).arity != 0
|
|
22
|
+
|
|
23
|
+
InstanceTag.new(object, method, self, options.delete(:object))
|
|
24
|
+
else
|
|
25
|
+
LanguageSelect.new(object, method, self, options)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
tag.to_language_select_tag(priority_languages, options, html_options)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
#
|
|
32
|
+
# Returns a string of option tags for most languages throughout the World.
|
|
33
|
+
#
|
|
34
|
+
# You can also supply an array of languages as +priority_languages+. They
|
|
35
|
+
# will be listed at the top of the (long) list.
|
|
36
|
+
#
|
|
37
|
+
# NOTE: Only the option tags are returned, you have to wrap this call in
|
|
38
|
+
# a regular HTML select tag.
|
|
39
|
+
#
|
|
40
|
+
def language_options_for_select(selected = nil, priority_languages = nil)
|
|
41
|
+
language_options = "".html_safe
|
|
42
|
+
|
|
43
|
+
if priority_languages then
|
|
44
|
+
priority_languages_options = priority_languages.map do |code|
|
|
45
|
+
[
|
|
46
|
+
::LanguageSelect::LANGUAGES[code],
|
|
47
|
+
code
|
|
48
|
+
]
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
language_options += options_for_select(priority_languages_options, selected)
|
|
52
|
+
language_options += '<option value="" disabled="disabled">-------------</option>\n'.html_safe
|
|
53
|
+
#
|
|
54
|
+
# prevents selected from being included
|
|
55
|
+
# twice in the HTML which causes
|
|
56
|
+
# some browsers to select the second
|
|
57
|
+
# selected option (not priority)
|
|
58
|
+
# which makes it harder to select an
|
|
59
|
+
# alternative priority language
|
|
60
|
+
#
|
|
61
|
+
selected = nil if priority_languages.include?(selected)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
return language_options + options_for_select(::LanguageSelect::LANGUAGES_FOR_SELECT, selected)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
module ToLanguageSelectTag
|
|
70
|
+
def to_language_select_tag(priority_languages, options, html_options)
|
|
71
|
+
html_options = html_options.stringify_keys
|
|
72
|
+
add_default_name_and_id(html_options)
|
|
73
|
+
value = value(object)
|
|
74
|
+
content_tag("select",
|
|
75
|
+
add_options(
|
|
76
|
+
language_options_for_select(value, priority_languages),
|
|
77
|
+
options, value
|
|
78
|
+
), html_options
|
|
79
|
+
)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
if defined?(ActionView::Helpers::InstanceTag) &&
|
|
84
|
+
ActionView::Helpers::InstanceTag.instance_method(:initialize).arity != 0
|
|
85
|
+
class InstanceTag
|
|
86
|
+
include ToCountrySelectTag
|
|
87
|
+
end
|
|
88
|
+
else
|
|
89
|
+
class LanguageSelect < Tags::Base
|
|
90
|
+
include ToLanguageSelectTag
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
class FormBuilder
|
|
95
|
+
def language_select(method, priority_languages = nil,
|
|
96
|
+
options = {},
|
|
97
|
+
html_options = {})
|
|
98
|
+
|
|
99
|
+
@template.language_select(@object_name, method, priority_languages,
|
|
100
|
+
options.merge(:object => @object),
|
|
101
|
+
html_options)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Copyright (c) 2014 Apide ApS; all rights reserved
|
|
3
|
+
|
|
4
|
+
require 'spec_helper'
|
|
5
|
+
|
|
6
|
+
require 'action_view'
|
|
7
|
+
require 'language_select'
|
|
8
|
+
|
|
9
|
+
module ActionView
|
|
10
|
+
|
|
11
|
+
module Helpers
|
|
12
|
+
|
|
13
|
+
describe LanguageSelect do
|
|
14
|
+
include TagHelper
|
|
15
|
+
|
|
16
|
+
class Walrus
|
|
17
|
+
attr_accessor :language
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
let(:walrus) { Walrus.new }
|
|
21
|
+
|
|
22
|
+
let!(:template) { ActionView::Base.new }
|
|
23
|
+
|
|
24
|
+
let(:select_tag) do
|
|
25
|
+
'<select id="walrus_language" name="walrus[language]">'
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
let(:selected_en_option) do
|
|
29
|
+
if defined?(Tags::Base)
|
|
30
|
+
content_tag(:option, 'English', :selected => :selected, :value => 'en')
|
|
31
|
+
else
|
|
32
|
+
'<option value="en" selected="selected">English</option>'
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
let(:builder) do
|
|
37
|
+
if defined?(Tags::Base)
|
|
38
|
+
FormBuilder.new(:walrus, walrus, template, {})
|
|
39
|
+
else
|
|
40
|
+
FormBuilder.new(:walrus, walrus, template, {}, Proc.new { })
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe "#language_select" do
|
|
45
|
+
let(:tag) { builder.language_select(:language) }
|
|
46
|
+
it "creates a select tag" do
|
|
47
|
+
tag.should include(select_tag)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "creates option for each language" do
|
|
51
|
+
::LanguageSelect::LANGUAGES.each do |code, name|
|
|
52
|
+
tag.should include(content_tag(:option, name, :value => code))
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "selects the value of language" do
|
|
57
|
+
walrus.language = 'en'
|
|
58
|
+
t = builder.language_select(:language)
|
|
59
|
+
t.should include(selected_en_option)
|
|
60
|
+
end
|
|
61
|
+
end # language_select
|
|
62
|
+
|
|
63
|
+
describe "#priority_languages" do
|
|
64
|
+
let(:tag) { builder.language_select(:language, ['en']) }
|
|
65
|
+
|
|
66
|
+
it "puts the priority languages at the top" do
|
|
67
|
+
tag.should include("#{select_tag}<option value=\"en")
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "inserts a divider" do
|
|
71
|
+
tag.should include('>English</option><option value="" disabled="disabled">-------------</option>')
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "does not mark two languages as selected" do
|
|
75
|
+
walrus.language = "en"
|
|
76
|
+
str = <<-EOS.strip
|
|
77
|
+
</option>\n<option value="en" selected="selected">English</option>
|
|
78
|
+
EOS
|
|
79
|
+
tag.should_not include(str)
|
|
80
|
+
end
|
|
81
|
+
end #proprity_languages
|
|
82
|
+
|
|
83
|
+
end #LanguageSelect
|
|
84
|
+
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
|
4
|
+
# loaded once.
|
|
5
|
+
#
|
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
|
7
|
+
|
|
8
|
+
require 'pry'
|
|
9
|
+
|
|
10
|
+
RSpec.configure do |config|
|
|
11
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
|
12
|
+
config.run_all_when_everything_filtered = true
|
|
13
|
+
config.filter_run :focus
|
|
14
|
+
|
|
15
|
+
# Run specs in random order to surface order dependencies. If you find an
|
|
16
|
+
# order dependency and want to debug it, you can fix the order by providing
|
|
17
|
+
# the seed, which is printed after each run.
|
|
18
|
+
# --seed 1234
|
|
19
|
+
config.order = 'random'
|
|
20
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: language_select
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Jacob Eiler
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2014-01-02 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: rspec
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
type: :development
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ! '>='
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '0'
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: actionpack
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ! '>='
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
type: :development
|
|
39
|
+
prerelease: false
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ! '>='
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '0'
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: appraisal
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
none: false
|
|
50
|
+
requirements:
|
|
51
|
+
- - ! '>='
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
type: :development
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
none: false
|
|
58
|
+
requirements:
|
|
59
|
+
- - ! '>='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
- !ruby/object:Gem::Dependency
|
|
63
|
+
name: pry
|
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
|
65
|
+
none: false
|
|
66
|
+
requirements:
|
|
67
|
+
- - ! '>='
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '0'
|
|
70
|
+
type: :development
|
|
71
|
+
prerelease: false
|
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
73
|
+
none: false
|
|
74
|
+
requirements:
|
|
75
|
+
- - ! '>='
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '0'
|
|
78
|
+
description: Provides a simple helper to get an HTML select list of ISO-639-1 languages. The
|
|
79
|
+
list of languages is obtained from Wikipedia (http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes).
|
|
80
|
+
email:
|
|
81
|
+
- jacob.eiler@apide.com
|
|
82
|
+
executables: []
|
|
83
|
+
extensions: []
|
|
84
|
+
extra_rdoc_files: []
|
|
85
|
+
files:
|
|
86
|
+
- Appraisals
|
|
87
|
+
- CHANGELOG.md
|
|
88
|
+
- Gemfile
|
|
89
|
+
- Gemfile.lock
|
|
90
|
+
- MIT-LICENSE
|
|
91
|
+
- README.md
|
|
92
|
+
- Rakefile
|
|
93
|
+
- gemfiles/actionpack3.0.gemfile
|
|
94
|
+
- gemfiles/actionpack3.0.gemfile.lock
|
|
95
|
+
- gemfiles/actionpack3.1.gemfile
|
|
96
|
+
- gemfiles/actionpack3.1.gemfile.lock
|
|
97
|
+
- gemfiles/actionpack3.2.gemfile
|
|
98
|
+
- gemfiles/actionpack3.2.gemfile.lock
|
|
99
|
+
- gemfiles/actionpack4.0.gemfile
|
|
100
|
+
- gemfiles/actionpack4.0.gemfile.lock
|
|
101
|
+
- language_select.gemspec
|
|
102
|
+
- lib/language_select.rb
|
|
103
|
+
- lib/language_select/languages.rb
|
|
104
|
+
- lib/language_select/version.rb
|
|
105
|
+
- spec/language_select_spec.rb
|
|
106
|
+
- spec/spec_helper.rb
|
|
107
|
+
homepage: https://github.com/apide/language_select
|
|
108
|
+
licenses: []
|
|
109
|
+
post_install_message:
|
|
110
|
+
rdoc_options: []
|
|
111
|
+
require_paths:
|
|
112
|
+
- lib
|
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
114
|
+
none: false
|
|
115
|
+
requirements:
|
|
116
|
+
- - ! '>='
|
|
117
|
+
- !ruby/object:Gem::Version
|
|
118
|
+
version: '0'
|
|
119
|
+
segments:
|
|
120
|
+
- 0
|
|
121
|
+
hash: -4540007196477433491
|
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
|
+
none: false
|
|
124
|
+
requirements:
|
|
125
|
+
- - ! '>='
|
|
126
|
+
- !ruby/object:Gem::Version
|
|
127
|
+
version: '0'
|
|
128
|
+
segments:
|
|
129
|
+
- 0
|
|
130
|
+
hash: -4540007196477433491
|
|
131
|
+
requirements: []
|
|
132
|
+
rubyforge_project: language_select
|
|
133
|
+
rubygems_version: 1.8.25
|
|
134
|
+
signing_key:
|
|
135
|
+
specification_version: 3
|
|
136
|
+
summary: Language Select Plugin
|
|
137
|
+
test_files: []
|