Code Monkey home page Code Monkey logo

foam's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.