assign ( 'classes', list ( ) ),
macro ( 'walk_classes', lambda tag, is_tag:
classes.extend ( [ "%s.%s { }" % ( tag.name, _v ) for _k, _v in tag.attrs.items ( )
if _k in ( '_class', 'class_', '_class_' ) ] )
),
macro ( 'walk_ids', lambda tag, is_tag:
classes.extend ( [ "%s#%s { }" % ( tag.name, _v ) for _k, _v in tag.attrs.items ( )
if _k in ( 'id', 'id_', '_id', '_id_' ) ] )
),
macro ( 'extract_css', lambda tag:
tag.walk ( walk_classes, True ) and tag.walk ( walk_ids, True ) and tag
),
macro ( 'css_results', lambda:
ul ( style = 'list-style: none;' ) [
[ li [ _c ] for _c in classes ]
]
),
html [
head [
title [ 'Extract styles' ]
],
body [ extract_css (
div ( class_ = 'text', id = 'main-content' ) [
img ( src = '/images/breve-logo.png', alt = 'breve logo' ),
br,
span ( class_='bold' ) [ '''Hello from Breve!''' ]
]
), css_results ( ) ]
]
This outputs the original page with the CSS selectors at the end like so:
div.text { }
span.bold { }
div#main-content { }
I'm probably going to redo this as a tool (CSS extractor), but I have to
admit I thought it was pretty cool that it could be done with macros =)
Thanks Sven, for an effing great idea!
Regards,
Cliff
> This outputs the original page with the CSS selectors at the end like so:
>
> div.text { }
> span.bold { }
> div#main-content { }
>
Let me add that this is probably the worst possible thing to do in a
template, I just did it to see if it would work =)
Professional-driver-on-closed-course'ly yrs,
Cliff