super_list 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/.document +5 -0
  2. data/Gemfile +15 -0
  3. data/Gemfile.lock +112 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.rdoc +40 -0
  6. data/Rakefile +53 -0
  7. data/lib/super_list.rb +77 -0
  8. data/super_list.gemspec +131 -0
  9. data/test/dummy/Rakefile +8 -0
  10. data/test/dummy/app/controllers/application_controller.rb +3 -0
  11. data/test/dummy/app/helpers/application_helper.rb +2 -0
  12. data/test/dummy/app/models/user.rb +5 -0
  13. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  14. data/test/dummy/config.ru +4 -0
  15. data/test/dummy/config/application.rb +47 -0
  16. data/test/dummy/config/boot.rb +11 -0
  17. data/test/dummy/config/database.yml +22 -0
  18. data/test/dummy/config/environment.rb +5 -0
  19. data/test/dummy/config/environments/development.rb +26 -0
  20. data/test/dummy/config/environments/production.rb +49 -0
  21. data/test/dummy/config/environments/test.rb +35 -0
  22. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  23. data/test/dummy/config/initializers/inflections.rb +10 -0
  24. data/test/dummy/config/initializers/mime_types.rb +5 -0
  25. data/test/dummy/config/initializers/secret_token.rb +7 -0
  26. data/test/dummy/config/initializers/session_store.rb +8 -0
  27. data/test/dummy/config/initializers/super_list.rb +2 -0
  28. data/test/dummy/config/locales/en.yml +5 -0
  29. data/test/dummy/config/routes.rb +58 -0
  30. data/test/dummy/db/migrate/20110227014750_create_users.rb +15 -0
  31. data/test/dummy/public/404.html +26 -0
  32. data/test/dummy/public/422.html +26 -0
  33. data/test/dummy/public/500.html +26 -0
  34. data/test/dummy/public/favicon.ico +0 -0
  35. data/test/dummy/public/javascripts/application.js +2 -0
  36. data/test/dummy/public/javascripts/controls.js +965 -0
  37. data/test/dummy/public/javascripts/dragdrop.js +974 -0
  38. data/test/dummy/public/javascripts/effects.js +1123 -0
  39. data/test/dummy/public/javascripts/prototype.js +6001 -0
  40. data/test/dummy/public/javascripts/rails.js +191 -0
  41. data/test/dummy/public/stylesheets/.gitkeep +0 -0
  42. data/test/dummy/script/rails +6 -0
  43. data/test/dummy/test/fixtures/users.yml +11 -0
  44. data/test/dummy/test/unit/user_test.rb +8 -0
  45. data/test/factories.rb +6 -0
  46. data/test/integration/navigation_test.rb +7 -0
  47. data/test/super_list_test.rb +39 -0
  48. data/test/support/integration_case.rb +5 -0
  49. data/test/test_helper.rb +24 -0
  50. metadata +243 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+
