role-rails 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/.gitignore +6 -0
  2. data/.gitmodules +3 -0
  3. data/Gemfile +2 -11
  4. data/Rakefile +18 -35
  5. data/lib/role-rails.rb +1 -5
  6. data/lib/role-rails/engine.rb +1 -6
  7. data/lib/role-rails/version.rb +1 -1
  8. data/role-rails.gemspec +34 -56
  9. data/test/dummy/README.rdoc +261 -0
  10. data/test/dummy/Rakefile +7 -0
  11. data/test/dummy/app/assets/javascripts/application.js +13 -0
  12. data/test/dummy/app/assets/javascripts/control.jst.skim +5 -0
  13. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  14. data/test/dummy/app/controllers/application_controller.rb +6 -0
  15. data/test/dummy/app/helpers/application_helper.rb +2 -0
  16. data/test/dummy/app/mailers/.gitkeep +0 -0
  17. data/test/dummy/app/models/.gitkeep +0 -0
  18. data/test/dummy/app/views/application/index.html.slim +5 -0
  19. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  20. data/test/dummy/config.ru +4 -0
  21. data/test/dummy/config/application.rb +60 -0
  22. data/test/dummy/config/boot.rb +10 -0
  23. data/test/dummy/config/database.yml +3 -0
  24. data/test/dummy/config/environment.rb +5 -0
  25. data/test/dummy/config/environments/development.rb +37 -0
  26. data/test/dummy/config/environments/production.rb +67 -0
  27. data/test/dummy/config/environments/test.rb +37 -0
  28. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  29. data/test/dummy/config/initializers/inflections.rb +15 -0
  30. data/test/dummy/config/initializers/mime_types.rb +5 -0
  31. data/test/dummy/config/initializers/secret_token.rb +7 -0
  32. data/test/dummy/config/initializers/session_store.rb +8 -0
  33. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  34. data/test/dummy/config/locales/en.yml +5 -0
  35. data/test/dummy/config/routes.rb +3 -0
  36. data/test/dummy/lib/assets/.gitkeep +0 -0
  37. data/test/dummy/log/.gitkeep +0 -0
  38. data/test/dummy/public/404.html +26 -0
  39. data/test/dummy/public/422.html +26 -0
  40. data/test/dummy/public/500.html +25 -0
  41. data/test/dummy/public/favicon.ico +0 -0
  42. data/test/dummy/script/rails +6 -0
  43. data/test/helper.rb +20 -0
  44. data/test/integration/slim_family_engines_test.rb +23 -0
  45. data/vendor/assets/javascripts/jquery.role.js +17 -27
  46. data/vendor/assets/javascripts/jquery.role.min.js +1 -0
  47. data/vendor/assets/javascripts/role.js +17 -23
  48. data/vendor/assets/javascripts/role.min.js +1 -0
  49. data/vendor/role/.gitignore +1 -0
  50. data/vendor/role/Gemfile +9 -0
  51. data/vendor/role/Guardfile +2 -0
  52. data/vendor/role/Procfile +2 -0
  53. data/vendor/role/README.md +201 -0
  54. data/vendor/role/Rakefile +10 -0
  55. data/vendor/role/doc/yuno.png +0 -0
  56. data/vendor/role/lib/tasks/compress.rake +13 -0
  57. data/vendor/role/lib/tasks/touch.rake +3 -0
  58. data/vendor/role/spec/javascripts/fixtures/base.html +4 -0
  59. data/vendor/role/spec/javascripts/role_jquery_spec.coffee +52 -0
  60. data/vendor/role/spec/javascripts/support/jasmine.yml +15 -0
  61. data/vendor/role/spec/javascripts/support/jasmine_config.rb +23 -0
  62. data/vendor/role/spec/javascripts/support/jasmine_runner.rb +32 -0
  63. data/vendor/role/src/jquery.role.coffee +37 -0
  64. data/vendor/role/src/role.coffee +11 -0
  65. metadata +118 -18
