- Introduction
- Requirements
- Installation
- Using
Cactus Refactored
- Usage example
- Custom Plugins
- Custom Context Processors
- Special Template Tags
- Known Bugs/Errors
Cactus Refactored
is a static website generator using Python
and the Django template system.
Originally I wrote this as a refactored version of Cactus,
so credits go to Koenbok.
By now Cactus Refactored
has the following features:
- create projects from skeletons (builtin or custom)
- builtin skeleton is
default
- builtin skeleton is
- serve project via builtin development webserver with auto-reload-functionality working on Windows, Mac OS X and Linux
- (obviously) build projects
- deploy projects via SSH (public key auth and simple password auth are supported)
- deploy projects via Amazon S3
- extendable via plugins (builtin and custom). Builtin plugins are:
- Coffeescript
- Sass/Scss
- Less
- imageopti (lossless image compression for png, gif and jpg files)
- minify JS
- Haml
- custom template context processors (see context_processors/default.py for an example)
- completely configurable via YAML. See config.yml for details.
Install pip:
$ sudo easy_install pip
Download source and install package using pip (Version 1.6 Stable):
$ sudo pip install -e git+https://github.com/randomknowledge/Cactus_Refactored.git@1-6-stable#egg=Cactus
Download source and install package using pip (Development version):
$ sudo pip install -e git+https://github.com/randomknowledge/Cactus_Refactored.git#egg=Cactus
Usage: cactus [serve|create|help|build|deploy]
serve [listen_address:port]: Serve you website at local development server
create <path> [<skeleton type>|<skeleton path>]: Create a new website skeleton at the given path.
help <task>: Get help for specified task.
build: Rebuild your site from source files
deploy [target] [--build=yes|no]: deploy project to the given target.
$ cactus create www.mywebsite.com
$ cd www.mywebsite.com
$ cactus serve
<CTRL>+C
$ cactus build
To activate custom plugins inside your project, add them to a directory named plugins
inside your project directory. The plugin filename must be unique and the file must contain a class that extends CactusPluginBase. Have a look at the minifyjs plugin for a simple example.
With Context Processors you can add custom variables to the template context. Those variables can then be accessed from inside your templates.
To activate custom template processors inside your project, add them to a directory named context_processors
inside your project directory. The context-processor's filename must be unique and the file must contain a class that extends ContextProcessorBase. Have a look at the default context processor for a simple example.
Plugins also have their own template context (wich is empty by default). Just override templateContext
inside a plugin and make sure it returns a dictionary. Plugin contexts are automatically namespaces to plugins.<plugin_name>
.
Plugin context example
# file: plugins/mycustomplugin.py
class MyCustomPlugin(CactusPluginBase):
def templateContext(self, *args, **kwargs):
return {
"name": "World"
}
<html>
<body>
Hello {{ plugins.mycustomplugin.name }}!
</body>
</html>
custom template context example
# file: context_processors/customcontext.py
class MyCustomContext(ContextProcessorBase):
def context(self):
return {
"name": "World"
}
<html>
<body>
Hello {{ name }}!
</body>
</html>
Right now Cactus Refactored
has one custom template tag: render_block_from_file
.
Use it like this:
{% render_block_from_file 'another-page' 'blockname' %}
This will render the block 'blockname' from the page 'another-page' inside your template. To render a block from a page in a subfolder use the followinf syntax:
{% render_block_from_file 'sub/folder/another-page' 'blockname' %}
There is an error loading the Adobe Unit Types osascript under OSX 1.6.6+. It is used to refresh a page in the browser. Solution: Install the update from Adobe under /Library/ScriptingAdditions available here: http://helpx.adobe.com/photoshop/kb/unit-type-conversion-error-applescript.html
Thanks to @remeiberlin for reporting this!