Permalink
Browse files

Generator for simple canhaz generator. Now you canhaz generator.simpl…

…e to write your own generator
  • Loading branch information...
1 parent 80fea4f commit f0607701764a71ea81eeb3605fccf7952ae3dbcf @briancavalier briancavalier committed Apr 6, 2011
View
@@ -198,7 +198,7 @@ MODULE=`basename "$MODULE_PATH"`
MODULE_BASE=`dirname "$MODULE_PATH"`
# Export vars that should be available to templates
-export CANHAZ_DIR ME VERSION PHP MY_DIR MY_BIN_DIR GEN_BASE_DIR MODULE MODULE_BASE BASE_DIR TEST_DIR TEMPLATE_DIR FORCE COPYRIGHT
+export CANHAZ_DIR ME VERSION PHP MY_DIR MY_BIN_DIR GEN_BASE_DIR MODULE MODULE_BASE BASE_DIR TEMPLATE_DIR FORCE COPYRIGHT
# Run the general setup, if it exists
load "setup"
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+#
+# This is a simple generator example that will generate
+# files from templates in TEMPLATE_DIR
+#
+
+fail_if_exists "$MODULE_BASE/$MODULE.$1"
+
+log_file "$MODULE_BASE/$MODULE.$1"
+template "$TEMPLATE_DIR/template.$1" > "$MODULE.$1"
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+# A list of things to generate
+# Your generate script will be called once for each thing listed
+# here, passing the thing as the command line arg.
+#
+# For example, say you are creating a widget generator, and
+# your generator can generate a Javascript widget stub and a css
+# stub for the widget, you might list:
+# GENERATORS="js css"
+#
+# When you run canhaz my.widget, your generate script will be invoked
+# twice:
+# 1. generate js
+# 2. generate css
+GENERATORS="txt"
+
+# Dir containing templates
+TEMPLATE_DIR="$MY_DIR/templates"
+
+DIR="$BASE_DIR/$MODULE_BASE"
+
+# Create output dir
+mkdir -p "$DIR"
+pushd "$DIR" >> /dev/null
+
+export TEMPLATE_DIR
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+# Do any generator-specific teardown here.
+# This will be run after your generate script has been called.
+
+popd >> /dev/null
+
+cat "$MODULE_BASE/$MODULE.txt"
@@ -0,0 +1,9 @@
+Congratulations, you've created your very own canhaz generator,
+and it actually works!
+
+MODULE: ${MODULE}
+MODULE_BASE: ${MODULE_BASE}
+MY_DIR: ${MY_DIR}
+TEMPLATE_DIR: ${TEMPLATE_DIR}
+CANHAZ_DIR: ${CANHAZ_DIR}
+VERSION: ${VERSION}
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+fail_if_exists "$MODULE_BASE/$MODULE"
+
+log_dir "$MODULE_BASE/$MODULE"
+
+mkdir -p "$MODULE_BASE"
+cp -fR "$MY_DIR/files" "$MODULE_BASE/$MODULE"

0 comments on commit f060770

Please sign in to comment.