@@ -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'
data/test/helper.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ ENV['RAILS_ENV'] = 'test'
5
+ require "dummy/config/environment"
6
+ require "rails/test_help"
7
+
8
+ begin
9
+ Bundler.setup(:default, :development)
10
+ rescue Bundler::BundlerError => e
11
+ $stderr.puts e.message
12
+ $stderr.puts "Run `bundle install` to install missing gems"
13
+ exit e.status_code
14
+ end
15
+ require 'test/unit'
16
+ require 'shoulda'
17
+
18
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
19
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
20
+ require 'role-rails'
@@ -0,0 +1,23 @@
1
+ require 'helper'
2
+
3
+ class SlimFamilyEnginesTest < ActionDispatch::IntegrationTest
4
+
5
+ context "skim engine" do
6
+ should 'setup role attribute' do
7
+ get("/assets/application.js")
8
+
9
+ assert_match /<div role=\\"implicitly_defined\\">/, response.body
10
+ assert_match /<div role=\\"explicitly_defined\\">/, response.body
11
+ end
12
+ end
13
+
14
+ context 'slim engine' do
15
+ should 'setup role attribute' do
16
+ get "/"
17
+
18
+ assert_tag :tag => 'div', :attributes => { :role => 'implicitly_defined' }
19
+ assert_tag :tag => 'div', :attributes => { :role => 'explicitly_defined' }
20
+ end
21
+ end
22
+
23
+ end
@@ -1,29 +1,19 @@
1
- // Role.js, jQuery adapter v1.1.0 ~ https://github.com/kossnocorp/role
2
-
3
- (function($) {
4
- var matchesSelectorOrigin, type;
5
- if ($ == null) $ = jQuery;
6
- $.expr.match['ROLE'] = /@((?:[\w\u00c0-\uFFFF\-]|\\.)+)/;
7
- $.expr.preFilter['ROLE'] = function(match) {
8
- return ' ' + match[1] + ' ';
9
- };
10
- $.expr.filter['ROLE'] = function(el, match) {
11
- return (el.getAttribute != null) && (" " + (el.getAttribute('role')) + " ").indexOf(match) !== -1;
12
- };
13
- for (type in $.expr.match) {
14
- $.expr.match[type] = new RegExp($.expr.match[type].source + /(?![^\[]*\])(?![^\(]*\))/.source);
15
- $.expr.leftMatch[type] = new RegExp(/(^(?:.|\r|\n)*?)/.source + $.expr.match[type].source.replace(/\\(\d+)/g, function(all, num) {
16
- return "\\" + (num - 0 + 1);
17
- }));
18
- }
19
- if (!(document.documentElement.matchesSelector != null) && (document.documentElement.mozMatchesSelector != null)) {
20
- matchesSelectorOrigin = $.find.matchesSelector;
21
- return $.find.matchesSelector = function(node, expr) {
22
- return matchesSelectorOrigin(node, expr.replace(/(@[\w\-]+)/g, function($0) {
23
- return $0.replace(/^@([\w\-]+)$/, function(__, $1) {
24
- return "[role~=\"" + $1 + "\"]";
25
- });
26
- }));
1
+ !function($){
2
+ function rewriteSelector(context, name, argPos){
3
+ var original = context[name];
4
+
5
+ if (!original) return;
6
+
7
+ context[name] = function(){
8
+ arguments[argPos] = arguments[argPos].replace(/@([\w\u00c0-\uFFFF\-]+)/g, '[role~="$1"]')
9
+ return original.apply(context, arguments);
27
10
  };
11
+
12
+ $.extend(context[name], original);
28
13
  }
29
- })($);
14
+
15
+ rewriteSelector($, 'find', 0);
16
+ rewriteSelector($, 'multiFilter', 0);
17
+ rewriteSelector($.find, 'matchesSelector', 1);
18
+ rewriteSelector($.find, 'matches', 0);
19
+ }(jQuery)
@@ -0,0 +1 @@
1
+ !function(a){function b(b,c,d){var e=b[c];if(!e)return;b[c]=function(){return arguments[d]=arguments[d].replace(/@([\w\u00c0-\uFFFF\-]+)/g,'[role~="$1"]'),e.apply(b,arguments)},a.extend(b[c],e)}b(a,"find",0),b(a,"multiFilter",0),b(a.find,"matchesSelector",1),b(a.find,"matches",0)}(jQuery);
@@ -1,24 +1,18 @@
1
- // Role.js, extension for querySelectorAll function v1.1.0 ~ https://github.com/kossnocorp/role
2
-
3
- (function() {
4
- var elements, elm, _fn, _i, _len;
5
-
6
- elements = [];
7
-
8
- if (typeof Document !== "undefined" && Document !== null) elements << Document;
9
-
10
- if (typeof Element !== "undefined" && Element !== null) elements << Element;
11
-
12
- _fn = function(elm) {
13
- var nativeQuery;
14
- nativeQuery = elm.prototype.querySelectorAll;
15
- return elm.prototype.querySelectorAll = function(selector) {
16
- return nativeQuery.call(this, selector.replace(/@(\w+)/g, "[role~=\"$1\"]"));
17
- };
18
- };
19
- for (_i = 0, _len = elements.length; _i < _len; _i++) {
20
- elm = elements[_i];
21
- _fn(elm);
1
+ !function(window, methods){
2
+ function overrideMethod(klass, methodName){
3
+ var original;
4
+ if (klass && (original = klass.prototype[methodName])) {
5
+ klass.prototype[methodName] = function(){
6
+ arguments[0] = arguments[0].replace(/@([\w\u00c0-\uFFFF\-]+)/g, '[role~="$1"]');
7
+ return original.apply(this, arguments);
8
+ };
9
+ }
22
10
  }
23
-
24
- }).call(this);
11
+
12
+ function overridePrototype(klass){
13
+ for(var i=0; i<methods.length; i++)
14
+ overrideMethod(klass, methods[i]);
15
+ }
16
+
17
+ overridePrototype(window.Element); overridePrototype(window.Document);
18
+ }(this, ['querySelector', 'querySelectorAll']);
@@ -0,0 +1 @@
1
+ !function(a,b){function c(a,b){var c;a&&(c=a.prototype[b])&&(a.prototype[b]=function(){return arguments[0]=arguments[0].replace(/@([\w\u00c0-\uFFFF\-]+)/g,'[role~="$1"]'),c.apply(this,arguments)})}function d(a){for(var d=0;d<b.length;d++)c(a,b[d])}d(a.Element),d(a.Document)}(this,["querySelector","querySelectorAll"]);
@@ -0,0 +1 @@
1
+ *.js
@@ -0,0 +1,9 @@
1
+ source :rubygems
2
+
3
+ gem 'rake'
4
+ gem 'foreman'
5
+ gem 'jasmine', '1.1.0'
6
+ gem 'guard-coffeescript'
7
+ gem 'rb-fsevent'
8
+ gem 'growl_notify'
9
+ gem 'uglifier'
@@ -0,0 +1,2 @@
1
+ guard 'coffeescript', :input => 'src', :output => 'lib'
2
+ guard 'coffeescript', :input => 'spec/javascripts', :output => 'spec/javascripts'
@@ -0,0 +1,2 @@
1
+ jasmine: rake jasmine
2
+ guard: guard
@@ -0,0 +1,201 @@
1
+ # jquery.role — jQuery plugin to provide easy way to handle DOM elements by role attribute
2
+
3
+ This project uses [Semantic Versioning](http://semver.org/) for release numbering.
4
+
5
+ Sponsored by [Evil Martians](http://evilmartians.com/).
6
+
7
+ ## Downloads
8
+
9
+ * [jquery.role.min.js](https://raw.github.com/kossnocorp/role/master/lib/jquery.role.min.js)
10
+ * [role.min.js](https://raw.github.com/kossnocorp/role/master/lib/jquery.role.min.js)
11
+ * [jquery.role.js](https://raw.github.com/kossnocorp/role/master/lib/jquery.role.js)
12
+ * [role.js](https://raw.github.com/kossnocorp/role/master/lib/role.js)
13
+ * [jquery.role.coffee](https://raw.github.com/kossnocorp/role/master/src/jquery.role.coffee)
14
+ * [role.coffee](https://raw.github.com/kossnocorp/role/master/src/role.coffee)
15
+
16
+ Also you can add jquery.role.js and role.js by bundle `role-rails` gem. For futher details see *installation* section below.
17
+
18
+ ## Use `role` attribute FTW
19
+
20
+ ```
21
+ Use cases for a role attribute for HTML5, include:
22
+
23
+ * accessibility,
24
+ * device adaptation,
25
+ * server-side processing, and
26
+ * complex data description.
27
+ ```
28
+
29
+ This is a quote from [W3C Specification on Role attribute](http://www.w3.org/wiki/PF/XTech/HTML5/RoleAttribute#A_Role_Attribute_for_HTML5).
30
+
31
+ In [Evil Martians](http://evilmartians.com/) we came up with a way to use this attribute for our own purposes.
32
+
33
+ Say you have to update your website page design. HTML markup is done and you have to apply it to the existing site. Of course this marvelous page is crammed with Javascript code tied to an existing structure.
34
+
35
+ ``` javascript
36
+ $('.list .item img')
37
+ .mouseenter(function () {
38
+ $(this).rotateTo(30, 300)
39
+ })
40
+ .mouseleave(function () {
41
+ $(this).rotateTo(0, 300)
42
+ });
43
+ ```
44
+
45
+ Obviously, you'll have to rewrite all the selectors for the new layout. And it would be nice if you had to fix only one (or even ten) of these selectors. In reality, most likely, there will be several dozen of them.
46
+
47
+ Another issue is that refactoring process requires you to change the names or a number of classes. You'll have to muddle through every JS file to find all classes you are going to change.
48
+
49
+ And, of course, in both cases the end result is absolutely unpredictable, because layout alone is not enougn to figure out if a class is actualy used in JS.
50
+
51
+ The `.js-class_name` prefix use may seem like a good idea, except that someone will surely add styles to this class in a future... Let alone the difficulty to spot, among a large of number of classes, one with a prefix.
52
+
53
+ In order to avoid this problems, we can "attach" JS to DOM elements by a `role` attribute.
54
+
55
+ It's a lot safer then prefixes, beacause it's much harder to attach styles to `role` and it feals morally difficult to break the `role` use convention.
56
+
57
+ With the use of `role`, layout update becomes very straightforward: you just have to add roles to a new element, and if you are not tied to the "magic numbers" -- it will work with no further hassle.
58
+
59
+ To make life easier (shoutout to [@alex_chrome](https://twitter.com/#!/alex_chrome) for the great idea) we also extended jQuery selector syntax:
60
+
61
+ ``` javascript
62
+ $('@list @item @image')
63
+ .mouseenter(function () {
64
+ $(this).rotateTo(30, 300)
65
+ })
66
+ .mouseleave(function () {
67
+ $(this).rotateTo(0, 300)
68
+ });
69
+ ```
70
+
71
+ `$('@list @item @image')` is the same as `$('[role="list"] [role="item] [role="image"]')` and you can use "multirole": `$('@list@coupons')`.
72
+
73
+ In addition to the jQuery plug-in, I also wrote a version that extends `querySelectorAll` of [Zepto.js](http://zeptojs.com/) with a Role functionality.
74
+
75
+ Using of 'role' in a query may work a bit slower compared to usual selectors, but it's neglectable even in a large number of queries.
76
+
77
+ In addition to `role`, I sometimes use `id`, but only in very extraodinary cases — because if there is only single element on a page today, it may happen that there will be a few tomorrow, even if that wasn't planned.
78
+
79
+ ## Usage
80
+
81
+ ### Using selectors
82
+
83
+ You can use shortcut `@` in jQuery selectors to find elements with roles.
84
+
85
+ Will select all elements in document with `role="ajax-link"`:
86
+
87
+ ``` js
88
+ $('@ajax-link')
89
+ ```
90
+
91
+ Also you can combinate roles:
92
+
93
+ `<form role="from login_form"></form>`:
94
+
95
+ ``` js
96
+ $('@form@login_form')
97
+ ```
98
+
99
+ Will select all forms with "form" as role `<form role="from login_form"></form><form role="from registration_form"></form>`:
100
+
101
+ ``` js
102
+ $('@form')
103
+ ```
104
+
105
+ You can combine role with other selectors, but that is not recommended:
106
+
107
+ `<form class="dark" role="login_form" method="post"></form>`:
108
+
109
+ ``` js
110
+ $('form.dark@login_form[method=post]')
111
+ ```
112
+
113
+ ## Installation
114
+
115
+ Coming soon.
116
+
117
+ ## Roadmap
118
+
119
+ ### 1.1.0
120
+
121
+ * Turn on configurable attribute shortcuts for Slim in role-rails (#14)
122
+
123
+ ### 1.2.0
124
+
125
+ * Add `@role_name.some_class` shortcut to Haml
126
+
127
+ ### 1.3.0
128
+
129
+ * Optional usage of `data-role` instead `role`.
130
+ * Better docs
131
+
132
+ ### 1.4.0
133
+
134
+ * Optimization
135
+ * More tests
136
+
137
+ ## Changelog
138
+
139
+ ### 1.0.2 (March 14, 2012)
140
+
141
+ * Fixes problem in Internet Explorer 8 in jquery.role.js and role.js (issue #11) (thanks @igor-alexandrov for help)
142
+
143
+ ### 1.0.1 (January 27, 2012)
144
+
145
+ * Fixes problem with multiple roles in Firefox 8 and later (issue #9)
146
+
147
+ ### 1.0.0 (December 26, 2011)
148
+
149
+ * Remove depricated function
150
+ * Rewrite in CoffeeScript
151
+
152
+ ### 0.4.1 (December 8, 2011)
153
+
154
+ * Fix issue #8
155
+
156
+ ### 0.4.0 (December 8, 2011)
157
+
158
+ * Added specs for jQuery Role
159
+ * Selectors performance improvement for modern browsers (also covers #6)
160
+ * Role extension for querySelectorAll function (`src/role.coffee`)
161
+
162
+ ### 0.3.2 (June 2, 2011)
163
+
164
+ * Reverted changes made in 0.3.1 because issue #6
165
+
166
+ ### 0.3.1 (May 24, 2011)
167
+
168
+ * Selectors performance improvement for modern browsers
169
+
170
+ ### 0.3.0 (May 23, 2011)
171
+
172
+ * Added native Sizzle selectors support (`$('@ajax_link')`)
173
+
174
+ ### 0.2.0 (May 20, 2011)
175
+
176
+ * Added mechanism to pick roles by element id
177
+
178
+ ### 0.1.0 (May 05, 2011)
179
+
180
+ * Initial release
181
+
182
+ ## Contributors
183
+
184
+ Original idea by @kossnocorp and @ai.
185
+
186
+ * @kossnocorp
187
+ * @chrome
188
+
189
+ Special thanks to @skfd and @yaroslav for helping with this README.
190
+
191
+ ## License
192
+
193
+ The MIT License
194
+
195
+ Copyright (c) 2011 Sasha Koss
196
+
197
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
198
+
199
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
200
+
201
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,10 @@
1
+ Dir['lib/tasks/*.rake'].sort.each { |r| load r }
2
+
3
+ begin
4
+ require 'jasmine'
5
+ load 'jasmine/tasks/jasmine.rake'
6
+ rescue LoadError
7
+ task :jasmine do
8
+ abort "Jasmine is not available. In order to run jasmine, you must: (sudo) gem install jasmine"
9
+ end
10
+ end
Binary file
@@ -0,0 +1,13 @@
1
+ require 'uglifier'
2
+
3
+ task :uglify do
4
+ ['jquery.role', 'role'].each do |file_name|
5
+ base_name = File.join('lib', file_name)
6
+ File.write(
7
+ base_name + '.min.js',
8
+ Uglifier.new.compile(
9
+ File.read(base_name + '.js')
10
+ )
11
+ )
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ task :touch do
2
+ puts `find . -name "*.coffee" -exec touch {} \+`
3
+ end
@@ -0,0 +1,4 @@
1
+ <div id="element_one" class="awesome_div" role="some_role"></div>
2
+ <div id="element_two" role="role_one role_two">
3
+ <div id="element_three" role="role_three"></div>
4
+ </div>