the_data_role_block_rails 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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/app/.DS_Store +0 -0
- data/app/assets/javascripts/jquery.data-role-block.js +110 -0
- data/gem_version.rb +3 -0
- data/lib/the_data_role_block_rails.rb +107 -0
- data/lib/the_data_role_block_rails/version.rb +1 -0
- data/the_data_role_block_rails.gemspec +24 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dfc92cd9165bddb5c00d11c9ddf571c9d1ae1eb0
|
4
|
+
data.tar.gz: cce5a8869427075ac4c31d916a1b23d3e15a3b1d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 17d7c8575f87d1f26fdda21838f6ea07b0ca1b10363f3c0378ad886aaca0a75cb3ce2e06adcdda499f20db8768258d628db2e0266e36101ba6cc5682d8c4ac36
|
7
|
+
data.tar.gz: a6085957555124b91b2993e02ef41b1b78f93496db3ca88e3e36f808ec3b660931216ed9cb959526bb650bd11061b44b56bf8f983cfb96f0fa4e529fe6218fb5
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Ilya N. Zykin
|
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,35 @@
|
|
1
|
+
# TheDataRoleBlockRails
|
2
|
+
|
3
|
+
Mix of `data-role`, `data-block` solutions from:
|
4
|
+
|
5
|
+
1. https://github.com/ai/evil-blocks
|
6
|
+
2. https://github.com/kossnocorp/role
|
7
|
+
|
8
|
+
Gem provide
|
9
|
+
|
10
|
+
1. marker `@` for `data-role` and marker `@@` for `data-block` for `SLIM` and `HAML`
|
11
|
+
2. JQuery plugin with selectors `$('@role-name')` and `$('@@block-name')` and methods `addRole`, `removeRole`, `addBlock`, `removeBlock`
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'the_data_role_block_rails'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
```
|
24
|
+
bundle
|
25
|
+
```
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
app/assets/javascripts/application.js
|
30
|
+
|
31
|
+
```
|
32
|
+
//= require /jquery.data-role-block
|
33
|
+
```
|
34
|
+
|
35
|
+
## MIT license
|
data/Rakefile
ADDED
data/app/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,110 @@
|
|
1
|
+
!function($){
|
2
|
+
// https://github.com/kossnocorp/role gem based on role param
|
3
|
+
// https://github.com/ai/evil-blocks/ gem based on data-role and data-block param and created for slim
|
4
|
+
// this gem based on data-role and has patch for slim and haml
|
5
|
+
var rewriteSelector = function (context, name, pos) {
|
6
|
+
var original = context[name];
|
7
|
+
if ( !original ) return;
|
8
|
+
|
9
|
+
context[name] = function () {
|
10
|
+
arguments[pos] = arguments[pos].replace(
|
11
|
+
/@@([\w\u00c0-\uFFFF\-]+)/g, '[data-block~="$1"]');
|
12
|
+
arguments[pos] = arguments[pos].replace(
|
13
|
+
/@([\w\u00c0-\uFFFF\-]+)/g, '[data-role~="$1"]');
|
14
|
+
return original.apply(context, arguments);
|
15
|
+
};
|
16
|
+
|
17
|
+
$.extend(context[name], original);
|
18
|
+
};
|
19
|
+
|
20
|
+
rewriteSelector($, 'find', 0);
|
21
|
+
rewriteSelector($, 'multiFilter', 0);
|
22
|
+
rewriteSelector($.find, 'matchesSelector', 1);
|
23
|
+
rewriteSelector($.find, 'matches', 0);
|
24
|
+
|
25
|
+
function parse(roleString, without){
|
26
|
+
var role, result = [], roles = $.trim(roleString).split(/\s+/);
|
27
|
+
|
28
|
+
for(var i=0; i<roles.length; i++) {
|
29
|
+
role = roles[i];
|
30
|
+
if (!~$.inArray(role, result) && (!without || !~$.inArray(role, without)))
|
31
|
+
result.push(role);
|
32
|
+
}
|
33
|
+
|
34
|
+
return result;
|
35
|
+
};
|
36
|
+
|
37
|
+
$.extend($.fn, {
|
38
|
+
// roles
|
39
|
+
roles: function(){ return parse(this.attr('data-role')); },
|
40
|
+
|
41
|
+
hasRole: function(roleName){
|
42
|
+
var roles = parse(roleName);
|
43
|
+
for(var i=0;i<roles.length;i++)
|
44
|
+
if (!this.is('@'+roles[i])) return false;
|
45
|
+
|
46
|
+
return true;
|
47
|
+
},
|
48
|
+
|
49
|
+
addRole: function(roleName){
|
50
|
+
if (this.hasRole(roleName)) return this;
|
51
|
+
|
52
|
+
return this.each(function(_, element){
|
53
|
+
var $el = $(element);
|
54
|
+
$el.attr('data-role', parse($el.attr('data-role') + ' ' + roleName).join(' '));
|
55
|
+
});
|
56
|
+
},
|
57
|
+
|
58
|
+
removeRole: function(roleName){
|
59
|
+
if (!this.hasRole(roleName)) return this;
|
60
|
+
|
61
|
+
return this.each(function(_, element){
|
62
|
+
var $el = $(element);
|
63
|
+
$el.attr('data-role', parse($el.attr('data-role'), parse(roleName)).join(' '));
|
64
|
+
});
|
65
|
+
},
|
66
|
+
|
67
|
+
toggleRole: function(roleName){
|
68
|
+
var roles = parse(roleName);
|
69
|
+
for(var i=0;i<roles.length;i++)
|
70
|
+
this[this.hasRole(roles[i]) ? 'removeRole' : 'addRole'].call(this, roles[i]);
|
71
|
+
return this;
|
72
|
+
},
|
73
|
+
|
74
|
+
// Blocks
|
75
|
+
blocks: function(){ return parse(this.attr('data-block')); },
|
76
|
+
|
77
|
+
hasBlock: function(blockName){
|
78
|
+
var blocks = parse(blockName);
|
79
|
+
for(var i=0;i<blocks.length;i++)
|
80
|
+
if (!this.is('@@'+blocks[i])) return false;
|
81
|
+
|
82
|
+
return true;
|
83
|
+
},
|
84
|
+
|
85
|
+
addBlock: function(blockName){
|
86
|
+
if (this.hasBlock(blockName)) return this;
|
87
|
+
|
88
|
+
return this.each(function(_, element){
|
89
|
+
var $el = $(element);
|
90
|
+
$el.attr('data-block', parse($el.attr('data-block') + ' ' + blockName).join(' '));
|
91
|
+
});
|
92
|
+
},
|
93
|
+
|
94
|
+
removeBlock: function(blockName){
|
95
|
+
if (!this.hasBlock(blockName)) return this;
|
96
|
+
|
97
|
+
return this.each(function(_, element){
|
98
|
+
var $el = $(element);
|
99
|
+
$el.attr('data-block', parse($el.attr('data-block'), parse(blockName)).join(' '));
|
100
|
+
});
|
101
|
+
},
|
102
|
+
|
103
|
+
toggleBlock: function(blockName){
|
104
|
+
var blocks = parse(blockName);
|
105
|
+
for(var i=0;i<blocks.length;i++)
|
106
|
+
this[this.hasBlock(blocks[i]) ? 'removeBlock' : 'addBlock'].call(this, blocks[i]);
|
107
|
+
return this;
|
108
|
+
}
|
109
|
+
});
|
110
|
+
}(jQuery)
|
data/gem_version.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
require "the_data_role_block_rails/version"
|
2
|
+
|
3
|
+
module TheDataRoleBlockRails
|
4
|
+
class Engine < ::Rails::Engine
|
5
|
+
initializer 'data-role-block-slim.register' do
|
6
|
+
if defined?(Slim::Parser)
|
7
|
+
shortcut = Slim::Parser.default_options[:shortcut]
|
8
|
+
|
9
|
+
shortcut['@'] = { attr: 'data-role' }
|
10
|
+
shortcut['@@'] = { attr: 'data-block' }
|
11
|
+
|
12
|
+
Slim::Engine.default_options[:merge_attrs]['data-role'] = ' '
|
13
|
+
Slim::Engine.default_options[:merge_attrs]['data-block'] = ' '
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
initializer 'data-role-block-haml.register' do |app|
|
18
|
+
if defined?(Haml::Parser)
|
19
|
+
class Haml::Parser
|
20
|
+
DIV_ROLE = '@'
|
21
|
+
DIV_BLOCK = '@@'
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
original_process_line_method = instance_method :process_line
|
26
|
+
define_method :process_line do |text, index|
|
27
|
+
if (text.slice(0,2) === DIV_BLOCK) || (text[0] === DIV_ROLE)
|
28
|
+
push div(text)
|
29
|
+
else
|
30
|
+
original_process_line_method.bind(self).call(text, index)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.parse_class_and_id(list)
|
35
|
+
attributes = {}
|
36
|
+
list.scan(/(#|\.|@|@@)([-:_a-zA-Z0-9]+)/) do |type, property|
|
37
|
+
case type
|
38
|
+
when '.'
|
39
|
+
if attributes['class']
|
40
|
+
attributes['class'] += " "
|
41
|
+
else
|
42
|
+
attributes['class'] = ""
|
43
|
+
end
|
44
|
+
attributes['class'] += property
|
45
|
+
when '#'; attributes['id'] = property
|
46
|
+
when '@'
|
47
|
+
if attributes['data-role']
|
48
|
+
attributes['data-role'] += " "
|
49
|
+
else
|
50
|
+
attributes['data-role'] = ""
|
51
|
+
end
|
52
|
+
attributes['data-role'] += property
|
53
|
+
when '@@'
|
54
|
+
if attributes['data-block']
|
55
|
+
attributes['data-block'] += " "
|
56
|
+
else
|
57
|
+
attributes['data-block'] = ""
|
58
|
+
end
|
59
|
+
attributes['data-block'] += property
|
60
|
+
end
|
61
|
+
end
|
62
|
+
attributes
|
63
|
+
end
|
64
|
+
|
65
|
+
def parse_tag(line)
|
66
|
+
raise SyntaxError.new("Invalid tag: \"#{line}\".") unless match = line.scan(/%([-:\w]+)([-:\w\.\#\@]*)(.*)/)[0]
|
67
|
+
|
68
|
+
tag_name, attributes, rest = match
|
69
|
+
raise SyntaxError.new("Illegal element: classes and ids must have values.") if attributes =~ /[\.#](\.|#|\z)/
|
70
|
+
|
71
|
+
new_attributes_hash = old_attributes_hash = last_line = nil
|
72
|
+
object_ref = "nil"
|
73
|
+
attributes_hashes = {}
|
74
|
+
while rest
|
75
|
+
case rest[0]
|
76
|
+
when ?{
|
77
|
+
break if old_attributes_hash
|
78
|
+
old_attributes_hash, rest, last_line = parse_old_attributes(rest)
|
79
|
+
attributes_hashes[:old] = old_attributes_hash
|
80
|
+
when ?(
|
81
|
+
break if new_attributes_hash
|
82
|
+
new_attributes_hash, rest, last_line = parse_new_attributes(rest)
|
83
|
+
attributes_hashes[:new] = new_attributes_hash
|
84
|
+
when ?[
|
85
|
+
break unless object_ref == "nil"
|
86
|
+
object_ref, rest = balance(rest, ?[, ?])
|
87
|
+
else; break
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
if rest
|
92
|
+
nuke_whitespace, action, value = rest.scan(/(<>|><|[><])?([=\/\~&!])?(.*)?/)[0]
|
93
|
+
nuke_whitespace ||= ''
|
94
|
+
nuke_outer_whitespace = nuke_whitespace.include? '>'
|
95
|
+
nuke_inner_whitespace = nuke_whitespace.include? '<'
|
96
|
+
end
|
97
|
+
|
98
|
+
value = value.to_s.strip
|
99
|
+
[tag_name, attributes, attributes_hashes, object_ref, nuke_outer_whitespace,
|
100
|
+
nuke_inner_whitespace, action, value, last_line || @index]
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative '../../gem_version'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'the_data_role_block_rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "the_data_role_block_rails"
|
8
|
+
spec.version = TheDataRoleBlockRails::VERSION
|
9
|
+
spec.authors = ["Ilya N. Zykin"]
|
10
|
+
spec.email = ["zykin-ilya@ya.ru"]
|
11
|
+
spec.summary = %q{Mix of `data-role`, `data-block` solutions from AI and kossnocorp}
|
12
|
+
spec.description = %q{Mix of `data-role`, `data-block` solutions from AI and kossnocorp for JQ, SLIM, HAML}
|
13
|
+
spec.homepage = "https://github.com/the-teacher/the_data_role_block_rails"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: the_data_role_block_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ilya N. Zykin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: Mix of `data-role`, `data-block` solutions from AI and kossnocorp for
|
56
|
+
JQ, SLIM, HAML
|
57
|
+
email:
|
58
|
+
- zykin-ilya@ya.ru
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- app/.DS_Store
|
69
|
+
- app/assets/javascripts/jquery.data-role-block.js
|
70
|
+
- gem_version.rb
|
71
|
+
- lib/the_data_role_block_rails.rb
|
72
|
+
- lib/the_data_role_block_rails/version.rb
|
73
|
+
- the_data_role_block_rails.gemspec
|
74
|
+
homepage: https://github.com/the-teacher/the_data_role_block_rails
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.2.2
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Mix of `data-role`, `data-block` solutions from AI and kossnocorp
|
98
|
+
test_files: []
|