Permalink
Browse files

added: new command -> volt add

  • Loading branch information...
1 parent 90155e3 commit ba20becd25ccb15b5b4aea45af3d647751474e61 @bow committed Apr 11, 2012
Showing with 89 additions and 9 deletions.
  1. +10 −6 README.rst
  2. +10 −2 extras/volt
  3. +25 −1 volt/main.py
  4. +31 −0 volt/templates/engine.py
  5. +9 −0 volt/templates/plugin.py
  6. +4 −0 volt/templates/widgets.py
View
@@ -124,19 +124,23 @@ Here's a quick summary of the currently available commands:
The ``voltconf.py`` file created by this command currently contains almost all
the default settings. You can safely edit or remove them.
+* ``volt demo``: Starts the demo, must be run inside an empty directory.
+
* ``volt gen``: Generates the website into a ``site`` folder in your current
- project directory. Can be run from anywhere inside a Volt project directory.
+ project directory.
* ``volt serve``: Generates the website and Starts the server pointing to the
- ``site`` directory. Can be run from anywhere inside a Volt project directory.
+ ``site`` directory.
-* ``volt demo``: Starts the demo, must be run inside an empty directory.
+* ``volt add``: Adds a template for writing your custom engine, plugin, or
+ widget. Custom engines and plugins are stored respectively inside the
+ ``engines`` and ``plugins`` directory in the root Volt project directory.
+ Widgets are stored inside ``widgets.py`` in the same directory.
* ``volt version``: Shows the current Volt version.
-Use your own engines by writing them in an ``engines`` directory inside your
-Volt project directory. Plugins follow the same rule: ``plugins`` inside your
-Volt project directory.
+All of the commands except for ``init`` and ``demo`` can be run from anywhere
+inside a Volt project directory.
The docs are, unfortunately, minimum at the moment. For now, the source is the
primary documentation.
View
@@ -9,11 +9,19 @@ _volt()
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
- opts="help init gen serve switch demo version"
+ opts="help add init gen serve demo version"
case "${prev}" in
help)
- COMPREPLY=( $(compgen -W "init gen serve switch demo version" -- ${cur}) )
+ COMPREPLY=( $(compgen -W "add init gen serve demo version" -- ${cur}) )
+ ;;
+ add)
+ case "${cur}" in
+ *)
+ local subopts="engine plugin widget"
+ COMPREPLY=( $(compgen -W "${subopts}" -- ${cur}) )
+ ;;
+ esac
;;
gen)
case "${cur}" in
View
@@ -75,6 +75,11 @@ def build_parsers(self):
parser = ArgParser()
subparsers = parser.add_subparsers(title='subcommands')
+ # parser for add
+ add_parser = subparsers.add_parser('add',
+ help="adds template for custom engine, plugin, or widget")
+ add_parser.add_argument('template', type=str, choices=['engine', 'plugin', 'widget'])
+
# parser for init
init_parser = subparsers.add_parser('init',
help="starts a bare Volt project")
@@ -107,6 +112,25 @@ def build_parsers(self):
return parser
+ def run_add(self):
+ """Adds template for engine, plugin, or widget."""
+ template = CONFIG.CMD.template
+ template_source = os.path.join(os.path.dirname(__file__), 'templates')
+
+ if template == 'widget':
+ if not os.path.exists(CONFIG.VOLT.USER_WIDGET):
+ shutil.copy2(os.path.join(template_source, 'widgets.py'), os.curdir)
+ else:
+ template_dir = os.path.join(os.getcwd(), template + 's')
+ template_file = template + '.py'
+
+ if not os.path.exists(template_dir):
+ os.mkdir(template_dir)
+
+ if not os.path.exists(os.path.join(template_dir, template_file)):
+ shutil.copy2(os.path.join(template_source, template_file), \
+ template_dir)
+
def run_init(self, cmd_name='init'):
"""Starts a new Volt project.
@@ -149,7 +173,6 @@ def run_demo(self):
def run_gen(self):
"""Generates the static site."""
- os.chdir(CONFIG.VOLT.ROOT_DIR)
generator.run()
def run_serve(self):
@@ -175,6 +198,7 @@ def main(cli_arglist=None):
# only build logger if we're not starting a new project
if CONFIG.CMD.name not in ['demo', 'init']:
session.build_logger()
+ os.chdir(CONFIG.VOLT.ROOT_DIR)
logger = logging.getLogger('main')
logger.debug("running: %s" % CONFIG.CMD.name)
View
@@ -0,0 +1,31 @@
+# Volt custom engine
+
+from volt.config import Config
+from volt.utils import cachedproperty
+from volt.engine.core import Engine
+
+
+class MyEngine(Engine):
+
+ # Default engine configurations
+ DEFAULTS = Config(
+ # URL for all engine content relative to root site URL
+ URL = '',
+
+ # Permalink pattern for engine units relative to engine URL
+ PERMALINK = '',
+
+ # Directory path for storing engine content
+ # relative to the default Volt content directory
+ CONTENT_DIR = '',
+ )
+
+ # Config instance name in voltconf.py
+ USER_CONF_ENTRY = ''
+
+ @cachedproperty
+ def units(self):
+ pass
+
+ def dispatch(self):
+ pass
View
@@ -0,0 +1,9 @@
+# Volt custom plugin
+
+from volt.plugin.core import Plugin
+
+
+class MyPlugin(Plugin):
+
+ def run(self, units):
+ pass
@@ -0,0 +1,4 @@
+# Volt custom widgets
+
+def my_widget(units):
+ pass

0 comments on commit ba20bec

Please sign in to comment.