enlightenment 0.0.1.pre.1 → 0.0.1.pre.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/.gemset.template +1 -0
  2. data/.gitignore +14 -0
  3. data/.rspec.template +1 -0
  4. data/.rvmrc.template +10 -0
  5. data/Gemfile +20 -0
  6. data/Gemfile.lock +171 -0
  7. data/app/assets/images/enlightenment/.gitkeep +0 -0
  8. data/enlightenment.gemspec +32 -0
  9. data/lib/enlightenment/version.rb +1 -1
  10. data/script/rails +8 -0
  11. data/spec/dummy/README.rdoc +261 -0
  12. data/spec/dummy/Rakefile +7 -0
  13. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  14. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  15. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  16. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  17. data/spec/dummy/app/mailers/.gitkeep +0 -0
  18. data/spec/dummy/app/models/.gitkeep +0 -0
  19. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  20. data/spec/dummy/config.ru +4 -0
  21. data/spec/dummy/config/application.rb +65 -0
  22. data/spec/dummy/config/boot.rb +10 -0
  23. data/spec/dummy/config/database.yml +25 -0
  24. data/spec/dummy/config/environment.rb +5 -0
  25. data/spec/dummy/config/environments/development.rb +37 -0
  26. data/spec/dummy/config/environments/production.rb +67 -0
  27. data/spec/dummy/config/environments/test.rb +37 -0
  28. data/spec/dummy/config/i18n-js.yml +25 -0
  29. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  30. data/spec/dummy/config/initializers/inflections.rb +15 -0
  31. data/spec/dummy/config/initializers/jasmine.rb +3 -0
  32. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  33. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  34. data/spec/dummy/config/initializers/session_store.rb +8 -0
  35. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  36. data/spec/dummy/config/locales/en.yml +5 -0
  37. data/spec/dummy/config/routes.rb +6 -0
  38. data/spec/dummy/lib/assets/.gitkeep +0 -0
  39. data/spec/dummy/log/.gitkeep +0 -0
  40. data/spec/dummy/public/404.html +26 -0
  41. data/spec/dummy/public/422.html +26 -0
  42. data/spec/dummy/public/500.html +25 -0
  43. data/spec/dummy/public/favicon.ico +0 -0
  44. data/spec/dummy/script/rails +6 -0
  45. data/spec/javascripts/helpers/.gitkeep +0 -0
  46. data/spec/javascripts/spec.css +3 -0
  47. data/spec/javascripts/spec.js +7 -0
  48. data/spec/javascripts/spec_helper.js +1 -0
  49. data/spec/javascripts/specs/enlightenment_spec.js +5 -0
  50. data/spec/javascripts/support/jasmine.yml +75 -0
  51. data/spec/javascripts/support/jasmine_config.rb +1 -0
  52. data/spec/spec_helper.rb +43 -0
  53. data/vendor/assets/javascripts/enlightenment.js +210 -0
  54. data/vendor/assets/javascripts/jquery.validate.js +1257 -0
  55. metadata +102 -7
