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

Embedding with RequireJS #72

Merged
merged 3 commits into from Feb 28, 2014
Merged

Embedding with RequireJS #72

merged 3 commits into from Feb 28, 2014

Conversation

zepheiryan
Copy link
Contributor

This works, and should take care of line breaks and quotation marks in titles, but.

  • I could not find a way to dynamically get absolute URLs into the static build for r.js. By nature, require's private context prevents reaching in and modifying paths. r.js does not accept external variables, sadly. Other solution possibilities are definitely welcome; perhaps it hook into the collectstatic action to generate an embed-main based on a template before require runs?
  • The require.conf module's settings cannot find REQUIRE_STANDALONE_MODULES without it being in viewshare_site_settings.py (i.e., the most local settings file) and will not find it in other settings files.
  • It may be useful to amend Exhibit to take some sort of loadCss: false configuration. It currently goes out to fetch all the CSS already bundled in through Viewshare. It may also be useful to provide post-setting paths methods.
  • There's an open question as to how this will do when interacting with existing Bootstrap / jQuery setups in the pages it will be embedded in. It shouldn't affect RequireJS setups.

…n get escaped to HTML entities; removing JSON dump
…uilt file. note that this looks for a setting which won't be found unless it's in the most local file (e.g., local_settings.py, vs. vanilla source settings.py). also note that there wasn't a good way to get full URLs into the require config, so they're built in by default. needs a fix of some sort.
@zepheiryan
Copy link
Contributor Author

Just to pull it out and re-emphasize, embed-main.js contains absolute paths like http://viewshare.org/static/simile/exhibit/styles/exhibit-bundle.css because there doesn't appear to be a great way to get those configurations set without modifying Exhibit, et al.

@dfeeney
Copy link
Contributor

dfeeney commented Feb 28, 2014

Thanks.

I could not find a way to dynamically get absolute URLs into the static build for r.js. By nature, require's private context prevents reaching in and modifying paths. r.js does not accept external variables, sadly. Other solution possibilities are definitely welcome; perhaps it hook into the collectstatic action to generate an embed-main based on a template before require runs?

Hmm. That's a shame. The notion of hooking into collectstatic sprang to mind for me as well. That seems it should be reasonably straightforward (assuming that the hooks can be ordered -- the optimization process that django-require uses would have to come after this one.)

The require.conf module's settings cannot find REQUIRE_STANDALONE_MODULES without it being in viewshare_site_settings.py (i.e., the most local settings file) and will not find it in other settings files.

Just to check, did you try modifying the settings.py in viewshare_site? This is the root settings for the site project, and the settings.py in the viewshare project isn't used at all (which is something worth streamlining at some point).

It may be useful to amend Exhibit to take some sort of loadCss: false configuration. It currently goes out to fetch all the CSS already bundled in through Viewshare. It may also be useful to provide post-setting paths methods.

If I understand correctly, this would be a potential solution to the first problem?

There's an open question as to how this will do when interacting with existing Bootstrap / jQuery setups in the pages it will be embedded in. It shouldn't affect RequireJS setups.

Yeah...

Despite the above issues, this looks like a great start. I'll merge and we can deal with the above separately.

dfeeney added a commit that referenced this pull request Feb 28, 2014
@dfeeney dfeeney merged commit dc059dc into develop Feb 28, 2014
@dfeeney dfeeney deleted the feature/embed-requirejs branch March 4, 2014 21:17
@zepheiryan
Copy link
Contributor Author

Let's go ahead and say the collectstatic hook is the best option to explore. I'm not sure I can guarantee the correct order of operations setting the path later (e.g., it may go out to fetch an image before the path is set properly).

I thought I'd tried bubbling the REQUIRE config up through the less to the more local settings files, including the viewshare_site/settings.py file, yes.

@dfeeney
Copy link
Contributor

dfeeney commented Mar 5, 2014

I've made some progress with this. It turns out you can call requirejs.config multiple times, with the last call overriding any previous. If we define a global window.freemix.staticUrl in the base template, we can embed a requirejs.config() that overrides these values in the body of the main. I've validated this with a debug setup after making some modifications so that the base css and the proper main is provided. I'll make sure this works optimized, then make a separate pull request for your review.

This comes with a couple of caveats. There are a couple of images that aren't loading. Also, there's an error in the EHistory module when I try to switch views. This was happening before I made these modifications, though, so probably isn't related.

@zepheiryan
Copy link
Contributor Author

There are a couple of images that aren't loading.

That's why I didn't pursue that strategy any farther. If you can find a way to make this work, by all means, but I couldn't. Using paths comes up pretty early in the Exhibit setup process, so config basically needs to happen before it starts. You can also pre-define a variable named require with settings before requirejs loads, but that didn't seem to work out either (it didn't appear to do a full-depth merge).

There are a couple ways to hook into commands. One is just to take over the name and call the original handler when needed. Another less brute force way is that the collectstatic command explicitly calls a post processing method for the static file storage class, and the require module provides one. We could subclass it and call its handler at need, changing the Django settings to point to our own class.

@dfeeney dfeeney mentioned this pull request Mar 7, 2014
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

Successfully merging this pull request may close these issues.

None yet

2 participants