changeset 774:2bb3c1a04e98

prepare: Add ablity to run an editor program after creating the page file.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 03 Jul 2016 16:44:18 -0700
parents 87f1e79d3fbe
children ba0a6bd5e913
files docs/docs/03_content/01_creating-pages.md docs/docs/99_reference/01_website-configuration.md piecrust/commands/builtin/scaffolding.py
diffstat 3 files changed, 50 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/docs/docs/03_content/01_creating-pages.md	Sun Jul 03 15:56:35 2016 -0700
+++ b/docs/docs/03_content/01_creating-pages.md	Sun Jul 03 16:44:18 2016 -0700
@@ -7,8 +7,16 @@
 you're using, but we can go over how it works for the sources involved in the
 [default content model][dcm].
 
-We will also go over the `chef prepare` command, which semi-automates the
-process of creating pages.
+We will also mention the `chef prepare` command, which semi-automates the
+process of creating pages by letting you type a lot less than what would be
+otherwise needed to create the correctly named text file in the correct folder.
+Generally speaking, you should be able to run `chef prepare -h` and figure it
+out on your own.
+
+> In addition to creating the text file, you can make PieCrust open your
+> favorite text editor too, with the `prepare/editor` site configuration
+> setting. For more information, see the [site configuration
+> reference][confref].
 
 
 ## Overview
@@ -75,4 +83,5 @@
 [src]: {{docurl('content-model/sources')}}
 [dcm]: {{docurl('content-model/default-model')}}
 [srcref]: {{docurl('reference/sources')}}
+[confref]: {{docurl('reference/website-configuration')}}
 
--- a/docs/docs/99_reference/01_website-configuration.md	Sun Jul 03 15:56:35 2016 -0700
+++ b/docs/docs/99_reference/01_website-configuration.md	Sun Jul 03 16:44:18 2016 -0700
@@ -122,6 +122,25 @@
 [cm]: {{docurl('content-model')}}
 
 
+## Preparation
+
+The following settings are under the `prepare` section, and are used by the
+`chef/prepare` command.
+
+* `editor`: The path to an editor executable to run after creating a page with
+  the `chef prepare` command. By default, PieCrust will pass the path of the new
+  page as an argument to the executable. If you want more control over the
+  generated command line, use the `%path%` token in the value -- it will be
+  replaced with the path of the new page and nothing else will be passed.
+
+* `editor_type` (`exe`): The type of executable specified in the
+  `prepare/editor` setting. Values can be:
+  
+      * `exe`: the command is run as an executable. This is the default.
+      * `shell`: the command is run through the shell, in case you need
+        environment variable expansion and other shell features.
+
+
 ## Baker
 
 The following settings are under the `baker` section, and are used by the `chef
@@ -137,8 +156,8 @@
   asset pipeline. Patterns are either glob-like (_i.e._ using wildcards) or
   regex-like (when the pattern starts and ends with a slash).
 
-  Some patterns will always be added to the list: `_cache`, `_counter`,
-  `theme_info.yml`, `.DS_Store`, `Thumbs.db`, `.git*`, `.hg*`, and `.svn`.
+    Some patterns will always be added to the list: `_cache`, `_counter`,
+    `theme_info.yml`, `.DS_Store`, `Thumbs.db`, `.git*`, `.hg*`, and `.svn`.
 
 * `is_baking` (`false`): This setting is read-only, and will be set to true
   while baking the website (_i.e._ while the `chef bake` command is running).
--- a/piecrust/commands/builtin/scaffolding.py	Sun Jul 03 15:56:35 2016 -0700
+++ b/piecrust/commands/builtin/scaffolding.py	Sun Jul 03 16:44:18 2016 -0700
@@ -114,6 +114,24 @@
         with open(path, 'w') as f:
             f.write(tpl_text)
 
+        editor = ctx.app.config.get('prepare/editor')
+        editor_type = ctx.app.config.get('prepare/editor_type', 'exe')
+        if editor:
+            import shlex
+            shell = False
+            args = '%s "%s"' % (editor, path)
+            if '%path%' in editor:
+                args = editor.replace('%path%', path)
+
+            if editor_type.lower() == 'shell':
+                shell = True
+            else:
+                args = shlex.split(args)
+
+            import subprocess
+            logger.info("Running: %s" % args)
+            subprocess.Popen(args, shell=shell)
+
 
 class DefaultPrepareTemplatesCommandExtension(ChefCommandExtension):
     """ Provides the default scaffolding templates to the `prepare`