zen-coding: turn those CSS selectors upside down
secretGeek .:dot Nuts about dot Net:.
home .: about .: sign up .: sitemap .: secretGeek RSS

zen-coding: turn those CSS selectors upside down

zen-coding, online demonstration

Web developers Sergey Chikuyonok and Vadim Makeev have built a nifty set of plugins called 'zen-coding' that work across a range of IDE's.

The niftiest idea from 'zen-coding' is a way of writing Html very very quickly, by a kind of reverse-application of CSS-selectors.

Ah, I think examples will show what words could never explain...

If you type:

div.name

and press the shortcut-key to invoke 'zen-coding' -- the snippet expands into this piece of html:

<div class="name"></div>

If you type:

div#name>p+p

and invoke 'zen-coding' -- the snippet becomes:

<div id="name">
  <p></p>
  <p></p>
</div>

There are more complicated scenarios as well: if you understand CSS selectors, you'll wrap your head around it very easily.

Hence, zen-coding lets you write markup very very quickly.

I've built an online demonstration, a simple web app that uses the code from Sergey's aptana plugin.

These ideas have been re-implemented for emacs, and there's a vim re-implementation in the wild as well.

There's some very good screencasts around, here's one from Vadim and one from Sergey.

This is a cool idea. In the same way that JScript takes CSS Selector DSL and re-purposes them, 'zen-coding' squeezes extra utility out of this tiny DSL. What other DSL's can be used backwards, forwards, sideways? Can linq expressions be reversed for generating .net classes (rebuilder style)? Can SQL Select Queries be parsed and turned into DDL for creating a database schema? Can XPath be used as an XML generation tool?

It's also gotten me thinking about how this style of code generation can be applied to my favourite little hobby-tool, 'World's Simplest Code Generator'

WSCG has come a long way lately, as I've been using my bus-rides to make WSCG more powerful (typing on the HP-mini I got at Tech-Ed) adding more macros, built-in functions, an extensive help file, and some powerful operators called $ONCE and $EACH.





'Einar Egilsson' on Tue, 10 Nov 2009 08:03:15 GMT, sez:

That is incredibly cool! It's inspired me to start on a Visual Studio AddIn for this. I've already added a C# wrapper around the original python implementation using IronPython, since I don't want to port. Now I just need to work on the abomination that is the Visual Studio extension API and hookup some commands. I'll post it probably this weekend or next week when I have a little more time.



'lb' on Tue, 10 Nov 2009 08:09:04 GMT, sez:

@Einar -- brilliant!
I'd love to see it in visual studio.

But also, I'd love to see it implemented in IronPython, so I can try and get my head around adding it to 'MetaNote', the editor I'm (sometimes) working on.

Stick to it Einar, this is very cool stuff.



'Alexander Nikitin' on Tue, 10 Nov 2009 08:57:39 GMT, sez:

This is really cool. Have thought of it many times, but it turned out to be too complex, etc.

And that solution is pure, clean and nice :)



'Einar Egilsson' on Tue, 10 Nov 2009 12:49:05 GMT, sez:

If you just want to access it from an IronPython script then that is no problem. The library runs perfectly in IronPython, it only requires the re regular expression module. You just add the zencoding folder to your IronPython search path and then do something like:

>>> from zencoding.zen_core import find_abbr_in_line, expand_abbr
>>> abbr, startIndex = find_abbr_in_line('bla td', 6)
>>> abbr
'td'
>>> startIndex
4
>>> expand_abbr(abbr)
'<td></td>'

And then there's some extra magic around setting the insertion point, indentation etc. but nothing that should be a problem.



'mongo lloyd' on Tue, 10 Nov 2009 16:24:21 GMT, sez:

That's truly brilliant. One of those "why didn't I think of that?" ideas.



'Einar Egilsson' on Thu, 12 Nov 2009 20:31:55 GMT, sez:

ZenCoding Visual Studio AddIn for VS2005,VS2008 and VS2010b2 now available at: http://tech.einaregilsson.com/2009/11/12/zen-coding-visual-studio-addin/



'lb' on Fri, 13 Nov 2009 01:49:39 GMT, sez:

