Very simple plugin to generate and use a simple rails dsl for
describing ActiveRecord collection listings, it doesn’t add any
awesome behavior, it just looks nice.
First install the actual plugin:
script/plugin install git://github.com/rha7dotcom/listing_for.git
Then run the generator, to place the theme files in public drectory:
script/generate listing_for
The add a css stylesheet link tag line to your layout, at the appropriate place:
= stylesheet_link_tag 'listings/ui-lightness', :media => "screen, projection"
And that’s all, just follow the example below to get an idea of how it works, hopefully with a bit more time, I’ll add more themes and give more help on usage.
Using HAML, this:
- listing_for "Products Listing", @products, :will_paginate => true do |list|
- list.add Product.human_attribute_name(:upc_code) do |product|
= product.upc_code
- list.add Product.human_attribute_name(:name) do |product|
= product.name
- list.add Product.human_attribute_name(:description) do |product|
= product.description
- list.add Product.human_attribute_name(:price) do |product|
= number_to_currency(product.price)
- list.add Product.human_attribute_name(:stock), :align => :right do |product|
= number_to_currency(product.stock)
- list.add Product.human_attribute_name(:unit), :align => :right do |product|
= product.unit.name
- list.add "Actions" do |product|
= product.upc_code
Produces this:
Please feel free to contribute, modify at your heart’s content and send me a pull request, I’d be glad and honored to hear from you.
Greetings,
Gabriel Medina
Copyright © 2009 Gabriel Medina, released under the MIT license