On Wed, Nov 6, 2013 at 7:24 PM, Edward K. Ream <[email protected]> wrote:

>
> > I've hacked away on Brian's script. This has been a lot of fun.
>
> The old way of generating selectors was:
>
> table = (
>         # bits: dirty=8,clone=4,mark=2,body=1.
>         (0,'leaf'),
>         (1,'body'),
>         (2,'mark'),
>         (3,'mark-body'),
>         (4,'clone'),
>         (5,'clone-body'),
>         (6,'clone-mark'),
>         (7,'clone-mark-body'),
>         (8,'dirty'),
>         (9,'dirty-body'),
>         (10,'dirty-mark'),
>         (11,'dirty-mark-body'),
>         (12,'dirty-clone'),
>         (13,'dirty-clone-body'),
>         (14,'dirty-clone-mark'),
>         (15,'dirty-clone-mark-body'),
>     )
>     boxes_css = '\n'.join([
>         'li.%s {\n  background-image: url(%s)\n}' %
> (kind,icon('box%02d.GIF' % (n)))
>             for n,kind in table])
>
> But this is bad style.  It is error prone and hides the essential
> relationships in the box naming.
>

Otoh, it's pretty clear what is going on ;-)


>
> In contrast, the following shows that icons are named in a specific manner.
>
>     def selector(n):
>         table = ((8,'dirty'),(4,'clone'),(2,'mark'),(1,'body'))
>         return '-'.join([s for n2,s in table if n & n2]) or 'leaf'
>
>
> 
> 
> def css(n):
>         return 'li.%s {\n  background-image: url(%s)\n}' % (
>             selector(n),icon('box%02d.GIF' % n))
>
>     boxes_css = '\n'.join([css(n) for n in range(15)])
>
> The table in the selector function makes the bits explicit: the dirty bit
> is the 8 bit, and so on.
>

It can be made clearer if we define::

    def box(n):
       return icon('box%02d.GIF' % n)

Then the css function is::

    def css(n):
        return 'li.%s {\n  background-image: url(%s)\n}' % (
            selector(n),box(n))

Oh well, it's a minor matter.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to