Skip to content

Commit

Permalink
Merge pull request #4422 from OriHoch/fanstatic-support-supersede
Browse files Browse the repository at this point in the history
support resource overrides in resources.config using fanstatic supersedes feature
  • Loading branch information
smotornyuk committed Sep 3, 2018
2 parents 90daf5c + 6f15cfb commit 49d348a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ckan/config/middleware/flask_app.py
Expand Up @@ -206,13 +206,16 @@ def hello_world_post():
app = plugin.make_middleware(app, config)

# Fanstatic
fanstatic_enable_rollup = asbool(app_conf.get('fanstatic_enable_rollup',
False))
if debug:
fanstatic_config = {
'versioning': True,
'recompute_hashes': True,
'minified': False,
'bottom': True,
'bundle': False,
'rollup': fanstatic_enable_rollup,
}
else:
fanstatic_config = {
Expand All @@ -221,6 +224,7 @@ def hello_world_post():
'minified': True,
'bottom': True,
'bundle': True,
'rollup': fanstatic_enable_rollup,
}
root_path = config.get('ckan.root_path', None)
if root_path:
Expand Down
4 changes: 4 additions & 0 deletions ckan/config/middleware/pylons_app.py
Expand Up @@ -75,13 +75,16 @@ def make_pylons_stack(conf, full_stack=True, static_files=True,
cleanup_pylons_response_string)

# Fanstatic
fanstatic_enable_rollup = asbool(app_conf.get('fanstatic_enable_rollup',
False))
if asbool(config.get('debug', False)):
fanstatic_config = {
'versioning': True,
'recompute_hashes': True,
'minified': False,
'bottom': True,
'bundle': False,
'rollup': fanstatic_enable_rollup,
}
else:
fanstatic_config = {
Expand All @@ -90,6 +93,7 @@ def make_pylons_stack(conf, full_stack=True, static_files=True,
'minified': True,
'bottom': True,
'bundle': True,
'rollup': fanstatic_enable_rollup,
}
root_path = config.get('ckan.root_path', None)
if root_path:
Expand Down
15 changes: 13 additions & 2 deletions ckan/lib/fanstatic_resources.py
Expand Up @@ -38,7 +38,7 @@ def get_resource(lib_name, resource_name):
res = getattr(module, '%s' % resource_name)
return res

def create_resource(path, lib_name, count, inline=False):
def create_resource(path, lib_name, count, inline=False, supersedes=None):
''' create the fanstatic Resource '''
renderer = None
kw = {}
Expand Down Expand Up @@ -83,6 +83,12 @@ def create_resource(path, lib_name, count, inline=False):
script=inline,
renderer=renderer,
other_browsers=other_browsers)
if supersedes:
superseded_library, superseded_resource_path = supersedes
for _library in get_library_registry().values():
if _library.name == superseded_library:
kw['supersedes'] = [_library.known_resources[superseded_resource_path]]
break
resource = Resource(library, path, **kw)

# Add our customised ordering
Expand Down Expand Up @@ -116,6 +122,7 @@ def create_resource(path, lib_name, count, inline=False):
IE_conditionals = {}
custom_render_order = {}
inline_scripts = {}
supersedes = {}

# parse the resource.config file if it exists
config_path = os.path.join(resource_path, 'resource.config')
Expand Down Expand Up @@ -150,6 +157,9 @@ def create_resource(path, lib_name, count, inline=False):
if f not in IE_conditionals:
IE_conditionals[f] = []
IE_conditionals[f].append(n)
if config.has_section('supersedes'):
items = config.items('supersedes')
supersedes = dict((n, v.split('/', 1)) for (n, v) in items)

# add dependencies for resources in groups
for group in groups:
Expand Down Expand Up @@ -210,7 +220,8 @@ def create_resource(path, lib_name, count, inline=False):
inline = inline_scripts[resource_name].strip()
else:
inline = None
create_resource(resource_name, name, count, inline=inline)
create_resource(resource_name, name, count, inline=inline,
supersedes=supersedes.get(resource_name))
count += 1

# add groups
Expand Down
11 changes: 11 additions & 0 deletions doc/contributing/frontend/resources.rst
Expand Up @@ -111,6 +111,11 @@ the same as for the .ini config file.
bootstrap/js/bootstrap-button.js
font-awesome/css/font-awesome-ie7.css

[supersedes]

select2-upgraded.js = vendor/select2/select2.js



[main]
~~~~~~
Expand Down Expand Up @@ -187,3 +192,9 @@ used.

Groups can be referred to in many places in the
resource.config file eg. [depends]

[supersedes]
~~~~~~~~~~~~

Allows to override static files from other resources. Has to be enabled at the
app config by setting fanstatic_enable_rollup = yes

0 comments on commit 49d348a

Please sign in to comment.