Not Logged In

django-hooks 0.1.0

A plugin system for django apps. It provides ways for an app to inject
code into another app. So you can integrate existing apps into your main
app. I call this existing app an *App-Hook*.

There are 3 kinds of hooks:

- TemplateHook: the most useful one, App-Hooks will be able to inject
their own code into your templates.
- ViewHook: App-Hooks will be able to add Forms in your views.
- SignalHook: This is the same as django signals except that
*signal-hooks* don’t need to be pre-created. You can connect or emit
a signal by its name/id.

**Tested** in Django 1.4, 1.5, 1.6; Python 2.7, 3.4

Configuration
-------------

1. Add ``hooks`` to your *INSTALLED\_APPS*. This is required only if you
are going to use the templatetags.

Learn by example
----------------

TemplateHook
~~~~~~~~~~~~

Adding a hook in your main-app template:

.. code:: html

# main_app/templates/_base.html

{% load hooks_tags %}

<html>
<head>
<meta charset="utf-8">
#...

{% hook 'within_head' %}

#...
</head>
</html>

Here we are adding a *hook point* called ``within_head`` where App-Hooks
will be able to inject their code.

def a_more_complex_hook(context, *args, **kwargs):
# If you are doing this a lot, make sure to keep your templates in memory (google: django.template.loaders.cached.Loader)
return render_to_string('templates/app_hook/head_resources.html', context_instance=context)

**Note** SignalHook uses django signals under the hook, so you can
do pretty much the same.

Miscellaneous
~~~~~~~~~~~~~

As you saw earlier *TemplateHooks* don’t need to be pre-created, passing
``within_head`` to hook will call any callback previously registered to
that name/id. But, what if you want to have static/pre-created
template-hooks… you can! but it requires you to create an extra template
tag. Let’s create a static template-hook:

You may also report any bug or propose new features in the `issues
tracker`_

Copyright / License
-------------------

Copyright 2014 `Esteban Castro Borsani`_.

Licensed under the `MIT License`_.

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.