1 // Copyright 2014 Jason Woofenden -- Public Domain (CC0)
3 // This file contains helpers for using stylus in your project.
5 // Put something like this in your styl.styl:
6 // @require 'code/wfpl/stylus-helpers.styl'
9 // set units to px if it doesn't have a unit already
11 unit(i) == '' ? unit(i, px) : i
13 // transparently support vender-specific tags
15 -webkit-border-radius: arguments
16 border-radius: arguments
18 -webkit-box-shadow: arguments
21 -webkit-box-sizing: arguments
22 -moz-box-sizing: arguments
25 // map "whitespace:" to "white-space:"
27 white-space: arguments
31 position: unquote(type)
32 for i in (0...length(args))
33 if not args[i] is a 'unit'
34 {args[i]}: args[i + 1] is a 'unit' ? args[i + 1] : 0
36 // you can pass directions and units, or just directions. Examples:
37 // absolute: top 20px left 0
41 _pos('absolute', arguments)
43 _pos('fixed', arguments)
45 _pos('relative', arguments)
47 // Make children of this element inline-blocks that are spaced evenly accross.
49 // To create a minimum distance between: don't use word-spacing, it's broken in
50 // firefox. Instead, try padding on the children and negative margin on the
52 space_evenly(line_height = 1.2em)
56 relative top line_height
61 margin-bottom -(line_height)
67 // image layout: left column has normal, right column hover versions
69 // arguments: width/height are pixel dimensions of a single sprite
71 // markup: put classes n1, n2, etc on the items.
78 // <li class="n1">home</li>
79 // <li class="n2">contact</li>
84 // sprite-rollover "images/nav.png" 150 35 2
85 sprite-rollover(image, width, height, count)
86 width = unit(width, px)
87 height = unit(width, px)
90 background: transparent url(image) top left no-repeat;
94 background-position 0 y
96 background-position -(width) y
98 // Styling for a variable height element with an image background where the
99 // middle repeats vertically. You must split your image into three images, and
100 // name them with "-top", "-mid" and "-bot" suffixes (right before the file
101 // extension.) then pass a filepath as the first argument to this function
102 // which does not have a suffix.
107 // i/foo-top.png (900x20)
108 // i/foo-mid.png (900xwhatever)
109 // i/foo-bot.png (900x30)
111 // dom layout: <div id="expando"><div><div><div>...</div></div></div></div>
116 // mangin: 10px auto;
118 // background-vertical-stretch("i/foo.png", 20, 30)
122 // You can (optionally) pass 1-4 additional arguments which
123 // (effectively) add padding to the inner most div. The default is to
124 // have the height and width of the inner div match exactly the outer
125 // one. Parameters you specify are relative to that (not the section
126 // filled with the "-mid" image).
127 background-vertical-stretch(image, top-height, bottom-height, top-pad = 0, right-pad = top-pad, bottom-pad = top-pad, left-pad = right-pad)
128 top-height = _px(top-height)
129 bottom-height = _px(bottom-height)
130 top-pad = _px(top-pad)
131 right-pad = _px(right-pad)
132 bottom-pad = _px(bottom-pad)
133 left-pad = _px(left-pad)
135 path = pathjoin(dirname(image), basename(image, ext))
137 // bottom image (outermost block)
138 background transparent url(path + '-bot' + ext)
139 padding-bottom bottom-height + 1 // +1 to prevent margin collapsing
141 background transparent url(path + '-top' + ext) 0 0 no-repeat
142 padding-top top-height + 1 // +1 to prevent margin collapsing
144 background transparent url(path + '-mid' + ext) 0 0 repeat-y;
145 margin-top -1px; // correct for above +1 from top
146 margin-bottom -1px; // correct for above +1 from bottom
147 padding 1px; // to prevent margin collapsing
149 // all "2px" below are to correct for 1px above padding and below
151 margin-top 2px - top-height + top-pad
152 margin-left: left-pad - 2px
153 margin-right: right-pad - 2px
154 margin-bottom: 2px - bottom-height + bottom-pad
155 background transparent;