diff --git a/ckan/config/middleware/flask_app.py b/ckan/config/middleware/flask_app.py index 8a6d6184685..4293d82b378 100644 --- a/ckan/config/middleware/flask_app.py +++ b/ckan/config/middleware/flask_app.py @@ -206,6 +206,8 @@ 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, @@ -213,6 +215,7 @@ def hello_world_post(): 'minified': False, 'bottom': True, 'bundle': False, + 'rollup': fanstatic_enable_rollup, } else: fanstatic_config = { @@ -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: diff --git a/ckan/config/middleware/pylons_app.py b/ckan/config/middleware/pylons_app.py index 2d352324101..73b714509a7 100644 --- a/ckan/config/middleware/pylons_app.py +++ b/ckan/config/middleware/pylons_app.py @@ -75,6 +75,8 @@ 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, @@ -82,6 +84,7 @@ def make_pylons_stack(conf, full_stack=True, static_files=True, 'minified': False, 'bottom': True, 'bundle': False, + 'rollup': fanstatic_enable_rollup, } else: fanstatic_config = { @@ -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: diff --git a/ckan/lib/fanstatic_resources.py b/ckan/lib/fanstatic_resources.py index aa010be9495..a0d4ad9e7a6 100644 --- a/ckan/lib/fanstatic_resources.py +++ b/ckan/lib/fanstatic_resources.py @@ -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 = {} @@ -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 @@ -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') @@ -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: @@ -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 diff --git a/doc/contributing/frontend/resources.rst b/doc/contributing/frontend/resources.rst index 5abff1b4626..eb93fad8ef1 100644 --- a/doc/contributing/frontend/resources.rst +++ b/doc/contributing/frontend/resources.rst @@ -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] ~~~~~~ @@ -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