File without changes
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
File without changes
@@ -0,0 +1,3 @@
1
+ /**
2
+ *= require application
3
+ */
@@ -0,0 +1,7 @@
1
+ //= require jquery
2
+ //= require jquery_ujs
3
+ //= require jasminerice_reporter
4
+ //= require enlightenment
5
+ //= require_tree .
6
+
7
+ jasmine.getFixtures().fixturePath = 'fixtures';
@@ -0,0 +1 @@
1
+ // console.info('spec_helper');
@@ -0,0 +1,5 @@
1
+ describe("$.enlightenment", function() {
2
+ it("exists", function() {
3
+ expect($.enlightenment).toBeDefined();
4
+ });
5
+ });
@@ -0,0 +1,75 @@
1
+ # src_files
2
+ #
3
+ # Return an array of filepaths relative to src_dir to include before jasmine specs.
4
+ # Default: []
5
+ #
6
+ # EXAMPLE:
7
+ #
8
+ # src_files:
9
+ # - lib/source1.js
10
+ # - lib/source2.js
11
+ # - dist/**/*.js
12
+ #
13
+ src_files:
14
+ - vendor/**/*.js
15
+
16
+ # stylesheets
17
+ #
18
+ # Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
19
+ # Default: []
20
+ #
21
+ # EXAMPLE:
22
+ #
23
+ # stylesheets:
24
+ # - css/style.css
25
+ # - stylesheets/*.css
26
+ #
27
+ stylesheets:
28
+ - spec/helpers/**/*.css
29
+
30
+ # helpers
31
+ #
32
+ # Return an array of filepaths relative to spec_dir to include before jasmine specs.
33
+ # Default: ["helpers/**/*.js"]
34
+ #
35
+ # EXAMPLE:
36
+ #
37
+ # helpers:
38
+ # - helpers/**/*.js
39
+ #
40
+ helpers:
41
+ - helpers/**/*.js
42
+
43
+ # spec_files
44
+ #
45
+ # Return an array of filepaths relative to spec_dir to include.
46
+ # Default: ["**/*[sS]pec.js"]
47
+ #
48
+ # EXAMPLE:
49
+ #
50
+ # spec_files:
51
+ # - **/*[sS]pec.js
52
+ #
53
+ spec_files:
54
+
55
+ # src_dir
56
+ #
57
+ # Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
58
+ # Default: project root
59
+ #
60
+ # EXAMPLE:
61
+ #
62
+ # src_dir: public
63
+ #
64
+ src_dir:
65
+
66
+ # spec_dir
67
+ #
68
+ # Spec directory path. Your spec_files must be returned relative to this path.
69
+ # Default: spec/javascripts
70
+ #
71
+ # EXAMPLE:
72
+ #
73
+ # spec_dir: spec/javascripts
74
+ #
75
+ spec_dir: spec
@@ -0,0 +1,43 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require File.expand_path("../dummy/config/environment", __FILE__)
4
+ require 'rspec/rails'
5
+ require 'rspec/autorun'
6
+ require 'capybara/rspec'
7
+
8
+ # Requires supporting ruby files with custom matchers and macros, etc,
9
+ # in spec/support/ and its subdirectories.
10
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
11
+
12
+ Capybara.register_driver :firefox do |app|
13
+ Capybara::Selenium::Driver.new(app, :browser => :firefox)
14
+ end
15
+
16
+ RSpec.configure do |config|
17
+ # ## Mock Framework
18
+ #
19
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
20
+ #
21
+ # config.mock_with :mocha
22
+ # config.mock_with :flexmock
23
+ # config.mock_with :rr
24
+
25
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
26
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
27
+
28
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
29
+ # examples within a transaction, remove the following line or assign false
30
+ # instead of true.
31
+ config.use_transactional_fixtures = true
32
+
33
+ # If true, the base class of anonymous controllers will be inferred
34
+ # automatically. This will be the default behavior in future versions of
35
+ # rspec-rails.
36
+ config.infer_base_class_for_anonymous_controllers = false
37
+
38
+ # Run specs in random order to surface order dependencies. If you find an
39
+ # order dependency and want to debug it, you can fix the order by providing
40
+ # the seed, which is printed after each run.
41
+ # --seed 1234
42
+ config.order = "random"
43
+ end
@@ -0,0 +1,210 @@
1
+ //= require i18n
2
+ //= require i18n/translations
3
+ //= require jquery.validate
4
+
5
+ (function($) {
6
+ $.enlightenment = {
7
+ validator : {
8
+ settings : {
9
+ debug : false,
10
+ rules : {},
11
+ focusCleanup : true,
12
+ focusInvalid : false,
13
+ onkeyup : false,
14
+ wrapper : undefined,
15
+ showErrors : undefined,
16
+ highlight : undefined,
17
+ unhighlight : undefined
18
+ },
19
+ // messages
20
+
21
+ prototype : {
22
+ addWrapper : function addWrapper(target) {
23
+ if(this.settings.wrapper) {
24
+ target = target.add(target.closest(this.settings.wrapper));
25
+ }
26
+
27
+ return target;
28
+ }
29
+ }
30
+ }
31
+ };
32
+
33
+ $.enlightenment.extend = function extend(extension) {
34
+ var validator = extension.validator || {};
35
+
36
+ $.extend(this.validator.settings, validator.settings || {});
37
+ $.extend(this.validator.prototype, validator.prototype || {});
38
+ };
39
+
40
+
41
+ // extensions to jquery
42
+ // --------------------------------------------------------------------------
43
+ $.fn.extend({
44
+ // like $.fn.clone, but with `id` and `name` corrections.
45
+ duplicate : function duplicate(placement, withDataAndEvents, deepWithDataAndEvents) {
46
+ var now = (new Date()).getTime();
47
+ var result = [];
48
+ duplicate.counter = duplicate.counter || 0;
49
+
50
+ this.each(function() {
51
+ var indicator;
52
+ var source = $(this);
53
+ var clone = source.clone(withDataAndEvents, deepWithDataAndEvents);
54
+
55
+ duplicate.counter += 1;
56
+ indicator = ["", now, duplicate.counter].join(''); // in case we're duplicating many
57
+
58
+ // id...
59
+ // from : user_friends_attributes_0_name
60
+ // to : user_friends_attributes_1234567890_name
61
+ clone.find('[id]').each(function() {
62
+ var elem = $(this);
63
+ elem.attr('id', elem.attr('id').replace(/_[0-9]+_/g, '_' + indicator + '_'));
64
+ });
65
+
66
+ // name...
67
+ // from : user_[friends_attributes][0][name]
68
+ // to : user_[friends_attributes][1234567890][name]
69
+ clone.find('[name]').each(function() {
70
+ var elem = $(this);
71
+ elem.attr('name', elem.attr('name').replace(/\[[0-9]+\]/g, '[' + indicator + ']'));
72
+ });
73
+
74
+ source[placement](clone);
75
+ result.push(clone[0]);
76
+
77
+ clone.closest('form').trigger('revalidate');
78
+ });
79
+
80
+ return $(result);
81
+ }
82
+ });
83
+
84
+ // extensions to jquery.validate
85
+ // --------------------------------------------------------------------------
86
+ $.validator.addMethod('regex', function(value, element, regexp) {
87
+ var check = false;
88
+ var re = new RegExp(regexp.replace('\\A', '^').replace('\\z', '$'));
89
+ return this.optional(element) || re.test(value);
90
+ },
91
+ 'You have entered an invalid value for this field'
92
+ );
93
+
94
+ $.validator.addMethod('remote', function(value, element, url) {
95
+ if(this.optional(element)) {
96
+ return "dependency-mismatch";
97
+ }
98
+
99
+ var validator = this;
100
+ var form = $(element).closest('form');
101
+ var name = element.name;
102
+ var previous = this.previousValue(element);
103
+
104
+ if( ! this.settings.messages[element.name]) {
105
+ this.settings.messages[element.name] = {};
106
+ }
107
+
108
+ previous.originalMessage = this.settings.messages[element.name].remote;
109
+ this.settings.messages[element.name].remote = previous.message;
110
+
111
+ if(pending[name]) {
112
+ return "pending";
113
+ }
114
+ if(previous.old === value) {
115
+ return previous.valid;
116
+ }
117
+
118
+ previous.old = value;
119
+ this.startRequest(element);
120
+
121
+ $.ajax({
122
+ url : url,
123
+ type : 'post',
124
+ dataType : 'json',
125
+ data : form.serialize(),
126
+
127
+ beforeSend : function beforeSend(xhr, settings) {
128
+ if(pending[name]) {
129
+ pending[name].abort();
130
+ }
131
+
132
+ pending[name] = xhr;
133
+ },
134
+
135
+ complete : function complete(xhr, status) {
136
+ delete pending[name];
137
+ },
138
+
139
+ success : function success(response, status, xhr) {
140
+ var submitted = validator.formSubmitted;
141
+
142
+ validator.settings.messages[element.name].remote = previous.originalMessage;
143
+ validator.prepareElement(element);
144
+ validator.formSubmitted = submitted;
145
+ validator.successList.push(element);
146
+
147
+ delete validator.invalid[element.name];
148
+ validator.showErrors();
149
+
150
+ previous.valid = true;
151
+ validator.stopRequest(element, true);
152
+ },
153
+
154
+ error : function error(xhr, status, error) {
155
+ var text = xhr.responseText;
156
+ validator.settings.messages[element.name].remote = previous.originalMessage;
157
+
158
+ if(text) {
159
+ var response = JSON.parse(text);
160
+ var errors = {};
161
+ errors[element.name] = previous.message = response.message;
162
+
163
+ validator.invalid[element.name] = true;
164
+ validator.showErrors(errors);
165
+
166
+ previous.valid = false;
167
+ validator.stopRequest(element, false);
168
+ }
169
+ }
170
+ });
171
+
172
+ return "pending";
173
+ });
174
+
175
+ $(function() {
176
+ $.extend($.validator.prototype, $.enlightenment.validator.prototype);
177
+ });
178
+
179
+ // TODO: make non-specific to bootstrap & app-custom label
180
+ // $.validator.prototype.errorsFor = function(element) {
181
+ // return $(element).closest('div.controls').find('label.error');
182
+ // };
183
+
184
+ $.validator.messages = {
185
+ // remote : message('invalid'),
186
+ required : message('invalid'),
187
+ email : message('invalid'),
188
+ url : message('invalid'),
189
+ date : message('invalid'),
190
+ dateISO : message('invalid'),
191
+ number : message('invalid'),
192
+ digits : message('invalid'),
193
+ creditcard : message('invalid'),
194
+ equalTo : message('invalid'),
195
+ maxlength : message('invalid'),
196
+ minlength : message('invalid'),
197
+ rangelength : message('invalid'),
198
+ range : message('invalid'),
199
+ max : message('invalid'),
200
+ min : message('invalid')
201
+ };
202
+
203
+ var pending = {};
204
+
205
+ function message(key) {
206
+ return function message(parameters, field) {
207
+ return I18n.t(key, { scope : 'activerecord.errors.messages' });
208
+ }
209
+ }
210
+ })(jQuery);