Skip to content

ingoweiss/foam

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A Resource Scaffold Meta-Generator

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages