evil-blocks-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog ADDED
@@ -0,0 +1,2 @@
1
+ == 0.1 (The Gadget, 16th July 1945)
2
+ * Initial release.
data/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README.md ADDED
@@ -0,0 +1,135 @@
1
+ # Evil Blocks
2
+
3
+ Evil Block is a tiny framework for web pages. It splits your application
4
+ to separated blocks with isolated styles and scripts.
5
+
6
+ Sponsored by [Evil Martians](http://evilmartians.com/).
7
+ Role aliases taken from [role](https://github.com/kossnocorp/role)
8
+ and [role-rails](https://github.com/kossnocorp/role-rails) by Sasha Koss.
9
+
10
+ ## Quick Example
11
+
12
+ ### Slim Template
13
+
14
+ ```haml
15
+ .user-page
16
+ .title User Name
17
+ .gallery-control.is-big
18
+ // Evil Blocks add @data-role alias to Slim
19
+ // .class to bind styles, @data-role to bind JavaScript
20
+ a.gallery-left@next-photo href="#"
21
+ a.gallery-right@prev-photo href="#"
22
+ img src="photos/1.jpg"
23
+ img src="photos/2.jpg"
24
+ img src="photos/3.jpg"
25
+ ```
26
+
27
+ ### Sass Styles
28
+
29
+ ```sass
30
+ // Block
31
+ .user-page
32
+ // All elements must be inside blocks (like in namespaces)
33
+ .title
34
+ font-size: 20px
35
+
36
+ // Block
37
+ .gallery-control
38
+ position: relative
39
+ img, .gallery-left, .gallery-right
40
+ position: absolute
41
+ // Modificator
42
+ &.is-big
43
+ width: 600px
44
+ ```
45
+
46
+ ### CoffeeScript
47
+
48
+ ```coffee
49
+ # Will execute callback only if .gallery-control is in current page
50
+ evil.block '.gallery-control', ($, b, block) ->
51
+ current = 0
52
+ showPhoto = (num) ->
53
+ # b-function finds only inside .gallery-control
54
+ b('img').hide()
55
+ b("img:eql(#{ num })").show()
56
+
57
+ initState: ->
58
+ showPhoto(current)
59
+
60
+ buttons: ->
61
+ # Shortcuts for data-role="next-photo"
62
+ b.nextPhoto.click ->
63
+ showPhoto(current += 1)
64
+
65
+ slideShow: ->
66
+ # You can communicate between blocks by simple events
67
+ block.on 'slideshow-start', ->
68
+ setTimeout( -> b.nextPhoto.click() , 5000)
69
+
70
+ # Will execute callback only on user page, where .user-page exists
71
+ evil.block '.user-page', ($, b, block) ->
72
+
73
+ startSlidehow: ->
74
+ b('.gallery-control').trigger('slideshow-start')
75
+ ```
76
+
77
+ ## Styles
78
+
79
+ * You split all you tags to “blocks” and “elements”. Elements must belong
80
+ to block. Blocks can be nested.
81
+ * Blocks classes must have special suffix, that can’t be accidentally used
82
+ in elements. For example. `-page`, `-layout`, `-control` suffixes
83
+ (for example, `.user-page`, `.header-layout`, `.gallery-control`).
84
+ * All styles must have block class in condition. For example,
85
+ `.user-page .title`, `.user-page .edit`. So all you styles is protected
86
+ from accidentally same classes (it’s important, if you join all your CSS files
87
+ in one file).
88
+ * If block can be nested in another blocks (like common controls), adds prefix
89
+ to all its elements (like `.gallery-left`). If block is a root block
90
+ (like `.user-page` or `.header-layout`) be free to use short classes.
91
+ * Classes to modificate elements or blocks, must be like sentence without a noun
92
+ (for example, `.is-big`, `.with-header`).
93
+
94
+ ## JavaScript
95
+
96
+ * Unobtrusive JavaScript.
97
+ * Write animation and states in CSS. JavaScript just changes CSS classes.
98
+ * Avoid rendering. Send from server HTML, not JSON.
99
+ * Wrap scrips to revive blocks in `evil.block(selector, callback)`.
100
+ It will execute `callback` only if block `selector` exists in current page.
101
+ So you can be free to join all JS files in one.
102
+ * `evil.block` will send to `callback` three arguments: `$` is jQuery,
103
+ `b` is “b-function”, `block` is a finded blocks by `selector`.
104
+ * B-function is like jQuery function, but find only inside finded block
105
+ (alias `b('a') = $('a', selector)`).
106
+ * Bind JavaScript to `data-role` attribute to be free to change styles
107
+ and classes without dangeros of breaking scripts.
108
+ * You can easy find special`data-role` by b-function. It will has properties
109
+ for all roles inside block (`@role-name` will be camelized to `b.roleName`).
110
+ * If `callback` return object, `evil-block` will execute all it methods.
111
+ It’s useful to split your script to several initializer with separated
112
+ variables scope.
113
+
114
+ ## Install
115
+
116
+ ### Ruby on Rails
117
+
118
+ Add `evil-block-rails` gem to `Gemfile`:
119
+ ```ruby
120
+ gem "evil-blocks-rails"
121
+ ```
122
+
123
+ Load `evil-blocks.js` in your script:
124
+ ```js
125
+ //= require evil-blocks
126
+ ```
127
+
128
+ ### Others
129
+
130
+ Add file `lib/evil-blocks.js` to your project.
131
+
132
+ ## See Also
133
+
134
+ * [Evil Front](https://github.com/ai/evil-front) – pack of helpers and libraries
135
+ for Ruby on Rails and Evil Blocks.
@@ -0,0 +1,118 @@
1
+ /*
2
+ * Copyright 2013 Andrey “A.I.” Sitnik <andrey@sitnik.ru>,
3
+ * sponsored by Evil Martians.
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU Lesser General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public License
16
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+ ;(function ($) {
20
+ "use strict";
21
+
22
+ /*
23
+ * Add `@data-role` alias to jQuery.
24
+ *
25
+ * Copy from jquery.role by Sasha Koss https://github.com/kossnocorp/role
26
+ */
27
+
28
+ var rewriteSelector = function (context, name, pos) {
29
+ var original = context[name];
30
+ if ( !original ) {
31
+ return;
32
+ }
33
+
34
+ context[name] = function () {
35
+ arguments[pos] = arguments[pos].replace(
36
+ /@([\w\u00c0-\uFFFF\-]+)/g, '[data-role~="$1"]');
37
+ return original.apply(context, arguments);
38
+ };
39
+
40
+ $.extend(context[name], original);
41
+ };
42
+
43
+ rewriteSelector($, 'find', 0);
44
+ rewriteSelector($, 'multiFilter', 0);
45
+ rewriteSelector($.find, 'matchesSelector', 1);
46
+ rewriteSelector($.find, 'matches', 0);
47
+
48
+ /*
49
+ * Evil namespace. Also can be used in Evil Front.
50
+ */
51
+ if ( !window.evil ) {
52
+ window.evil = { };
53
+ }
54
+
55
+ /**
56
+ * Call `callback` only if `selector` was founded on page.
57
+ * `callback` will receive 3 arguments:
58
+ * * `$` - jQuery.
59
+ * * `b` - like jQuery, but find only inside founded blocks.
60
+ * * `block` - blocks, founded by `selector`.
61
+ *
62
+ * All elements with `data-role` will be add as property to `b`.
63
+ *
64
+ * `callback` can return hash of inititalizer functions,
65
+ * `evil.block` will execute them. It is good way to isolate variables
66
+ * in separated initializers.
67
+ *
68
+ * evil.block '.user-page', ($, b, block) ->
69
+ *
70
+ * editUser: ->
71
+ * # Click on `data-role="edit"` inside `.user-page`
72
+ * b.edit.click ->
73
+ * b('.edit-form').show()
74
+ *
75
+ * delUser: ->
76
+ * b.del.click -> b('.delete-form').submit()
77
+ *
78
+ * initGallery: ->
79
+ * b.gallery.fotorama()
80
+ */
81
+ window.evil.block = function (selector, callback) {
82
+ $(function () {
83
+ var block = $(selector);
84
+ if ( !block.length ) {
85
+ return;
86
+ }
87
+
88
+ var b = function (subselector) {
89
+ return $(subselector, block);
90
+ };
91
+ var actives = { };
92
+ block.find('[data-role]').each(function (_, el) {
93
+ var roles = el.attributes['data-role'].value.split(' ');
94
+ for ( var i = 0; i < roles.length; i++ ) {
95
+ var role = roles[i].replace(/-\w/g, function (s) {
96
+ return s[1].toUpperCase();
97
+ });
98
+ if ( !actives[role] ) {
99
+ actives[role] = [];
100
+ }
101
+ actives[role].push(el);
102
+ }
103
+ });
104
+
105
+ for ( var role in actives ) {
106
+ b[role] = $(actives[role]);
107
+ }
108
+
109
+ var inits = callback($, b, block);
110
+ if ( typeof(inits) == 'object' ) {
111
+ for ( var i in inits ) {
112
+ inits[i]($, b, block);
113
+ }
114
+ }
115
+ });
116
+ };
117
+
118
+ })(jQuery);
@@ -0,0 +1,33 @@
1
+ =begin
2
+ Copyright 2013 Andrey “A.I.” Sitnik <andrey@sitnik.ru>,
3
+ sponsored by Evil Martians.
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ =end
18
+
19
+ module EvilBlocks
20
+ # Tell Ruby on Rails to add `evil-block.js` to Rails Admin load paths.
21
+ class Engine < ::Rails::Engine
22
+ initializer 'evil-front.slim' do
23
+ if defined?(Slim::Parser)
24
+ # Add @data-role alias to Slim.
25
+ #
26
+ # Copy from role-rails by Sasha Koss.
27
+ # https://github.com/kossnocorp/role-rails
28
+ Slim::Parser.default_options[:shortcut]['@'] = { :attr => 'data-role' }
29
+ Slim::Engine.default_options[:merge_attrs]['data-role'] = ' '
30
+ end
31
+ end
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: evil-blocks-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrey "A.I." Sitnik
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sprockets
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '2'
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: '2'
30
+ description: Evil Block is a tiny framework for web pages. It split your application
31
+ to separated blocks and isolate their styles and scripts.
32
+ email:
33
+ - andrey@sitnik.ru
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files:
37
+ - LICENSE
38
+ - README.md
39
+ - ChangeLog
40
+ files:
41
+ - lib/assets/javascripts/evil-blocks.js
42
+ - lib/evil-blocks-rails.rb
43
+ - LICENSE
44
+ - README.md
45
+ - ChangeLog
46
+ homepage: https://github.com/ai/evil-blocks
47
+ licenses: []
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 1.8.23
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Tiny framework for web pages to split your app to separated blocks
70
+ test_files: []