Git Product home page Git Product logo

generators's Introduction

Generators

Generators for CompoundJS MVC framework.

model

command

compound generate model modelName [ field, ... ]

modelName: word in singular form

field: word OR word:datatype, when :datatype is missing String property created

files

Model generator create/patch following files and directories:

create  ./app
create  ./app/models
create  ./app/models/modelName.js
patch   ./db/schema.js

examples

compound g model user email password approved:boolean

Example above will generate User model with the following fields:

  • email: String
  • password: String
  • approved: Boolean

Following example will generate Post(title, content) model using coffee-script

compound g post title content --coffee

controller

Generate controller with number of actions and views

command

compound generate controller controllerName [actionName, ...]

controllerName: word (plural or singular form)

actionName: word in camelcase with first lowercase letter

files

Model generator create/patch following files and directories:

exists  ./app
exists  ./app/controllers
create  ./app/controllers/controllerName_controller.js
exists  ./app/helpers
create  ./app/helpers/controllerName_helper.js
exists  ./app/views
create  ./app/views/controllerName
create  ./app/views/controllerName/actionName1.ejs
create  ./app/views/controllerName/actionName2.ejs
...
create  ./app/views/controllerName/actionNameN.ejs

examples

compound generate controller profile show edit

exists  app/
exists  app/controllers/
exists  app/helpers/
exists  app/views/
create  app/views/profile
create  app/controllers/profile_controller.js
create  app/helpers/profile_helper.js
create  app/views/profile/show.ejs
create  app/views/profile/edit.ejs

scaffold (crud)

Generate controller with CRUD actions, views, and model. Patch routes and schema. Most powerful generator for quick prototyping.

command

compound generate crud modelName [ field, ... ] [ options ]

modelName: word in singular form

field: word OR word:datatype, when :datatype is missing String property created

options:

  • --noeval - create noeval controllers
  • --tpl - specify templating engine (ejs and jade supported)

example

compound generate crud post title content

Will generate scaffold for Post(title, content) model. Following files/directories will be created:

create  client-side.js
create  app/
create  app/controllers/
create  app/helpers/
create  app/views/
create  app/views/posts/
create  app/views/layouts
exists  test/
exists  test/controllers/
create  app/controllers/posts_controller.js
exists  app/
create  app/models/
create  app/models/post.js
patch   db/schema.js
create  app/views/layouts/posts_layout.ejs
create  app/views/posts/_form.ejs
create  app/views/posts/show.ejs
create  app/views/posts/new.ejs
create  app/views/posts/edit.ejs
create  app/views/posts/index.ejs
create  app/helpers/posts.js
exists  test/controllers/posts_controller_test.js
exists  test/test_helper.js
patch   config/routes.js

License (MIT)

Copyright (C) 2011 by Anatoliy Chakkaev <mail [åt] anatoliy [døt] in>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

generators's People

Contributors

1602 avatar romb avatar saschagehlich avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

generators's Issues

Camel Case models break scaffolded views in coffee mode

I need a table for 'packages'. Initializing with --coffee, it won't let me make that table, saying it's a reserved word. It will create it happily if the project is javascript, but I want coffee, and I don't see a NOT coffee switch for the scaffolding.

So I renamed it 'appPackage', trying to stick to javascripty formatting.

That breaks the view--at least, the add view, with:

12| h1 New apppackage
13|
> 14| - var form = formFor(apppackage, {action: pathTo.apppackages(), method: 'POST', id: "apppackage_form", class: 'form-horizontal'})
15|
16| != form.begin()
17| include _form

It looks like the schema and models are keeping the CamelCase, but the views are lowercasing everything?

---- Comment from Anatoliy ----
There's no way to correct this behavior currently using generators. But I
agree this makes life harder sometimes. To fix it need to come up with some
naming convention in model/crud generator. For example always assume model
is camelCase singular word. And then just produce all forms used in app:
lowerCase first camelcase singular for instance name, upperCase first
camelcase singilar for class name, lowerCase first plural for collections.
It also may require some fixes in routing helpers generators. Probably it
worth opening issue in co-generators package.

---- Comment from Neil ----
There's never going to be a way to always get automated plurals and casing correct; there're just too many mutations. It might be simpler in other languages, but English at least is about 90% edge-cases.

I would vote for the above (assume camelCase singular), but possibly with override options (-plural xxxx). .NET uses a -tablename option. -collection, or similar might be good options.

Admin scaffold

We can provide an administration module like django to consume all CRUD files, and create a default user table for authentication?

Generated helpers aren't recognized until renamed to [controller]_helper.js

When helpers are generated for a controller, they do not include the _helper suffix.

For example when post crud is created, a file called [projecthome]/app/helpers/posts.js is created. However, it does not show up in the view until it is renamed to [projecthome]/app/helpers/posts_helper.js.

Although the _helper seems redundant, it's currently required in order for the function to be recognized.

crud generators ending with 's' blow up

compound generate crud status

fs.js:338
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^
Error: ENOENT, no such file or directory '/data/home/nbryant/src/nodeapps/compound/cv/app/views/status/_form.ejs'

The controller is named incorrectly (singular statu_controller, rather than plural) and internally refers to 'statu'. Model is correct.

If I pluralize the command (compound g crud statuses), the controller, handler, etc all look correct, and only the model file is wrong (plural filename, plural object internally)... but there is only the one file to fix.

I took a stab at finding the problem, but didn't really get anywhere in the time I have. I see vendor/inflection.js and the rules look OK, but I'm not certain... are the first regexes stripping off 's' at the end of a word?

I've tried this with several other nouns: octopus, alias, bus, and all fail when scaffolded in the singular. Nouns not ending in 's' (ox, person, matrix) all work as expected.

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.