Project

commaparty

0.0
No commit activity in last 3 years
No release in over 3 years
A ruby implementation of Clojure's Hiccup markup generation library.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.3
>= 0
>= 0

Runtime

 Project Readme

CommaParty

Build Status

CommaParty is a Ruby implementation of Clojure's Hiccup HTML generation library. It uses arrays to represent elements, and hashes to represent an element's attributes. Unlike in Clojure, you have to use a lot of commas everywhere all the time.

Install

Add the following dependency to your Gemfile:

gem 'commaparty'

then

require 'commaparty'

Syntax

Here is a basic example of commaparty syntax:

[1] pry(main)> require 'commaparty'
=> true
[2] pry(main)> CommaParty.markup([:span, {class: "foo"}, "bar"])
=> "<span class=\"foo\">bar</span>"

The first element of the array is used as the element name. The second attribute can optionally be a hash, in which case it is used to supply the element's attributes. Every other element is considered part of the tag's body.

It provides a CSS-like shortcut for denoting id and class attributes:

[1] pry(main)> CommaParty.markup([:'div#foo.bar.baz', "bang"])
=> "<div class=\"bar baz\" id=\"foo\">bang</div>"

If the body of the element is an array, its contents will be expanded out into the element body. This makes working with methods like map more convenient:

[2] pry(main)> CommaParty.markup([:ul, (1..4).map {|n| [:li, n]}])
=> "<ul>\n<li>1</li>\n<li>2</li>\n<li>3</li>\n<li>4</li>\n</ul>"