grails

Grails documentation

Sunday, November 16th, 2008 | grails | 1 Comment

Open source projects don’t just require contributions to code, a lot of work goes into creating relevant and timely documentation. The fast pace that many open source projects work at mean that frequent releases can leave documentation frustratingly out of date.

There are a few things I like about how the Grails project manages it documentation. Firstly their website Grails.org has an own edit (Wiki) style. Meaning that pages regarding the many tutorials, plugins, new features can be updated by the community. This open style means that the project leads have more time to focus on more complex tasks.

Secondly I really like the Sun javadoc style Grails Framework Reference Documentation which are now being produced. The documentation includes descriptions and examples of the various aspects of the Grails framework.

Lastly, if any of the documentation is out of date for any reason, the community is invited to report problems to the project’s issue tracker to be recorded. Other members of the community can then look into any alterations which need to be made.

Grails natural names - GRAILS-564

Saturday, November 15th, 2008 | grails | No Comments

True to my pledge I’ve dived straight into the Grails source code, and the project’s issue tracker.

To start with I picked an improvement classed as ‘Trivial’ which I thought just about matched my level of Grails source code knowledge.

GRAILS-564 - “Have scaffolding display friendly names instead of camel case class names”

With my own use of Grails I’d seen that class properties were now being displayed with ‘friendly names’.

For example a domain class such as:

  1. class ManyWords {
  2.   String LotsOfWords
  3. }

The property LotsOfWords is defaultly displayed in the scaffolding as “Lots Of Words”, however the class name was still being displayed as the short code “ManyWords” instead of “Many Words”.

So to the fix.

I traced the scaffolding creation to the class DefaultGrailsTemplateGenerator. This class is responsible for the creation of the default scaffolding views and controllers. Its in this class where a map of values is passed to the templates in “src/grails/templates/scaffolding/” when you call a command like “grails generate-all <classname>”. Here is where I was going to make my change.

  1. def binding = [packageName: packageName,
  2.                 domainClass: domainClass,
  3.                 multiPart: multiPart,
  4.                 naturalClassName:domainClass.naturalName,
  5.                 shortClassName:domainClass.shortName,
  6.                 propertyName:  getPropertyName(domainClass),
  7.                 renderEditor: renderEditor,
  8.                 comparator: org.codehaus.groovy.grails.scaffolding.DomainClassPropertyComparator.class]
  9.  
  10. t.make(binding).writeTo(out)

I passed in a new property naturalClassName, to the view templates and replaced it with the
previous place holder where it was appropriate. The natural name is created using the method:

  1. GrailsClassUtils.getNaturalName(string)

Search