Drupal Module Builder Gem

Drupal now has a Ruby gem to vastly increase your productivity with Drupal development. Although this is currently in early ALPHA (0.0.5) you can install it and check out its fully functional module builder.

Features

  • Module builder
  • Todo list viewer
  • Project installer (modules, themes, core)

Installation

First open a terminal window and add Github to the gem sources, allowing Github to serve gems (do this only once).


$ gem sources -a http://gems.github.com

The command below will install the tool from its remote repository.


$ sudo gem install visionmedia-drupal

Screencast

Click here to view the screencast for version 0.0.5.

Usage - Todo List Viewer

Gathers todo lists from within the current directory recursively. In this case Drupal 6 core. Accepts also additional directory or filename arguments.

$ drupal todo list

./includes/menu.inc
   - Handle the case like a local task on a specific node in the menu.

./includes/session.inc
   - remove this when we require at least PHP 4.4.0

./modules/color/color.module
   - This should be solved in a different way. See issue #181003.

./modules/node/node.module
   - : use a better word counting algorithm that will work in other languages

./modules/tracker/tracker.pages.inc
   - These queries are very expensive, see http://drupal.org/node/105639
./modules/user/user.module
   - This should be solved more elegantly. See issue #119038.

Usage - Module Builder

The module builder walks you through a simple interactive wizard which produces entire modules consisting of up to the following (optional):

  • Several hooks with sample code (ranging from schema, block, menu and more)
  • Populated README.txt
  • Populated CHANGELOG.txt
  • <module>.info populated with all its information
  • <module>.module populated with hook implementations
  • <module>.install (created only when related hooks are chosen)

Initiates creation of the 'gui' module.

$ drupal create module gui

Below shows part of the module creation wizard, its very simple, but very fast and effective way to create normalized modules.

What is your name?:
TJ Holowaychuk

What is the URI to your companies website?:
http://vision-media.ca

What is your email?:
tj@vision-media.ca

Enter a human readable name for your module:
GUI

Enter a short description of your module:
Graphical User Interface utilities

Enter a list of dependencies for your module:
jquery_update jquery_ui

Hooks:
- block
- boot
- cron
- form_alter
- init
- menu
- perm
- schema
- theme

Which hooks would you like to implement?:
init menu schema perm

Usage - Project Installer

The project installer automatically downloads, extracts, and performs garbage collection for downloading Drupal core and modules. Currently only supports Drupal 6.x (same as module builder), however this may change in the future.

Install Drupal core 6.x to current directory:

$ drupal install core

Make the modules and themes directories in our new installation:

$ cd ./drupal-6.4
$ mkdir ./sites/all/{modules,themes}

Install several modules from Drupal root:

$ drupal install devel ./sites/all/modules
$ drupal install ac ./sites/all/modules

Install directly in the modules directory:

$ cd ./sites/all/modules
$ drupal install err
$ drupal install pathauto

Install directly in the modules directory using an optional list of projects:

$ cd ./sites/all/modules
$ drupal install err,pathauto,devel,ac

Future Features

As this gem is in active development adding more hook implementations and additional commands, please leave comments if you have any ideas for what you would like to see. ** Tested on Mac OS 10.5.5 **

Curious how much code you wrote? Check out the Source code analysis gem.

Comments

This is pretty much the coolest thing ever in the whole world.

I agree, I really collect conventions from both frameworks / languages. Ruby has certainly opened up my mind as far as doing things the way I think they SHOULD be, PHP ... well... haha, not going to bash PHP because it certainly has its place, but I dont know if I could go back to it now simply on an enjoyment level even.

To be honest I do not even use rails really, mostly lighter frameworks like merb or camping, (taking a look at Mack now, looks promising). I do agree though some times a Drupal instance is simply just WAY faster to set up, regardless of how agile these ruby frameworks are. I also find due to migration features of these ruby ORMs and their agile nature theres almost no need to facilitate 'nodes', or 'tags' on their own, you can go ahead and have a 'blog post', with 'blog post tags' etc, and thanks to metaprogramming your not really screwing yourself over by not having a generic tags table

I'm in Love with RoR too.
Yet I still get most of my customers trough my Drupal-work. But even then, I still do the occasional wordpress site, or a lost Joomla! install.

My idea: use tools where they are best. For many people the turnkey-readyness of a Drupalsite is highly valued over the have-to-think-about-everything-myself approach. Tagging in RoR is not hard, but still needs some time, thought and work. Tagging in Drupal is ready-to-go, in fact: you cannot really give it much thought, Drupal does tagging his way, so why bother at all.

That is just one of many examples of why one can easily do both Drupal and RoR work.

-- BTW: whenever I write RoR, my dba is very often inspired by Drupalisms: nodes, users, tags etc.

Also as you mentioned with the templating. I have a similar approach to ERB with 'mygem' a ruby gem scaffolding system I am working on which will support a copy of base templates to ~/.mygem/templates, which in turn can be altered at will, or you can create entirely new ones. Hopefully I will have time to implement a merge feature as well to cross merge templates, keeping up to date with core templates, as well as any conventions you change in one template to another.

Yup I am aware of Drush, although not really a huge fan of module based shell interaction like that.. kinda silly to have a module, IMO I would rather have an command that can do my bidding very quickly without needing to install it and provide additional overhead to Drupal.

I have tons of features in mind. The original gem was whipped up in an hour or so, needs tons of love and refactoring however I may no longer be using Drupal at all so its hard to say if I will be extending it or not.

ps. GIT > SVN

You are probably aware of Drush. if not http://drupal.org/project/drush.

It features (you might find inspiration..._)
* installing/uninstalling
* updateing modules (using update_status reports)
* pushing changes to SVN repos.
* running unit-tests
* running basic SQL commands (such as cache clear)
* running PHP code, with Drupal available (aka node_load(12))

For now, I will continue using that Drush system for my management, such as installation. But I se great opportunities for this gem to implement most of that.
But I will use this gem for module generation. great.

A few fetures that might be nice:

- template-support: generate the scaffodling-code from template, files, maybe simply erb files. That way, one can e.g. refactor the README according to internal standards.
- test-writing. Even if they are empty scaffolds with todo-placeholders. That way writing tests becomes simpler.

You might find some ideas for the test-writing in the PErl-Drupal module builder http://www.elvisblogs.org/drupal/modulator-very-quick-module-skeltons-wr...

Drupal admin <3's you (EOM)