Brilliant work Einar!

Very handy stuff.

Now I have to work out how to configure it, and how to add snippets...



'Evgeniy Dolzhenko' on Mon, 23 Nov 2009 07:58:00 GMT, sez:

Also somewhat reminds me of http://rubyquiz.com/quiz143.html




name


website (optional)


enter the word:
 

comment (HTML not allowed)


All viewpoints welcome. But the right to delete any post for any reason is reserved. Don't make me do it. Comments may be republished, emailed to your loved ones or printed and used as toilet paper. Who reads this legal bit anyhow?

TimeSnapper is a life analysis system that stores and plays-back your computer use. It makes timesheet recording a breeze, helps you recover lost work and shows you how to sharpen your act.

TimeSnapper won last year's Developer Competition at Larkware.com, and is used by over 10,000 people.

Articles

JSON Query Languages: 5 special purpose editors JSON Query Languages: 5 special purpose editors
What then, is b? What then, is b?
SQLike: A simple editor SQLike: A simple editor
Yet Another BizPlan Generator. Yet Another BizPlan Generator.
HOT GUIDS: A hot or not site for guids HOT GUIDS: A hot or not site for guids
How does life get better? One tiny hack at a time. How does life get better? One tiny hack at a time.
24 things to do, and 100 things *not* to do (yet) for building a MicroISV 24 things to do, and 100 things *not* to do (yet) for building a MicroISV
Venture capital won't kill Jeff Atwood, it will only make him Jeffer. Venture capital won't kill Jeff Atwood, it will only make him Jeffer.
A handy workflow image for newbie mercurial users A handy workflow image for newbie mercurial users
Fractal Feedback, a diversion into recreational programming Fractal Feedback, a diversion into recreational programming
Hump-Jumping: How the Education of Computer Science can be Saved, err, maybe. Hump-Jumping: How the Education of Computer Science can be Saved, err, maybe.
Suggested User Experience Improvements for DiffMerge Suggested User Experience Improvements for DiffMerge
SQL Style Extensions for C# SQL Style Extensions for C#
The Movie Hollywood (And My Wife) Doesn't Want You To See: Weekend at Jacko's The Movie Hollywood (And My Wife) Doesn't Want You To See: Weekend at Jacko's
Sysi: the ultimate administrators toolkit Sysi: the ultimate administrators toolkit

Archives .: secretGeek :: Complete Archives
TimeSnapper -- Automated Screenshot Journal TimeSnapper.com    
Version 3.3: true productivity boost

Next Action NextAction
Managing the top of your mind

World's Simplest Code Generator (html edition) World's Simplest Code Generator

25 steps for building a Micro-ISV 25 steps for building a Micro-ISV
3 minute guides -- babysteps in new technologies: powershell, JSON, watir, F# 3 Minute Guide Series
Universal Troubleshooting checklist Universal Troubleshooting Checklist
Top 10 SecretGeek articles Top 10 SecretGeek articles
ShinyPower (help with Powershell) ShinyPower
Now at CodePlex

Realtime CSS Editor, in a browser RealTime Online CSS Editor
Gradient Maker -- a tool for making background images that blend from one colour to another. Forget photoshop, this is the bomb. Gradient Maker


[powered by Google] 


How to be depressed How to be depressed
You are not inadequate.



Recommended Reading

The Best Software Writing I
The Business Of Software (Eric Sink)

Recommended blogs

Jeff Atwood
Joseph Cooney
Phil Haack
Scott Hanselman
Julia Lerman
Rhys Parry
Joel Pobar
OJ Reeves
Eric Sink

Aggregated Links

proggit
dzone
hacker news
dot net kicks

Human Link Machines

interesting finds
a continuous learner's weblog
arjan's world
weekly link post

LinkedIn profile
LogEnvy - event logs made sexy
ShuffleText - fuzzy search for .net
PC Smart Buys - Computer Hardware in Australia
 
home .: about .: sign up .: sitemap .: secretGeek RSS .: © Leon Bambrick 2006 .: privacy

home .: about .: sign up .: sitemap .: RSS .: © Leon Bambrick 2006 .: privacy