3
+ # To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
4
+ # gem 'ruby-debug'
5
+ # gem 'ruby-debug19'
6
+
7
+ group :development do
8
+ gem "bundler", "~> 1.0.0"
9
+ gem "jeweler", "~> 1.5.2"
10
+ gem "rcov", ">= 0"
11
+ gem "sqlite3-ruby", :require => "sqlite3"
12
+ gem "rails", "3.0.4"
13
+ gem "capybara", ">= 0.4.0"
14
+ gem "factory_girl"
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,112 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionmailer (3.0.4)
6
+ actionpack (= 3.0.4)
7
+ mail (~> 2.2.15)
8
+ actionpack (3.0.4)
9
+ activemodel (= 3.0.4)
10
+ activesupport (= 3.0.4)
11
+ builder (~> 2.1.2)
12
+ erubis (~> 2.6.6)
13
+ i18n (~> 0.4)
14
+ rack (~> 1.2.1)
15
+ rack-mount (~> 0.6.13)
16
+ rack-test (~> 0.5.7)
17
+ tzinfo (~> 0.3.23)
18
+ activemodel (3.0.4)
19
+ activesupport (= 3.0.4)
20
+ builder (~> 2.1.2)
21
+ i18n (~> 0.4)
22
+ activerecord (3.0.4)
23
+ activemodel (= 3.0.4)
24
+ activesupport (= 3.0.4)
25
+ arel (~> 2.0.2)
26
+ tzinfo (~> 0.3.23)
27
+ activeresource (3.0.4)
28
+ activemodel (= 3.0.4)
29
+ activesupport (= 3.0.4)
30
+ activesupport (3.0.4)
31
+ arel (2.0.8)
32
+ builder (2.1.2)
33
+ capybara (0.4.1.1)
34
+ celerity (>= 0.7.9)
35
+ culerity (>= 0.2.4)
36
+ mime-types (>= 1.16)
37
+ nokogiri (>= 1.3.3)
38
+ rack (>= 1.0.0)
39
+ rack-test (>= 0.5.4)
40
+ selenium-webdriver (>= 0.0.27)
41
+ xpath (~> 0.1.3)
42
+ celerity (0.8.7)
43
+ childprocess (0.1.6)
44
+ ffi (~> 0.6.3)
45
+ culerity (0.2.15)
46
+ erubis (2.6.6)
47
+ abstract (>= 1.0.0)
48
+ factory_girl (1.3.3)
49
+ ffi (0.6.3)
50
+ rake (>= 0.8.7)
51
+ git (1.2.5)
52
+ i18n (0.5.0)
53
+ jeweler (1.5.2)
54
+ bundler (~> 1.0.0)
55
+ git (>= 1.2.5)
56
+ rake
57
+ json_pure (1.5.1)
58
+ mail (2.2.15)
59
+ activesupport (>= 2.3.6)
60
+ i18n (>= 0.4.0)
61
+ mime-types (~> 1.16)
62
+ treetop (~> 1.4.8)
63
+ mime-types (1.16)
64
+ nokogiri (1.4.4)
65
+ polyglot (0.3.1)
66
+ rack (1.2.1)
67
+ rack-mount (0.6.13)
68
+ rack (>= 1.0.0)
69
+ rack-test (0.5.7)
70
+ rack (>= 1.0)
71
+ rails (3.0.4)
72
+ actionmailer (= 3.0.4)
73
+ actionpack (= 3.0.4)
74
+ activerecord (= 3.0.4)
75
+ activeresource (= 3.0.4)
76
+ activesupport (= 3.0.4)
77
+ bundler (~> 1.0)
78
+ railties (= 3.0.4)
79
+ railties (3.0.4)
80
+ actionpack (= 3.0.4)
81
+ activesupport (= 3.0.4)
82
+ rake (>= 0.8.7)
83
+ thor (~> 0.14.4)
84
+ rake (0.8.7)
85
+ rcov (0.9.9)
86
+ rubyzip (0.9.4)
87
+ selenium-webdriver (0.1.2)
88
+ childprocess (~> 0.1.5)
89
+ ffi (~> 0.6.3)
90
+ json_pure
91
+ rubyzip
92
+ sqlite3 (1.3.3)
93
+ sqlite3-ruby (1.3.3)
94
+ sqlite3 (>= 1.3.3)
95
+ thor (0.14.6)
96
+ treetop (1.4.9)
97
+ polyglot (>= 0.3.1)
98
+ tzinfo (0.3.24)
99
+ xpath (0.1.3)
100
+ nokogiri (~> 1.3)
101
+
102
+ PLATFORMS
103
+ ruby
104
+
105
+ DEPENDENCIES
106
+ bundler (~> 1.0.0)
107
+ capybara (>= 0.4.0)
108
+ factory_girl
109
+ jeweler (~> 1.5.2)
110
+ rails (= 3.0.4)
111
+ rcov
112
+ sqlite3-ruby
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Jinzhu
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.rdoc ADDED
@@ -0,0 +1,40 @@
1
+ = Super List - https://github.com/jinzhu/super_list
2
+
3
+ ## in config/initializers/super_list.rb
4
+ SuperList.new("Gender", {"M" => "Man", "F" => "Female"}, :allow_blank => true, :use_i18n => false)
5
+
6
+ ## in app/models/user.rb
7
+ class User < ActiveRecord::Base
8
+ super_list :gender, 'Gender'
9
+ super_list :gender2, 'Gender', :use_i18n => true
10
+ end
11
+
12
+ User.new(:gender => 'NF').valid? => false
13
+ User.new(:gender => 'M').valid? => true
14
+ User.new(:gender => 'F').gender => 'Female'
15
+ User.new(:gender => 'F').original_gender => 'F'
16
+
17
+ user = User.new(:gender => 'F', :gender2 => 'M')
18
+ user.gender2 => "translation missing: en.Gender.M"
19
+ user.gender2(:locale => "api") => "translation missing: api.Gender.M"
20
+
21
+ SuperList["Gender"].options => {:use_i18n=>false, :i18n_scope=>"Gender", :allow_blank=>true}
22
+ SuperList["Gender"].keys => ["M", "F"]
23
+ SuperList["Gender"].values(:use_i18n => true, :locale => 'zh')
24
+ => ["translation missing: zh.Gender1.M", "translation missing: zh.Gender1.F"]
25
+
26
+
27
+ == Contributing to super_list
28
+
29
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
30
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
31
+ * Fork the project
32
+ * Start a feature/bugfix branch
33
+ * Commit and push until you are happy with your contribution
34
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
35
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
36
+
37
+ == Copyright
38
+
39
+ Copyright (c) 2011 Jinzhu. See LICENSE.txt for
40
+ further details.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "super_list"
16
+ gem.homepage = "http://github.com/jinzhu/super_list"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{super list}
19
+ gem.description = %Q{super list}
20
+ gem.email = "wosmvp@gmail.com"
21
+ gem.authors = ["Jinzhu"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/*_test.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "super_list #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/lib/super_list.rb ADDED
@@ -0,0 +1,77 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+
4
+ class SuperList
5
+ @@options = { :use_i18n => false}
6
+ @@data = ActiveSupport::OrderedHash.new
7
+
8
+ def self.default_option=(options)
9
+ @@options.update(options)
10
+ end
11
+
12
+ def initialize(name, values, options={})
13
+ # { :use_i18n => false, :i18n_scope => 'super_list'}
14
+ options = @@options.merge(:i18n_scope => name).merge(options)
15
+ @@data[name] = Data.new(values, options)
16
+ end
17
+
18
+ def self.[](name)
19
+ @@data[name]
20
+ end
21
+
22
+ ## Data Store
23
+ class Data
24
+ def initialize(values, options)
25
+ @values, @options = values, options
26
+ end
27
+
28
+ def keys
29
+ @values.keys
30
+ end
31
+
32
+ def values(options={})
33
+ keys.map {|x| get_value(x, options) }
34
+ end
35
+
36
+ def get_value(key,options={})
37
+ options = @options.merge(options)
38
+ if options[:use_i18n]
39
+ I18n.t(key, :scope => options[:i18n_scope], :default => options[:i18n_default], :locale => options[:locale])
40
+ else
41
+ @values[key]
42
+ end
43
+ end
44
+
45
+ def options
46
+ @options
47
+ end
48
+ end
49
+ end
50
+
51
+
52
+ module SuperListActiveRecord
53
+ extend ActiveSupport::Concern
54
+
55
+ module ClassMethods
56
+ def super_list(column, data, options={})
57
+ original_column = "original_#{column}".to_sym
58
+ data = SuperList[data]
59
+ options = data.options.merge(options)
60
+
61
+ validates_inclusion_of original_column, { :in => data.keys }.merge(options)
62
+
63
+ define_method "#{column}" do |*opt|
64
+ opt = opt[0].is_a?(Hash) ? opt[0] : {}
65
+ opt = options.merge(opt)
66
+
67
+ data.get_value(attributes[column.to_s], opt)
68
+ end
69
+
70
+ define_method original_column do
71
+ attributes[column.to_s]
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ ActiveRecord::Base.send :include, SuperListActiveRecord
@@ -0,0 +1,131 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{super_list}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jinzhu"]
12
+ s.date = %q{2011-02-27}
13
+ s.description = %q{super list}
14
+ s.email = %q{wosmvp@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "lib/super_list.rb",
27
+ "super_list.gemspec",
28
+ "test/dummy/Rakefile",
29
+ "test/dummy/app/controllers/application_controller.rb",
30
+ "test/dummy/app/helpers/application_helper.rb",
31
+ "test/dummy/app/models/user.rb",
32
+ "test/dummy/app/views/layouts/application.html.erb",
33
+ "test/dummy/config.ru",
34
+ "test/dummy/config/application.rb",
35
+ "test/dummy/config/boot.rb",
36
+ "test/dummy/config/database.yml",
37
+ "test/dummy/config/environment.rb",
38
+ "test/dummy/config/environments/development.rb",
39
+ "test/dummy/config/environments/production.rb",
40
+ "test/dummy/config/environments/test.rb",
41
+ "test/dummy/config/initializers/backtrace_silencers.rb",
42
+ "test/dummy/config/initializers/inflections.rb",
43
+ "test/dummy/config/initializers/mime_types.rb",
44
+ "test/dummy/config/initializers/secret_token.rb",
45
+ "test/dummy/config/initializers/session_store.rb",
46
+ "test/dummy/config/initializers/super_list.rb",
47
+ "test/dummy/config/locales/en.yml",
48
+ "test/dummy/config/routes.rb",
49
+ "test/dummy/db/migrate/20110227014750_create_users.rb",
50
+ "test/dummy/public/404.html",
51
+ "test/dummy/public/422.html",
52
+ "test/dummy/public/500.html",
53
+ "test/dummy/public/favicon.ico",
54
+ "test/dummy/public/javascripts/application.js",
55
+ "test/dummy/public/javascripts/controls.js",
56
+ "test/dummy/public/javascripts/dragdrop.js",
57
+ "test/dummy/public/javascripts/effects.js",
58
+ "test/dummy/public/javascripts/prototype.js",
59
+ "test/dummy/public/javascripts/rails.js",
60
+ "test/dummy/public/stylesheets/.gitkeep",
61
+ "test/dummy/script/rails",
62
+ "test/dummy/test/fixtures/users.yml",
63
+ "test/dummy/test/unit/user_test.rb",
64
+ "test/factories.rb",
65
+ "test/integration/navigation_test.rb",
66
+ "test/super_list_test.rb",
67
+ "test/support/integration_case.rb",
68
+ "test/test_helper.rb"
69
+ ]
70
+ s.homepage = %q{http://github.com/jinzhu/super_list}
71
+ s.licenses = ["MIT"]
72
+ s.require_paths = ["lib"]
73
+ s.rubygems_version = %q{1.4.2}
74
+ s.summary = %q{super list}
75
+ s.test_files = [
76
+ "test/dummy/app/controllers/application_controller.rb",
77
+ "test/dummy/app/helpers/application_helper.rb",
78
+ "test/dummy/app/models/user.rb",
79
+ "test/dummy/config/application.rb",
80
+ "test/dummy/config/boot.rb",
81
+ "test/dummy/config/environment.rb",
82
+ "test/dummy/config/environments/development.rb",
83
+ "test/dummy/config/environments/production.rb",
84
+ "test/dummy/config/environments/test.rb",
85
+ "test/dummy/config/initializers/backtrace_silencers.rb",
86
+ "test/dummy/config/initializers/inflections.rb",
87
+ "test/dummy/config/initializers/mime_types.rb",
88
+ "test/dummy/config/initializers/secret_token.rb",
89
+ "test/dummy/config/initializers/session_store.rb",
90
+ "test/dummy/config/initializers/super_list.rb",
91
+ "test/dummy/config/routes.rb",
92
+ "test/dummy/db/migrate/20110227014750_create_users.rb",
93
+ "test/dummy/test/unit/user_test.rb",
94
+ "test/factories.rb",
95
+ "test/integration/navigation_test.rb",
96
+ "test/super_list_test.rb",
97
+ "test/support/integration_case.rb",
98
+ "test/test_helper.rb"
99
+ ]
100
+
101
+ if s.respond_to? :specification_version then
102
+ s.specification_version = 3
103
+
104
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
105
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
106
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
107
+ s.add_development_dependency(%q<rcov>, [">= 0"])
108
+ s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
109
+ s.add_development_dependency(%q<rails>, ["= 3.0.4"])
110
+ s.add_development_dependency(%q<capybara>, [">= 0.4.0"])
111
+ s.add_development_dependency(%q<factory_girl>, [">= 0"])
112
+ else
113
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
114
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
115
+ s.add_dependency(%q<rcov>, [">= 0"])
116
+ s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
117
+ s.add_dependency(%q<rails>, ["= 3.0.4"])
118
+ s.add_dependency(%q<capybara>, [">= 0.4.0"])
119
+ s.add_dependency(%q<factory_girl>, [">= 0"])
120
+ end
121
+ else
122
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
123
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
124
+ s.add_dependency(%q<rcov>, [">= 0"])
125
+ s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
126
+ s.add_dependency(%q<rails>, ["= 3.0.4"])
127
+ s.add_dependency(%q<capybara>, [">= 0.4.0"])
128
+ s.add_dependency(%q<factory_girl>, [">= 0"])
129
+ end
130
+ end
131
+