prototype-css 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,12 @@
1
+ require 'compass'
2
+ require 'SassyJSON'
3
+ require 'SassyStrings'
4
+
5
+
6
+ base_directory = File.expand_path(File.join(File.dirname(__FILE__), '..'))
7
+ p_stylesheets_path = File.join(base_directory, 'sass')
8
+ p_templates_path = File.join(base_directory, 'templates')
9
+
10
+
11
+ Compass::Frameworks.register('prototype-css', :stylesheets_directory => p_stylesheets_path, :templates_directory => p_templates_path)
12
+
@@ -0,0 +1,532 @@
1
+
2
+
3
+ @import 'SassyJSON';
4
+ @import 'SassyStrings';
5
+
6
+ //a collection of abstract blocks, or block-types
7
+
8
+ $abstract-blocks: () !default;
9
+ $abstract-block-modifiers: () !default;
10
+ $abstract-block-element-separator: '__' !default;
11
+ $abstract-block-modifier-separator: '--' !default;
12
+ $static-block-separator: '-' !default;
13
+ $static-block-element-separator: '__' !default;
14
+ $static-block-modifier-separator: '--' !default;
15
+ $static-block-class: 'static' !default;
16
+ $debug-mode: false !default;
17
+ $debug-mode-class: ".debug" !default;
18
+ $block-class: ".b_" !default;
19
+
20
+
21
+ //add an abstract block to the collection
22
+
23
+ @function define-abstract-block( $block ){
24
+
25
+ $abstract-blocks: map-merge( $abstract-blocks, ( $block: () ) ) !global;
26
+
27
+ @return 0;
28
+
29
+ }
30
+
31
+
32
+ //define a property for existing abstract block
33
+ //both elements and modifiers are properties of abstract blocks
34
+ //they are differentiated by prefix either __ for elements or -- for modifiers
35
+
36
+
37
+ @function define-abstract-block-property($type, $element){
38
+
39
+ $blocks : $abstract-blocks !global;
40
+
41
+ //give an error if the abstract block is not defined
42
+
43
+ @if not map-has-key( $blocks, $type ) {
44
+
45
+ @error "Cannot add property: '#{$element}' to undefined block: '#{$type}' ";
46
+
47
+ }
48
+
49
+ //get the value of the block type (a list of elements)
50
+ $b-elem : map-get( $blocks, $type );
51
+
52
+ //append new element to the list of elements
53
+ $b-elem : append($b-elem, $element);
54
+
55
+ //merge block type list with global b-types
56
+ $abstract-blocks: map-merge($abstract-blocks, ($type : $b-elem)) !global;
57
+
58
+
59
+ @return 0;
60
+
61
+ }
62
+
63
+ //@return end most portion of the selector, with given prefix
64
+
65
+ @function get-selector-suffix( $selector, $sep ){
66
+
67
+ $parts: str-explode( $selector, $sep );
68
+
69
+ @if( length($parts) > 1 )
70
+ {
71
+ $pos: length( $parts );
72
+ $suffix: nth( $parts, $pos );
73
+ @return $suffix;
74
+ }
75
+
76
+ @return false;
77
+
78
+ }
79
+
80
+ //remove part of a string
81
+
82
+ @function str-remove( $str, $remove ){
83
+
84
+ @return str-implode( str-explode( $str, $remove ) );
85
+
86
+ }
87
+
88
+ //mixin will attempt to parse given block(s)
89
+ //and register respective type
90
+
91
+ @mixin block{
92
+
93
+ $mod-sep: $abstract-block-modifier-separator !global;
94
+ $el-sep: $abstract-block-element-separator !global;
95
+
96
+ @if ( type-of( & ) == "null" )
97
+ {
98
+
99
+ @error "abs-component must be nested under a placeholder";
100
+
101
+ }
102
+
103
+ @for $i from 1 through length( & ) {
104
+
105
+ $is-mod: false;
106
+ $is-el: false;
107
+ $selector: nth( nth( &, $i ), 1 );
108
+
109
+
110
+ //throw an error if block is not placeholder
111
+ @if( str-index( $selector, "%" ) != 1 )
112
+ {
113
+
114
+ @error "#{$selector} is not a placeholder; block mixin can only be used with placeholders";
115
+ }
116
+
117
+ //if is modifier
118
+ $modifier: get-selector-suffix( $selector, $mod-sep );
119
+
120
+ @if( $modifier )
121
+ {
122
+ $is-mod: true;
123
+ $selector: str-remove( $selector, $mod-sep+$modifier );
124
+ }
125
+
126
+ //if is element
127
+ $element: get-selector-suffix( $selector, $el-sep );
128
+
129
+ @if( $element )
130
+ {
131
+ $is-el: true;
132
+ $selector: str-remove( $selector, $el-sep+$element );
133
+ }
134
+
135
+ //remove the placeholder % prefix
136
+ $selector: str-remove( $selector, "%" );
137
+
138
+
139
+ //if it's an element modifier
140
+ @if( $is-mod and $is-el )
141
+ {
142
+ @include abs-block-modifier( $selector, $element, $modifier );
143
+ }
144
+
145
+ //if it's a block modifier
146
+ @elseif( $is-mod )
147
+ {
148
+ @include abs-block-modifier( $selector, $modifier );
149
+ }
150
+
151
+ //if it's a element
152
+ @elseif( $is-el )
153
+ {
154
+ @include abs-block-property( $selector, $element );
155
+ }
156
+
157
+ //if it's a plain old block
158
+ @else
159
+ {
160
+ @include abs-block( $selector );
161
+ }
162
+
163
+ }
164
+
165
+ }
166
+
167
+
168
+
169
+ //mixin wrapper for defining abstract block
170
+ //defines a placeholder for the block
171
+
172
+
173
+ @mixin abs-block( $block ){
174
+
175
+ //store for adding properties later
176
+
177
+ $n: define-abstract-block( $block );
178
+
179
+ %#{$block}{
180
+
181
+ @content;
182
+
183
+ }
184
+
185
+ }
186
+
187
+ //create an element for the block,
188
+ //and a placeholder
189
+
190
+ @mixin abs-block-property( $block, $element ){
191
+
192
+ $separator: $abstract-block-element-separator !global;
193
+
194
+ $el-placeholder: #{$block}#{$separator}#{$element};
195
+
196
+ //add property to the abstract block
197
+
198
+ $n: define-abstract-block-property( $block, #{$separator}#{$element} );
199
+
200
+ //create placeholder
201
+
202
+ %#{$el-placeholder}{
203
+
204
+ @content;
205
+
206
+ }
207
+
208
+ }
209
+
210
+
211
+ //define modifiers for abstract blocks and elements
212
+ //param: $block, $element, $modifier
213
+ //or
214
+ //$block, $modifier
215
+
216
+
217
+ @mixin abs-block-modifier( $args... ){
218
+
219
+
220
+ $block: nth($args, 1);
221
+ $el: '';
222
+ $property: '';
223
+ $placeholder: '';
224
+ $el-sep: $abstract-block-element-separator !global;
225
+ $mod-sep: $abstract-block-modifier-separator !global;
226
+
227
+ @if length( $args ) == 3 {
228
+
229
+ $el: nth( $args, 2 );
230
+ $mod: nth( $args, 3 );
231
+
232
+ $placeholder: #{$block}#{$el-sep}#{$el}#{$mod-sep}#{$mod};
233
+ $property: #{$el-sep}#{$el}#{$mod-sep}#{$mod};
234
+
235
+ }
236
+
237
+ @elseif length( $args ) == 2 {
238
+
239
+ $mod: nth( $args, 2 );
240
+
241
+ $placeholder: #{$block}#{$mod-sep}#{$mod};
242
+ $property: #{$mod-sep}#{$mod};
243
+
244
+ }
245
+
246
+ @else {
247
+
248
+ @error 'incorrect number of arguments for abstract block modifier';
249
+
250
+ }
251
+
252
+
253
+ $n: define-abstract-block-property( $block, $property );
254
+
255
+ //add modifier to map
256
+ $abstract-block-modifiers: map-merge( $abstract-block-modifiers, ( $placeholder : $placeholder ) );
257
+
258
+ %#{$placeholder}{
259
+
260
+ @content;
261
+
262
+ }
263
+
264
+ }
265
+
266
+
267
+ //extend an abstract block
268
+ //by inheriting all it's properties
269
+
270
+
271
+ @mixin extend-block($block, $abstract: false){
272
+
273
+
274
+ //if second argument is not set,
275
+ //extend the currect seletor
276
+
277
+ @if( $abstract == false )
278
+ {
279
+
280
+ $abstract: $block;
281
+ $block: '&';
282
+
283
+ }
284
+
285
+
286
+ //if multiple selectors call extend-block on each
287
+
288
+ @if( str-index($block, ',') ){
289
+
290
+
291
+ $blocks: str-explode($block, ",");
292
+
293
+
294
+ @each $b in $blocks{
295
+
296
+ @include extend-block( $b, $abstract );
297
+
298
+ }
299
+
300
+ }
301
+
302
+ @else {
303
+
304
+ //remove all white-space from block
305
+
306
+ $block: str-trim( $block );
307
+
308
+
309
+ //only allow classes and placeholders to extend abstract blocks
310
+
311
+ @if str-index( $block, '.' ) != 1 and $block != '&' and $block != '__static__' and $block != '__proto__'{
312
+
313
+ @error 'Could not create block: #{$block}; only classes can extend abstract blocks';
314
+
315
+ }
316
+
317
+ $abs-blocks: $abstract-blocks !global;
318
+ $child: $block;
319
+ $static-block-separator: $static-block-separator !global;
320
+ $debug: $debug-mode !global;
321
+ $d-class: $debug-mode-class !global;
322
+
323
+ //give an error if the abstract block is not defined
324
+
325
+ @if not map-has-key( $abs-blocks, $abstract ){
326
+
327
+ @error "Cannot extend undefined abstract block: '#{$abstract}' ";
328
+
329
+ }
330
+
331
+ //if the block is a prototype then treat it exactly
332
+ //like a static block
333
+
334
+ $isPrototype: ( $block == '__proto__' );
335
+
336
+ @if( $isPrototype ){
337
+
338
+ $block: '__static__';
339
+
340
+ }
341
+
342
+ //if block is static,
343
+ //use attribute selectors
344
+ //if it's also a prototype
345
+ //use the $block-class
346
+
347
+ $isStatic: ( $block == '__static__' );
348
+
349
+ @if( $isStatic ){
350
+
351
+ $blk: $static-block-separator+$abstract;
352
+
353
+
354
+ @if( $isPrototype == false ){
355
+
356
+
357
+ $child: "[class*='#{$blk} #{$static-block-class}']";
358
+
359
+ } @else{
360
+
361
+ $blk-class: $block-class !global;
362
+ $child: $blk-class;
363
+
364
+ }
365
+
366
+
367
+ }
368
+
369
+ //extend the abstract block
370
+
371
+ #{$child}{
372
+
373
+ @content;
374
+ @extend %#{$abstract};
375
+
376
+ }
377
+
378
+ //if debug is true assign special styles to block is nested under debug class
379
+ @if( $debug == true )
380
+ {
381
+
382
+ #{$d-class} #{$child}{
383
+
384
+
385
+ $d-blk: $child;
386
+
387
+ @if ( $isStatic )
388
+ {
389
+ $d-blk: $abstract;
390
+ }
391
+
392
+ @include abs-debug-styles( $abstract, $isStatic );
393
+
394
+ &::after{
395
+ content: "{ 'block' : '#{$abstract}', 'static' : #{$isStatic} }";
396
+ display: none;
397
+ }
398
+
399
+
400
+ }
401
+
402
+ }
403
+
404
+ //now inherit all it's properties
405
+
406
+ $properties: map-get( $abs-blocks, $abstract );
407
+
408
+ @if length( $properties ) > 0 {
409
+
410
+
411
+ $modifiers: $abstract-block-modifiers !global;
412
+
413
+
414
+ @each $p in $properties{
415
+
416
+
417
+ $pSelector: $child + $p;
418
+
419
+
420
+ //if the selector is a modifier no need for static suffix
421
+ $isModifier: str-index( $pSelector, $static-block-modifier-separator );
422
+
423
+
424
+
425
+ //if block is static, use attr selector instead
426
+ //but do use static suffix for modifiers or prototypes
427
+
428
+ @if( $isStatic ) {
429
+
430
+ $property: $p;
431
+
432
+ @if( $isPrototype == false ){
433
+
434
+ $property: $static-block-separator+$abstract+$property;
435
+
436
+ }
437
+
438
+ @if( type-of( $isModifier ) == "null" and $isPrototype == false ){
439
+
440
+ $property: $property+' '+$static-block-class;
441
+
442
+ }
443
+
444
+ //by default static selectors is the class with a delimiter
445
+ $pSelector: "[class*='#{$property}']";
446
+
447
+ //if it's a prototype inheritance is required, use two selectors,
448
+ //and omit the delimiter
449
+ @if( $isPrototype ){
450
+
451
+ $pSelector: "[class$='#{$property}'],[class*='#{$property} ']";
452
+
453
+ }
454
+
455
+
456
+ }
457
+
458
+ //create property selector
459
+
460
+ #{$pSelector} {
461
+
462
+ @extend %#{$abstract}#{$p};
463
+
464
+ }
465
+
466
+ }
467
+
468
+ }
469
+
470
+ }
471
+
472
+ }
473
+
474
+ //create a static block
475
+ //classes will only have to follow the naming convention to inherit
476
+ //the functionality of static blocks, rather than using extend-block directive
477
+ // [class*="block static"] {}
478
+ // [class*="block__element static"]
479
+
480
+ @mixin static-block( $abstract ){
481
+
482
+
483
+ @if( type-of( & ) == 'list' ){
484
+
485
+ @error "static-block mixin cannot be nested in selector: '#{&}'";
486
+
487
+ }
488
+
489
+ @include extend-block( "__static__", $abstract );
490
+
491
+ }
492
+
493
+ //create prototype
494
+ //the same as a static block without static keyword
495
+
496
+ @mixin prototype( $abstract: prototype ){
497
+
498
+
499
+ @if( type-of( & ) == 'list' ){
500
+
501
+ @error "static-block mixin cannot be nested in selector: '#{&}'";
502
+
503
+ }
504
+
505
+ @include extend-block( "__proto__", $abstract );
506
+
507
+ }
508
+
509
+
510
+ @mixin abs-debug(){
511
+
512
+ $blocks: $abstract-blocks !global;
513
+
514
+ @include json-encode( $blocks, regular );
515
+
516
+ }
517
+
518
+
519
+ @mixin abs-debug-styles( $block, $static ){
520
+
521
+ &:hover{
522
+
523
+ outline: 1px solid red;
524
+
525
+ }
526
+
527
+ &::after{
528
+ content: "{ 'block' : '#{$block}', 'static' : #{$static} }";
529
+ display: none;
530
+ }
531
+
532
+ }// Your Compass Extension's Sass goes here! Run wild!
@@ -0,0 +1,11 @@
1
+ description "Prototype CSS"
2
+
3
+ discover :stylesheets
4
+
5
+ help %Q{
6
+ Example help message
7
+ }
8
+
9
+ welcome_message %Q{
10
+ Welcome
11
+ }
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prototype-css
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Richard A. Lee
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2015-09-01 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: sass
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 15
29
+ segments:
30
+ - 3
31
+ - 2
32
+ - 0
33
+ version: 3.2.0
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: compass
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 45
45
+ segments:
46
+ - 0
47
+ - 12
48
+ - 1
49
+ version: 0.12.1
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: SassyJSON
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 1
63
+ - 1
64
+ - 8
65
+ version: 1.1.8
66
+ type: :runtime
67
+ version_requirements: *id003
68
+ - !ruby/object:Gem::Dependency
69
+ name: SassyStrings
70
+ prerelease: false
71
+ requirement: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 27
77
+ segments:
78
+ - 1
79
+ - 1
80
+ - 4
81
+ version: 1.1.4
82
+ type: :runtime
83
+ version_requirements: *id004
84
+ description: Test
85
+ email:
86
+ - richardleedev@gmai.com
87
+ executables: []
88
+
89
+ extensions: []
90
+
91
+ extra_rdoc_files: []
92
+
93
+ files:
94
+ - lib/prototype-css.rb
95
+ - sass/_prototype-css.scss
96
+ - templates/project/manifest.rb
97
+ homepage: https://github.com/RichardAnthonyLee/compass-prototype-css
98
+ licenses:
99
+ - MIT
100
+ post_install_message:
101
+ rdoc_options: []
102
+
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ hash: 3
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ hash: 23
120
+ segments:
121
+ - 1
122
+ - 3
123
+ - 6
124
+ version: 1.3.6
125
+ requirements: []
126
+
127
+ rubyforge_project: prototype-css
128
+ rubygems_version: 1.8.15
129
+ signing_key:
130
+ specification_version: 3
131
+ summary: Testing Extension Creation
132
+ test_files: []
133
+