First, read about CSS Variables and why they are cool. Then come back here and finish the job...
Download the ZIP file, extract it and double-click the bundle file
to install in TextMate. It also works as expected with
E-TextEditor
- just extract the files and copy the CSS Variables.tmbundle
directory to your Bundles directory (somewhere
close to C:\Documents and Settings\[USER_NAME]\Application Data\e\Bundles
), then use the
Reload Bundles
command.
Bundle Contents
Commands
- Build CSS ⌘R
- The one you'd use while developing, since it retains the variables at-rule and keeps track of the replaced variables.
- Freeze CSS ⌃⇧⌘F
- This is the "no turning back" version of the above, because it erases its tracks upon invocation... use for deploying a clean CSS file.
Snippets
- CSS @variables vars⇥
- Expands to the @variables at-rule where you define your variables. This should be the first at-rule in the stylesheet!
- CSS var() var⇥
- Expands to a single variable replacement
Get Started Now
Using the bundle is very easy - just create a new document ⌘N, switch to the CSS Language ⌃⌥⇧C and type vars... then hit the ⇥ (TAB) key, and you're already on your way!
Check the sidebar for a list of what's currently included in the bundle.
Todo List
The Bundle does a couple of key things, but there's always room for improvements, so - in no particular order, this is the list of features I'd like to add, some day:
- Add scope(s) to the CSS language parser to allow for syntax colouring
- Add a Command for restoring replacements to their initial
var()
references - Create a "Toggle Variable Display" command ⇧⌃V
that toggles the current line between var() [a] and
development [b] modes, e.g.:
color: var(standardColor);
color: #fff; /* var(standardColor) */
- Put the source in Subversion (or on Github if I get adventurous)
Caveats
- Since the entire value of a rule is replaced, you cannot use a variable replacement as a
single value in a shorthand rule, e.g. the following won't work:
but this will:@variables { borderWidth: 2px; borderColor: #911; } div { border: var(borderWidth) solid var(borderColor); }
@variables { borderSettings: 2px solid #911; } div { border: var(borderSettings); }
- When using the Freeze CSS command, you get some whitespace for free before the first rule in the resulting file... :-)
Disclaimer
Do whatever you like with this, but please... don't hold me responsible for anything you accidentally lose while doing so, okay?
- Chriztian Steinmeier, May 2008. <chriztian [at] steinmeier [dot] dk>