Helping Sprouts Grow




Ask me anything

SC-Gen naming conventions (why isn’t it doing as I say!)

When I first started using sc-gen, little things kept tripping me up.

If you type “sc-gen model MyApp.SomeValue”

You’d get a file called “some_value.js” (note a _ is added, and your case is missing).  Worse, when you open the file, you’d be back in “some_value.js” using MyApp.SomeValue! The good news is, according to my understanding, this is merely because sc-gen is attempting to “gently suggest” a naming convention for you, you can change the file names at will.

This also extends to “sc-gen controller MyApp.MyController”  you’ll note that sc-gen will make a file in Controllers called “my.js” instead of “MyController.js”  (We both know, even if it added controller, it would say “My_Controller.js” just to spite you!)

Yet again, if you open the file, it’ll be called “MyApp.MyController = SC.ObjectController…”

Yep, you got it, you can rename the file to “MyController.js” and remain at ease. The same will happen to the word model & view as well, sc-gen apparently feels being inside a folder called “controller” or “view” is apt enough to describe the file and truncates it for you.

Rename & regain your sanity, its safe.  Just don’t forget to update any

sc_require(‘view/newView.js’) and so on, to reflect your newly discovered power.

———————————————————————————————

Edit: I decided to go ahead & post a more permanent fix to this problem.  If you download sproutcore abbot (the build tools for sproutcore)

 http://github.com/sproutit/sproutcore-abbot

You can modify this behavior yourself. Here’s what you do (Removing the “auto remove “controller” ” string behavior in this example)

  1. cd into where you downloaded abbot
  2. cd gen
  3. cd controller
  4. nano Buildfile
  5. Delete this line “GENERATOR.filename = GENERATOR.filename.sub(/_controller$/,”) “
  6. Ctrl X, Y, Enter (Exit, Save changes)
  7. Run sc-gen controller as you normally would , and it should no longer strip the name “controller” from your files. Remember you need to run the *abbot* sc-gen, and not your gem.  ”/abbot/bin/sc-gen” and not just “sc-gen”

This applies to all the Build files for controller/view/data_source, you can strip the last line to remove that behavior

GENERATOR.filename = GENERATOR.filename.sub(/_view$/,”)

GENERATOR.filename = GENERATOR.filename.sub(/_data_source$/,”)