Project

foam

0.0
No commit activity in last 3 years
No release in over 3 years
Foam is a meta generator for generating scaffold for a Rails application from a description of the application's resource layout
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

= 3.0.0
 Project Readme

Foam

Foam installs an experimental meta generator for generating scaffold for a Rails application from a description of the application’s resource layout

Installation

gem install foam

Usage

First we need to install foam

# Gemfile
gem 'foam'
gem 'ingoweiss_generators' # or any other generator that can be driven by foam (see below)

Then, we run foam once to create the ‘config/resource_layout.rb’ file

# reply with 'yes' when prompted 'Create resource layout file?'
rails generate resource_layout

Next, edit ‘config/resource_layout.rb’ to match the resource layout you want to generate. Presently, there is really not much to the syntax: ‘many’ is for plural and ‘one’ for singular resources, resource attribute name/type pairs are passed in as an options hash:

# config/resource_layout.rb
ResourceLayout.define do
  many :posts, :title => :string, :body => :text do
    many :comments, :body => :text
    one :approval
  end
end

Lastly, run foam using the scaffold generator of your choice. Foam expects a scaffold generator which, in addition to the usual ‘name’ and ‘attributes’ arguments supports a ‘scope’ option of type array for specifying parent resources and a ‘skip-routes’ option for skipping route definition injection (so that foam can inject the nested route definition at the end instead). The ingoweiss_generators gem contains the ‘ingoweiss:scaffold’ generator that meets those requirements

rails generate resource_layout --generator=ingoweiss:scaffold

This will generate scaffold for the following resources:

  • /posts
  • /posts/123/comments
  • /posts/123/approval

Please note that due to the experimental nature of foam it is subject to change

Copyright © 2010 Ingo Weiss, released under the MIT license