Skip to content

Instantly share code, notes, and snippets.

@matiskay
Created July 13, 2011 22:19
Show Gist options
  • Save matiskay/1081465 to your computer and use it in GitHub Desktop.
Save matiskay/1081465 to your computer and use it in GitHub Desktop.
Create a scaffold to develop a Drupal Module
MODULENAME=$1
MACHINENAME=$2
DESCRIPTION=$3
if [[ -d $MODULENAME ]]; then
printf "There is a module with that name\n"
exit 0
fi
if [[ ! -n $MACHINENAME ]]; then
printf "You Need to provide a valid Machine Name\n"
exit 0
fi
if [[ ! -n $DESCRIPTION ]]; then
DESCRIPTION=$MODULENAME
fi
mkdir $MACHINENAME
cd $MACHINENAME
{
printf "name = %s\n" "$MODULENAME"
printf "description = %s\n" "$DESCRIPTION"
printf "core = 7.x\n"
} > $MACHINENAME.info
touch $MACHINENAME.module
{
echo '<?php'
echo ''
echo '/*'
echo ' * Implementation of hook_init()'
echo " */"
echo "function @MACHINENAME_init() {"
echo ' $path = drupal_get_path("module", "@MACHINENAME");'
echo ' drupal_add_css($path . "/css/@MACHINENAME.css");'
echo ' drupal_add_js($path . "/js/@MACHINENAME.js");'
echo "}"
echo ""
echo '/*'
echo ' * Implementation of hook_menu()'
echo " */"
echo "function @MACHINENAME_menu() {"
echo ' $items["@MACHINENAME/prototype"] = array('
echo ' "title" => "",'
echo " 'page callback' => '@MACHINENAME_prototype_page_render',"
echo " 'access arguments' => array('access content'),"
echo " 'type' => MENU_CALLBACK,"
echo " );"
echo ' return $items;'
echo "}"
echo ""
echo '/*'
echo ' * Implementation of hook_block_info()'
echo " */"
echo "function @MACHINENAME_block_info() {"
echo ' $blocks["@MACHINENAME_prototype"]["info"] = t("@MACHINENAME prototype");'
echo ' return $blocks;'
echo "}"
echo ""
echo "/*"
echo " * Implementation of hook_block_view()"
echo " */"
echo 'function @MACHINENAME_block_view($delta = "") {'
echo ' $block = array();'
echo ''
echo ' switch ($delta) {'
echo ' case "@MACHINENAME_prototype":'
echo ' $block["subject"] = t("@MACHINENAME prototype");'
echo ' $block["content"] = @MACHINENAME_prototype_block_render();'
echo ' break;'
echo ' }'
echo ' return $block;'
echo '}'
echo ""
echo 'function @MACHINENAME_prototype_block_render() {'
echo ' $output = "";'
echo ' return $output;'
echo '}'
echo ''
echo 'function @MACHINENAME_prototype_page_render() {'
echo ' $output = "";'
echo ' return $output;'
echo '}'
} > $MACHINENAME.module.tmp
(sed s/@MACHINENAME/$MACHINENAME/g $MACHINENAME.module.tmp | sed s/\"/\'/g ) > $MACHINENAME.module
rm $MACHINENAME.module.tmp
mkdir js
mkdir css
cd js
{
echo "Drupal.behaviors.$MACHINENAME = {"
echo ' attach: function (context, settings) {'
echo ' }'
echo '};'
} > $MACHINENAME.js
@matiskay
Copy link
Author

I have been working on this code to scaffold a basic structure to start with a drupal module.
Bug reports are welcome.
Sorry I need to add comments and refactor many things, but the code is out there to play with it or just get ideas from it.

It works like this

bash drumod.sh NAME MACHINENAME [ DESCRIPTION]

If your description contains spaces, you have use double quotes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment