-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstyle.coffee
More file actions
60 lines (43 loc) · 1.2 KB
/
Copy pathstyle.coffee
File metadata and controls
60 lines (43 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
###
STYLE HELPER
@author faeb187
@git https://github.com/faeb187
###
# EXPORTS
export Style = (->
# PRIVATE
# nothing here yet...
# PUBLIC
return {
# @desc RENDER STYLES IN DOCUMENT HEAD
# @param styles {Array} array of style definitions
# @param opt.id {String} id of <style> element
# @return void
render: ( styles, opt ) ->
opt = opt or {}
$style = $( '<style>' ).text @parse styles
# replace existing <style> when id
if opt.id
$( '#' + opt.id ).remove()
$style[ 0 ].id = opt.id
# render css
$( 'head' ).append $style[ 0 ]
# @desc PARSE STYLE ARRAY
# @param styles {Array} array of style definitions
# @return css {String} minified css string
parse: ( styles ) ->
css = open = ''
for style in styles
tag = style[ 0 ]
# NEW TAG starting
if tag isnt open
# close previous and open next
if css then css += '}'
css += tag + '{'
# remember current
open = tag
# APPEND css property
css += style[ 1 ] + ':' + style[ 2 ] + ';'
css += '}'
}
)()