Skip to content

Class & Package Names Within Templates

Dominic Chambers edited this page Feb 26, 2014 · 2 revisions

It would be useful if templates could have access to different versions of node names (e.g. blade, bladeset, aspect, etc), depending on what they are being used for, for example:

  • Lower case for package, file and directory names.
  • Title case for class names.

At present however, the persisted version of a nodes's name is given by the all lower-case name used to define the directory it lives within, and a title case name can't be re-created from this. So we either need to allow a rich version of the name to be persisted, that can be converted to a title case name, or we allow an optional title case name to be provided at the point of node creation, solely for one-time use during template population.

Storing the directory names using either title case, camel case, hyphenated lower-case or underscored lower-case would allow both title case and lower-case names to be automatically calculated, but is problematic for a number of reasons:

  • Require paths and fully qualified package names would have even less relation to the directory names we view on disk, increasing cognitive load.
  • We currently ban the use of underscores and hyphens within file names because we use them as delimiters in a number of places (this may no longer be the case now that we have updated our bundlers, and once we update our directory structure), which potentially rules out these two strategies.
  • Web developers tend to favor lower-case directory names, and hyphenated lower-case or underscored lower-case file names, so this could look foreign depending on the option used.

If we assume that new users will generally be using Node.js style classes, and will therefore never need to use fully qualified class names anywhere, then we could also allow richer names that would map directly to require names, but have an awkard mapping to their associated fully qualified class name, for example:

my-lib/Class1 -> my_lib.Class1

Alternatively, if we are happy to ignore web developers general practice of favouring lower-case directory and file names, we could use camel case names which map better from require path to fully qualified class name, for example:

myLib/Class1 -> myLib.Class1

At the very beginning we mentioned that an alternative would be to provide a temporary title case name for the duration of template creation only, but since users might not want to provide this we could, by default, just automatically convert the first letter of the given lower-case name to upper-case.

Because we had difficultly navigating all the compromises that the various solutions have, and because we think any final solution may be affected by the pluggable template solution we plan to introduce, for the time being we have gone for an even simpler version of the solution above, where a temporary title case name is used, but without even the ability to optionally provide an alternative title case name for times when the node name contains more than word.

Clone this wiki locally