better-role-rails 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in better-role-rails.gemspec
4
+ gemspec
5
+
6
+ gem 'slim'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Andrey Ognevsky
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # BetterRoleRails
2
+
3
+ The same as [role-rails](https://github.com/kossnocorp/role-rails) gem from @kossnocorp, but with actual version of Slim.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'better-role-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install better-role-rails
18
+
19
+ ## Usage
20
+
21
+ @rolling.stone
22
+ # => <div role="rolling" class="stone"></div>
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'better-role-rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "better-role-rails"
8
+ spec.version = BetterRoleRails::VERSION
9
+ spec.authors = ["Andrey Ognevsky"]
10
+ spec.email = ["a.ognevsky@gmail.com"]
11
+ spec.description = "jQuery plugin to provide easy way to handle DOM elements by role attribute"
12
+ spec.summary = "jQuery plugin to provide easy way to handle DOM elements by role attribute"
13
+ spec.homepage = "https://github.com/ognevsky/better-role-rails"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rails", ">= 3.1.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1,2 @@
1
+ require 'better-role-rails/version'
2
+ require 'better-role-rails/engine'
@@ -0,0 +1,13 @@
1
+ module BetterRoleRails
2
+ class Engine < ::Rails::Engine
3
+ initializer "better-role-rails.register" do |app|
4
+ if defined?(Slim::Parser)
5
+ Slim::Parser.default_options[:shortcut].try(:[]=, '@', attr: 'role')
6
+ end
7
+
8
+ if defined?(Slim::Engine)
9
+ Slim::Engine.default_options[:attr_delimiter].try(:[]=, 'role', ' ')
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module BetterRoleRails
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,68 @@
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);
10
+ };
11
+
12
+ $.extend(context[name], original);
13
+ }
14
+
15
+ rewriteSelector($, 'find', 0);
16
+ rewriteSelector($, 'multiFilter', 0);
17
+ rewriteSelector($.find, 'matchesSelector', 1);
18
+ rewriteSelector($.find, 'matches', 0);
19
+
20
+ function parse(roleString, without){
21
+ var role, result = [], roles = $.trim(roleString).split(/\s+/);
22
+
23
+ for(var i=0; i<roles.length; i++) {
24
+ role = roles[i];
25
+ if (!~$.inArray(role, result) && (!without || !~$.inArray(role, without)))
26
+ result.push(role);
27
+ }
28
+
29
+ return result;
30
+ };
31
+
32
+ $.extend($.fn, {
33
+ roles: function(){ return parse(this.attr('role')); },
34
+
35
+ hasRole: function(roleName){
36
+ var roles = parse(roleName);
37
+ for(var i=0;i<roles.length;i++)
38
+ if (!this.is('@'+roles[i])) return false;
39
+
40
+ return true;
41
+ },
42
+
43
+ addRole: function(roleName){
44
+ if (this.hasRole(roleName)) return this;
45
+
46
+ return this.each(function(_, element){
47
+ var $el = $(element);
48
+ $el.attr('role', parse($el.attr('role') + ' ' + roleName).join(' '));
49
+ });
50
+ },
51
+
52
+ removeRole: function(roleName){
53
+ if (!this.hasRole(roleName)) return this;
54
+
55
+ return this.each(function(_, element){
56
+ var $el = $(element);
57
+ $el.attr('role', parse($el.attr('role'), parse(roleName)).join(' '));
58
+ });
59
+ },
60
+
61
+ toggleRole: function(roleName){
62
+ var roles = parse(roleName);
63
+ for(var i=0;i<roles.length;i++)
64
+ this[this.hasRole(roles[i]) ? 'removeRole' : 'addRole'].call(this, roles[i]);
65
+ return this;
66
+ }
67
+ });
68
+ }(jQuery)
@@ -0,0 +1 @@
1
+ !function(e){function t(t,n,r){var i=t[n];if(!i)return;t[n]=function(){return arguments[r]=arguments[r].replace(/@([\w\u00c0-\uFFFF\-]+)/g,'[role~="$1"]'),i.apply(t,arguments)},e.extend(t[n],i)}function n(t,n){var r,i=[],s=e.trim(t).split(/\s+/);for(var o=0;o<s.length;o++)r=s[o],!~e.inArray(r,i)&&(!n||!~e.inArray(r,n))&&i.push(r);return i}t(e,"find",0),t(e,"multiFilter",0),t(e.find,"matchesSelector",1),t(e.find,"matches",0),e.extend(e.fn,{roles:function(){return n(this.attr("role"))},hasRole:function(e){var t=n(e);for(var r=0;r<t.length;r++)if(!this.is("@"+t[r]))return!1;return!0},addRole:function(t){return this.hasRole(t)?this:this.each(function(r,i){var s=e(i);s.attr("role",n(s.attr("role")+" "+t).join(" "))})},removeRole:function(t){return this.hasRole(t)?this.each(function(r,i){var s=e(i);s.attr("role",n(s.attr("role"),n(t)).join(" "))}):this},toggleRole:function(e){var t=n(e);for(var r=0;r<t.length;r++)this[this.hasRole(t[r])?"removeRole":"addRole"].call(this,t[r]);return this}})}(jQuery);
@@ -0,0 +1,19 @@
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
+ }
10
+ }
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);
18
+ overridePrototype(window.Document);
19
+ }(this, ['querySelector', 'querySelectorAll', 'webkitMatchesSelector', 'mozMatchesSelector', 'oMatchesSelector', 'matchesSelector']);
@@ -0,0 +1 @@
1
+ !function(e,t){function n(e,t){var n;e&&(n=e.prototype[t])&&(e.prototype[t]=function(){return arguments[0]=arguments[0].replace(/@([\w\u00c0-\uFFFF\-]+)/g,'[role~="$1"]'),n.apply(this,arguments)})}function r(e){for(var r=0;r<t.length;r++)n(e,t[r])}r(e.Element),r(e.Document)}(this,["querySelector","querySelectorAll","webkitMatchesSelector","mozMatchesSelector","oMatchesSelector","matchesSelector"]);
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: better-role-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrey Ognevsky
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.1.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
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: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
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
+ description: jQuery plugin to provide easy way to handle DOM elements by role attribute
63
+ email:
64
+ - a.ognevsky@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - better-role-rails.gemspec
75
+ - lib/better-role-rails.rb
76
+ - lib/better-role-rails/engine.rb
77
+ - lib/better-role-rails/version.rb
78
+ - vendor/assets/javascripts/jquery.role.js
79
+ - vendor/assets/javascripts/jquery.role.min.js
80
+ - vendor/assets/javascripts/role.js
81
+ - vendor/assets/javascripts/role.min.js
82
+ homepage: https://github.com/ognevsky/better-role-rails
83
+ licenses:
84
+ - MIT
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 1.8.23
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: jQuery plugin to provide easy way to handle DOM elements by role attribute
107
+ test_files: []
108
+ has_rdoc: