Back

Announcing the Listify Gem

In a recent project, I had to do a fair amount of work dealing with nested HTML lists. Although they seemed simple enough, things did not go quite as simply as I expected which gave me material for two blog posts: Nesting the rails content_tag helper and Nesting the content_tag helper more deeply.

While not rocket science or brain surgery it occurred to me that I might have to deal with this again. To that end, I created the Listify Gem to help with creating HTML lists from ruby collections. For example, here is a ruby hash rendered as a two level list:

listify { 'First Category' => ['item one','item two'], 
          'Second Category' => ['item three','item four'] 
        } 
  => "<ul>
        <li>First Category
          <ul>
            <li>item one</li>
            <li>item two</li>
          </ul>
        </li>
        <li>Second Category
          <ul>
            <li>item three</li>
            <li>item four</li>
          </ul>
        </li>
      </ul>"

I don’t really know how likely it is that this gem will be useful to anyone else, but it’s out there and I welcome any feedback anyone might have.

Leave a Reply

Your email address will not be published. Required fields are marked *