GithubHelp home page GithubHelp logo

beds's Introduction

Beds

A BootStrap ERb DataMapper Sinatra [Scaffolder]

beds will generate a set of Sinata application in an MVC style directory structure with routes and corrisponding ERb views that will allow you to manipulate the DataMapper models specified in your models.rb.

Usage

beds scaffold -m <models.rb> [OPTIONS]
   -m, --models FILE                Specify file with DataMapper models defined.
   -v, --viewdir                    Specify which directory to place the views in. Default: ./views/
   -r, --routefile                  Sepcify the file to generate the routes in. Default: scaffold.rb
       --exclude x,y,z              Do not generate anything for specified models, or before, index, and/or layout
       --only x,y,z                 Only process the specified models.
   -f, --[no-]force                 Overwtie files

Example models.rb

require 'rubygems'
require 'dm-core'
require 'dm-mysql-adapter'
require 'dm-migrations'
require 'dm-validations'
require 'yaml'

# Assumes a "database.yml" configuration file.
db_config = YAML.load_file(File.join(File.dirname(__FILE__),"database.yml"))
DataMapper.setup(:default, "mysql://#{db_config['user']}:#{db_config['password']}@#{db_config['server']}/#{db_config['database']}")

class User
  include DataMapper::Resource
   property :id, Serial
   property  :name, Text, :required => true, :messages => { :presence => "Please enter your name" }
   property  :login, Text, :required => true, :unique => true, :messages => { :presence => "Please select a login ID", :is_unique => "Login already in use. Try again" }
   property  :pasword, Text, :required => true, :length => 6..100, :messages => { :presence => "Please provide a password", :length => "Sorry.  Your password must be between 6 and 100 characters long." }
   property  :email, Text, :format => :email_address, :unique => true, :messages => {  :format => "Please check your email address and try again.", :presence => "It looks like you forgot to enter your email address.", :is_unique => "Sorry. This email is already associated with a different account" }
end

class Product
  include DataMapper::Resource
  property :id, Serial
  property :title, Text, :required => true, :messages => {:presence => "Please name the server",:is_unique => "You " }
  property :description, Text, :required => true, :messages => { :presence => "Please provide a description of the product." }
  property :price, Float, :required => true, :messages => { :presence => "You must provide a price." }
end

app.rb example:

require 'rubygems'
require 'sinatra'
require './models.rb'
Dir.glob("#{File.dirname(__FILE__)}/controllers/*.rb").each { |controller| load controller }

Example cli usage

beds scaffold -m models.rb

Custom Templates

See the templates directory for example templates.
Templates should be in ~/.beds/<template_dir>/.  The <tempalte_dir> can be one of erb, static_erb, routes, static_routes, or hooks.
* erb - Views for save, edit, view, etc that need to be generated for every model.
* static_erb - Views like 'index.erb' that only need to be included once.
* routes - Routes needed to be generated for every model, i.e. view, edit, save, delete.
* static_routes - Routes only needed to be included once, i.e. get '/'
* hooks - Ruby scripts that will be 'eval'ed after the scaffolding to download required files (i.e. bootstarp & jquery)

beds's People

Contributors

jamez01 avatar

Watchers

 avatar  avatar

Forkers

marks

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.