author: Sylvain Viollon
date: Mon Aug 19 15:11:12 2013 +0200
revision: 34:7f61513f771d in silva.fanstatic
branch:
details: https://hg.infrae.com/silva.fanstatic?cmd=changeset;node=7f61513f771d
modified: src/silva/fanstatic/__init__.py src/silva/fanstatic/extending.py src/silva/fanstatic/injector.py
added:
removed:
log: Hack a way to get an Inclusion with the proper settings in
fanstatic. The settings are not store and used when creating a new
Inclusion, so you need to do it yourself.
diffstat:
src/silva/fanstatic/__init__.py | 9 ++++++---
src/silva/fanstatic/extending.py | 35 +++++++++++++++++++++++++++++++++++
src/silva/fanstatic/injector.py | 8 +++++++-
3 files changed, 48 insertions(+), 4 deletions(-)
diffs (101 lines):
diff -r 198dabd5beb1 -r 7f61513f771d src/silva/fanstatic/__init__.py
--- a/src/silva/fanstatic/__init__.py Thu Aug 01 11:02:11 2013 +0200
+++ b/src/silva/fanstatic/__init__.py Mon Aug 19 15:11:12 2013 +0200
@@ -2,11 +2,14 @@
# Copyright (c) 2011-2013 Infrae. All rights reserved.
# See also LICENSE.txt
-from silva.fanstatic.extending import need
+from silva.fanstatic.extending import need, get_inclusion
from silva.fanstatic.resources import ExternalResource, Snippet
-from fanstatic.core import Group
+from fanstatic import Group
+from fanstatic import get_needed
-__all__ = ['need', 'ExternalResource', 'Snippet', 'Group']
+__all__ = [
+ 'need', 'get_inclusion', 'get_needed',
+ 'ExternalResource', 'Snippet', 'Group']
# Patch fanstatic with missing API calls during testing
diff -r 198dabd5beb1 -r 7f61513f771d src/silva/fanstatic/extending.py
--- a/src/silva/fanstatic/extending.py Thu Aug 01 11:02:11 2013 +0200
+++ b/src/silva/fanstatic/extending.py Mon Aug 19 15:11:12 2013 +0200
@@ -3,6 +3,8 @@
# See also LICENSE.txt
import logging
+import Globals
+import fanstatic
from zope.interface.interfaces import IInterface
from zope.testing.cleanup import addCleanUp
@@ -10,8 +12,41 @@
logger = logging.getLogger('silva.fanstatic')
INTERFACES_RESOURCES = {}
+FANSTATIC_SETTINGS = {}
addCleanUp(INTERFACES_RESOURCES.clear)
+addCleanUp(FANSTATIC_SETTINGS.clear)
+
+def _set_settings(settings):
+ FANSTATIC_SETTINGS.update(settings)
+ mode = None
+ if 'debug' in FANSTATIC_SETTINGS:
+ mode = fanstatic.DEBUG
+ del FANSTATIC_SETTINGS['debug']
+ if 'minified' in FANSTATIC_SETTINGS:
+ if mode is None:
+ mode = fanstatic.MINIFIED
+ del FANSTATIC_SETTINGS['minified']
+ FANSTATIC_SETTINGS['mode'] = mode
+
+def _get_settings():
+ if FANSTATIC_SETTINGS:
+ return FANSTATIC_SETTINGS.copy()
+ if Globals.DevelopmentMode:
+ return {'mode': fanstatic.DEBUG}
+ return {'mode': fanstatic.MINIFIED,
+ 'bundle': True}
+
+def get_inclusion(needed, resources=None):
+ """Get a fanstatic ``Inclusion``. This can be used to get
+ resources URL.
+ """
+ settings = _get_settings()
+ return fanstatic.Inclusion(
+ needed,
+ resources=resources,
+ mode=settings.get('mode', None),
+ bundle=settings.get('bundle', False))
def need(resource):
diff -r 198dabd5beb1 -r 7f61513f771d src/silva/fanstatic/injector.py
--- a/src/silva/fanstatic/injector.py Thu Aug 01 11:02:11 2013 +0200
+++ b/src/silva/fanstatic/injector.py Mon Aug 19 15:11:12 2013 +0200
@@ -1,6 +1,7 @@
from fanstatic import compat
from fanstatic.injector import InjectorPlugin
+from silva.fanstatic.extending import _set_settings
import re
@@ -334,8 +335,13 @@
name = 'rules'
def __init__(self, options):
+ _set_settings(options)
super(RuleBasedInjector, self).__init__(options)
- self.default, self.rules = parse_rules(options.pop('rules'))
+ self.default, self.rules = parse_rules(
+ options.pop('rules',
+ """otherwise
+insert before </head>
+"""))
def __call__(self, html, needed, request, response=None):
rules = []
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.