[yelp-tools] [tools/yelp-new.in] Adding yelp-new, create pages from templates



commit 0817083db1278084bbe9dd2b3852ac7834a8e37a
Author: Shaun McCance <shaunm gnome org>
Date:   Mon Dec 13 11:21:54 2010 -0500

    [tools/yelp-new.in] Adding yelp-new, create pages from templates

 Makefile.am           |    2 +-
 configure.ac          |   11 ++++++
 templates/Makefile.am |    4 ++
 templates/task.page   |   25 +++++++++++++++
 tools/Makefile.am     |    4 +-
 tools/yelp-new.in     |   83 +++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 126 insertions(+), 3 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 68603ff..4750f10 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = tools xml2po
+SUBDIRS = templates tools xml2po
 
 EXTRA_DIST = 						\
 	COPYING.GPL					\
diff --git a/configure.ac b/configure.ac
index ac36961..b1860c4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -30,10 +30,21 @@ XSL_PATH="`$PKG_CONFIG --variable=xsltdir yelp-xsl`"
 XSL_MAL_CACHE="$XSL_PATH""/mallard/cache/mal-cache.xsl"
 AC_SUBST(XSL_MAL_CACHE)
 
+YELP_TMPL_DIR=`(
+        case $prefix in
+             NONE) prefix=$ac_default_prefix ;;
+             *) ;;
+        esac
+        eval echo $(eval echo $datadir)/yelp-tools/templates/
+)`
+AC_SUBST(YELP_TMPL_DIR)
+
 AC_CONFIG_FILES([
 Makefile
+templates/Makefile
 tools/Makefile
 tools/yelp-cache
+tools/yelp-new
 xml2po/Makefile
 xml2po/xml2po.pc
 xml2po/xml2po/Makefile
diff --git a/templates/Makefile.am b/templates/Makefile.am
new file mode 100644
index 0000000..d4bbb75
--- /dev/null
+++ b/templates/Makefile.am
@@ -0,0 +1,4 @@
+tmpldir = $(datadir)/yelp-tools/templates
+tmpl_DATA = task.page
+
+EXTRA_DIST = $(tmpl_DATA)
diff --git a/templates/task.page b/templates/task.page
new file mode 100644
index 0000000..6d103ef
--- /dev/null
+++ b/templates/task.page
@@ -0,0 +1,25 @@
+<?yelp-tmpl-desc Description of how to accomplish a user task?>
+<page xmlns="http://projectmallard.org/1.0/";
+      type="topic"
+      id="@ID@">
+  <info>
+    <credit type="author copyright">
+      <name>@NAME@</name>
+      <email>@EMAIL@</email>
+      <years>@YEAR@</years>
+    </credit>
+
+    <desc></desc>
+  </info>
+
+  <title>@TITLE@</title>
+
+  <p>Short introductory text...</p>
+
+  <steps>
+    <item><p>First step...</p></item>
+    <item><p>Second step...</p></item>
+    <item><p>Third step...</p></item>
+  </steps>
+
+</page>
diff --git a/tools/Makefile.am b/tools/Makefile.am
index d0928e5..4e99986 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -1,6 +1,6 @@
 aclocaldir = $(datadir)/aclocal
 aclocal_DATA = yelp.m4
 
-bin_SCRIPTS = yelp-cache
+bin_SCRIPTS = yelp-cache yelp-new
 
-EXTRA_DIST = $(aclocal_DATA)
+EXTRA_DIST = yelp-cache.in yelp-new.in $(aclocal_DATA)
diff --git a/tools/yelp-new.in b/tools/yelp-new.in
new file mode 100755
index 0000000..6f89e85
--- /dev/null
+++ b/tools/yelp-new.in
@@ -0,0 +1,83 @@
+#!/bin/sh
+# yelp-new - Create a new Mallard or DocBook file
+# Copyright (C) 2010 Shaun McCance <shaunm gnome org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+tmpldir="@YELP_TMPL_DIR@"
+
+yelp_describe_tmpl () {
+    line="  "`basename "$1" | sed -e 's/\.'$2'$//'`
+    desc=`cat "$f" | grep '<\?yelp-tmpl-desc' | sed -e 's/<?yelp-tmpl-desc //' -e 's/?>$//'`
+    if [ "x$desc" != "x" ]; then
+        line="$line - $desc"
+    fi
+    echo "$line"
+}
+
+yelp_usage() {
+    echo "Usage: yelp-new <TEMPLATE> <ID> [TITLE]"
+    if [ -f ${tmpldir}*.page ]; then
+        echo ""
+        echo "Mallard Templates:"
+        for f in ${tmpldir}*.page; do
+            yelp_describe_tmpl "$f" "page"
+        done
+    fi
+    if [ -f ${tmpldir}*.xml ]; then
+        echo ""
+        echo "DocBook Templates:"
+        for f in ${tmpldir}*.xml; do
+            yelp_describe_tmpl "$f" "xml"
+        done
+    fi
+}
+
+if [ $# -lt 2 ]; then
+    yelp_usage
+    exit 1
+fi
+
+# Locate the template file
+if [ -f "${tmpldir}${1}.page" ]; then
+    infile="${tmpldir}${1}.page"
+    outext=".page"
+elif [ -f "${tmpldir}${1}.xml" ]; then
+    infile="${tmpldir}${1}.xml"
+    outext=".xml"
+else
+    echo "Error: No template named ${1} found"
+    exit 1
+fi
+
+# Set up some variable for substitution
+username='YOUR NAME'
+useremail='YOUR EMAIL ADDRESS'
+if type -P git &>/dev/null; then
+    username=`git config user.name`
+    useremail=`git config user.email`
+fi
+pagetitle="$3"
+if [ "x$pagetitle" = "x" ]; then
+    pagetitle="TITLE"
+fi
+
+cat "$infile" | grep -v '<\?yelp-tmpl-desc' | sed \
+    -e s/@ID@/"$2"/ \
+    -e s/@YEAR@/`date +%Y`/ \
+    -e s/@NAME@/"$username"/ \
+    -e s/@EMAIL@/"$useremail"/ \
+    -e s/@TITLE@/"$pagetitle"/ \
+    > "${2}${outext}"



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]