Skip to content

Commit

Permalink
[#2618] Fanstatic flakes8
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Aug 20, 2012
1 parent db79da3 commit 7acbc16
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
25 changes: 18 additions & 7 deletions ckan/lib/fanstatic_extensions.py
Expand Up @@ -5,6 +5,7 @@

import fanstatic.core as core


class IEConditionalRenderer(object):
''' Allows for IE conditionals. '''
def __init__(self, condition, renderer, other_browsers=False):
Expand All @@ -22,14 +23,17 @@ def __call__(self, url):
self.other_browsers_start,
self.renderer(url),
self.other_browsers_end)


class InlineJSRenderer(object):
''' Allows for in-line js via fanstatic. '''
def __init__(self, script=None, renderer=None, condition=None, other_browsers=False):
def __init__(self, script=None, renderer=None, condition=None,
other_browsers=False):
self.script = script
self.other_browsers = other_browsers
self.renderer = renderer
start= ''
end= ''
start = ''
end = ''
# IE conditionals
if condition:
start = '<!--[if %s]>' % condition
Expand All @@ -48,9 +52,12 @@ def __call__(self, url):
return '%s%s%s' % (self.start,
self.renderer(url),
self.end)


def render_js(url):
return '<script type="text/javascript" src="%s"></script>' % (url,)


# Fanstatic Patch #
# FIXME add full license info & push upstream
def __init__(self, library, relpath, **kw):
Expand All @@ -69,7 +76,8 @@ def __init__(self, library, relpath, **kw):

self.library = library
fullpath = os.path.normpath(os.path.join(library.path, relpath))
if core._resource_file_existence_checking and not os.path.exists(fullpath) \
if core._resource_file_existence_checking \
and not os.path.exists(fullpath) \
and not kw.get('fake_resource', False):
raise core.UnknownResourceError("Resource file does not exist: %s" %
fullpath)
Expand Down Expand Up @@ -120,7 +128,8 @@ def __init__(self, library, relpath, **kw):
self.init_dependency_nr()

self.modes = {}
for mode_name, argument in [(core.DEBUG, debug), (core.MINIFIED, minified)]:
for mode_name, argument in [(core.DEBUG, debug),
(core.MINIFIED, minified)]:
if argument is None:
continue
elif isinstance(argument, basestring):
Expand Down Expand Up @@ -155,14 +164,13 @@ def __init__(self, library, relpath, **kw):
mode.supersedes.append(superseded_mode)
superseded_mode.rollups.append(mode)


# Register ourself with the Library.
self.library.register(self)

core.Resource.__init__ = __init__

def render(self, library_url):

def render(self, library_url):

paths = [resource.relpath for resource in self._resources]
# URL may become too long:
Expand All @@ -172,6 +180,8 @@ def render(self, library_url):
return self.renderer('%s/%s' % (library_url, relpath))

core.Bundle.render = render


def fits(self, resource):
if resource.dont_bundle:
return False
Expand All @@ -187,6 +197,7 @@ def fits(self, resource):

core.Bundle.fits = fits


def sort_resources(resources):
"""Sort resources for inclusion on web page.
Expand Down
9 changes: 5 additions & 4 deletions ckan/lib/fanstatic_resources.py
Expand Up @@ -140,7 +140,6 @@ def create_resource(path, lib_name, count, inline=False):
library = Library(name, path)
module = sys.modules[__name__]


# config options
order = []
dont_bundle = []
Expand Down Expand Up @@ -185,7 +184,6 @@ def create_resource(path, lib_name, count, inline=False):
IE_conditionals[f] = []
IE_conditionals[f].append(n)


# add dependencies for resources in groups
for group in groups:
if group in depends:
Expand Down Expand Up @@ -261,10 +259,13 @@ def create_resource(path, lib_name, count, inline=False):

base_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
'..', 'public', 'base'))

create_library('vendor', os.path.join(base_path, 'vendor'), depend_base=False)

create_library('datapreview', os.path.join(base_path, 'datapreview'), depend_base=False)
create_library('datapreview', os.path.join(base_path, 'datapreview'),
depend_base=False)

create_library('base', os.path.join(base_path, 'javascript'), depend_base=False)
create_library('base', os.path.join(base_path, 'javascript'),
depend_base=False)

create_library('css', os.path.join(base_path, 'css'), depend_base=False)

0 comments on commit 7acbc16

Please sign in to comment.