pre and post compile (assets) hooks #104

posativ opened this Issue Jan 26, 2013 · 1 comment

1 participant


@chripo suggested a new feature that allows users to run a shell script/python function for each file in the assets. The original idea came from a gallery hook, that generates thumbnails on-the-fly without any interaction of the user. So, ideally you would define a (regex) pattern for your gallery images or whatever you like and before (or after) Acrylamid compiles. The pattern matches the asset and does something with it (in this example, running convert -resize ...).

The exact syntax of a hook is not yet discussed, but it should be easy to write something like *.jpg => mkthumbnails or /js/ =>


New ideas from a short brain storming:

  • two possible pattern variants: shell globbing or regular expressions. Shell globbing is very intuitive and looks pretty cool: shots/**/*.jpg to apply the hook on all jpegs inside shots/ folder, but neither python's glob nor python-glob2 can handle this for all common usage cases e.g. *(.jpg|.png). RE: ugly, but easy to implement, hence the initial version must be configured using regular expressions

  • '.+\.jpg': (mkthumb, lambda p: join([dirname(p), 'thumbs/', basename(p))])) as configuration syntax. The first function runs the actual compution, but before doing this, Acrylamid evaluates the path translation function (the latter) to check whether the computation is necessary at all.

  • the path translation is optional, so the hook-configuration can be broken down to '.+\.html': html.minify.

  • not a high priority but: Acrylamid might detect a change in the function and can force a re-generation of the hooks. This is only possible when you define your function in separate module and import the function from there.

@posativ posativ added a commit that referenced this issue Feb 11, 2013
@posativ Merge branch 'hooks', part of #104 bd9519d
@posativ posativ added a commit that closed this issue Jun 25, 2013
@posativ Merge branch 'feature/post-hook', closes #104
(see section Pre and Post Hooks in docs/hooks.rst)
@posativ posativ closed this in 0332ee3 Jun 25, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment