Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support URLs that don't start with /static/ #177

Closed
benjmin-r opened this issue Jul 21, 2015 · 7 comments
Closed

Support URLs that don't start with /static/ #177

benjmin-r opened this issue Jul 21, 2015 · 7 comments

Comments

@benjmin-r
Copy link

In template_tags.py#L19 a TODO says exactly that.

I'd like to tackle this one, as we need it in one of our projects.

Do you have any hints on how to do this? Introduce a config setting, and if present use that as a base url for static assets? Did you have any concrete plans/ideas on how to implement this?

I wonder if it would be a good idea to reuse django's STATIC_ROOT related capabilities (or rather the collectstatic contrib to be exact) for that.

But this would somehow contradict the item on the roadmap (see #117) which states/asks, that other template engines than Django's would be a nice feature.

@benjmin-r
Copy link
Author

Hi @krallin,

Do you have an opinion on what approach you'd prefer? Should I hack the template tag or implement it as a new tag/plugin? Or should I just make a concrete implementation which you then can review?

Of course I could just hack something for our use case, but I imagine a solution for this could be useful for more people and I'd like to contribute it back to cactus and want to ensure I at last start working in the "right" direction.

Thanks a lot for your time & consideration!

Cheers!

@krallin
Copy link
Collaborator

krallin commented Jul 23, 2015

Hey @nureineide,

I'm sorry, I haven't really had time to look at this (but I'll try and do so this weekend). I wish I could give you a quick and straightforward answer but the truth is I don't really recall whether I knew how to address the problem when I wrote the TODO.

Generally speaking regarding editing existing functionality vs. building something new:

  • Building something new or a plugin if you cannot preserve backwards compatibility otherwise.
  • Building something new or a plugin is good if you want to make a feature optional (e.g. Page context plugin #141 which I desperately need to review).
  • For all other cases, editing existing functionality is fine.

Hope this helps! I'll try and follow up as I can.

Cheers,

@benjmin-r
Copy link
Author

Yes, this helps & is enough for now. I can take a stab from here and publish what I did. You then can decide if you'd like to integrate it at some point.

Thanks a lot for your quick response!

@hayabhay
Copy link

hayabhay commented Aug 7, 2015

I found a hacky way to do this. Simply include a static-url in the config.json and append this value while returning in the get_url_for_static function. Same can be extended for root-url if the pages aren't hosted in TLD.

@eMerzh
Copy link

eMerzh commented Jul 31, 2016

is there any news on this ? because it's really a blocker for running it in gitlab or other sites like this

@benjmin-r
Copy link
Author

We went the route of implementing a simple plugin, that reads an optional config.json file and given that file contains a key named static_base_url sets the template variable STATIC_URL to the respective value.
This also allowed us to maintain most of our cactus v2 templates unchanged.

The following is the plugin code, which you are free to use as is.

import os
from cactus import config

INFO = {
    'name': 'CUSTOM_STATIC_URL',
    'description': 'Set STATIC_URL to value from config.json in project dir'
}

STATIC_URL_KEY = 'static_base_url'
conf = config.Config('config.json')

def preBuildPage(site, path, context, data):
    if conf.get(STATIC_URL_KEY):
        context.update({ 'STATIC_URL': conf.get(STATIC_URL_KEY) })
    else:
        context.update({ 'STATIC_URL': '/static' })
    return context, data

... and a sample config.json

{
    "static_base_url": "https://cdn.example.com/somepath"
}

I'll close this issue, as I'll not put any further work into it. Sorry, for keeping it open for so long, without any update.

@macedd
Copy link

macedd commented Oct 9, 2016

The plugin does not work with the {% static %} tamplate tag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants