Skip to content

Commit

Permalink
Adding plugin handlers for assets and body blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Smári McCarthy committed Jan 7, 2014
1 parent f17c010 commit 0bdf121
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 3 additions & 1 deletion mailpile/jinjaextensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from mailpile.commands import Action
from mailpile.util import *
from mailpile.plugins import get_activities, get_selection_actions, get_display_actions, get_display_modes
from mailpile.plugins import get_activities, get_selection_actions, get_display_actions, get_display_modes, get_assets, get_body_blocks


class MailpileCommand(Extension):
Expand Down Expand Up @@ -49,6 +49,8 @@ def __init__(self, environment):
environment.globals['get_selection_actions'] = get_selection_actions
environment.globals['get_display_actions'] = get_display_actions
environment.globals['get_display_modes'] = get_display_modes
environment.globals['get_assets'] = get_assets
environment.globals['get_body_blocks'] = get_body_blocks


def _command(self, command, *args, **kwargs):
Expand Down
23 changes: 22 additions & 1 deletion mailpile/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ def register_commands(*args):
DISPLAY_MODES = {}
DISPLAY_ACTIONS = {}
SELECTION_ACTIONS = {}
ASSETS = {"javascript": [], "stylesheet": []}
BODY_BLOCKS = {}
ACTIVITIES = []

def register_uiclass(uiclass):
Expand All @@ -250,6 +252,7 @@ def register_uiclass(uiclass):
DISPLAY_ACTIONS[uiclass] = []
DISPLAY_MODES[uiclass] = []
SELECTION_ACTIONS[uiclass] = []
BODY_BLOCKS[uiclass] = []

def register_display_mode(uiclass, name, jsaction, text, url="#", icon=None):
assert(uiclass in DISPLAY_MODES)
Expand Down Expand Up @@ -294,6 +297,24 @@ def register_activity(name, jsaction, icon, url="#"):
"text": text
})

def register_asset(assettype, name):
assert(assettype in ASSETS)
if name not in ASSETS[assettype]:
ASSETS[assettype].append(name)

def get_assets(assettype):
assert(assettype in ASSETS)
return ASSETS[assettype]

def register_body_block(uiclass, name):
assert(uiclass in UICLASSES)
if name not in BODY_BLOCKS[uiclass]:
BODY_BLOCKS[uiclass].append(name)

def get_body_blocks(uiclass):
assert(uiclass in UICLASSES)
return BODY_BLOCKS[uiclass]

def get_activities():
return ACTIVITIES

Expand All @@ -306,5 +327,5 @@ def get_display_actions(uiclass):
def get_display_modes(uiclass):
return DISPLAY_MODES[uiclass]

for cl in ["search", "thread", "contact", "tag"]:
for cl in ["base", "search", "thread", "contact", "tag"]:
register_uiclass(cl)
4 changes: 4 additions & 0 deletions static/default/html/layouts/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
---------------------------------------------------------------------------- -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="/static/css/default.css" />
{% for asset in get_assets("stylesheet") %}<link rel="stylesheet" href="{{asset}}"/>
{% endfor %}
<!--[if lt IE 9]>
<script src="/static/js/html5.js"></script>
<![endif]-->
Expand Down Expand Up @@ -187,6 +189,8 @@ <h3>DEBUG</h3>
<script type="text/javascript" src="/static/js/app/contacts.js"></script>
<script type="text/javascript" src="/static/js/app/tags.js"></script>
<script type="text/javascript" src="/static/js/app/settings.js"></script>
{% for asset in get_assets("javascript") %}<link rel="stylesheet" href="{{asset}}"/>
{% endfor %}
<script type="text/javascript">
mailpile.instance = {
"command": "{{ command }}",
Expand Down

0 comments on commit 0bdf121

Please sign in to comment.