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

Frontend asset loading #49

Merged
merged 40 commits into from Apr 12, 2016

Conversation

rtibbles
Copy link
Member

@rtibbles rtibbles commented Mar 8, 2016

Summary

This is a WIP to implement and provide an example hook for base.html of both synchronous and asynchronous frontend asset loading.

TODO

  • Have tests been written for the new code?
  • Has documentation been written/updated?
  • New dependencies (if any) added to requirements file
  • Add an entry to CHANGELOG.rst
  • Add yourself it AUTHORS.rst if you don't appear there

Reviewer guidance

This PR also adds in JS Linting during the webpack build process, in order to compensate for the fact that the JSHint precommit hook doesn't work on Windows and had to be removed.

In addition, it simplifies the naming of frontend assets to provide a simpler naming convention, based solely on the name of their Python module in Kolibri, and the name of the Class in which they are defined in kolibri_plugins.py.

Finally, it provides a Javascript asynchronous frontend asset loader that can load both CSS and Javascript, in order to allow plugins to be registered to the frontend asynchronously and loaded when needed.

Adds a function for creating template tags with a hook to allow arbitrary plugins to plugin synchronously and asynchronously into any template.

Creates tags for these for base.html to allow for extension of base.html frontend functionality and as an example.

Issues addressed

Fixes #41, and fixes #38

Documentation

Much inline documentation. Also updates frontend.rst.

@rtibbles
Copy link
Member Author

rtibbles commented Mar 9, 2016

Woops, broke coverage.

@codecov-io
Copy link

Current coverage is 88.29%

Merging #49 into master will increase coverage by +4.03% as of 8050f0d

@@            master     #49   diff @@
======================================
  Files           38      40     +2
  Stmts         1017    1188   +171
  Branches       102     129    +27
  Methods          0       0       
======================================
+ Hit            857    1049   +192
+ Partial         23      22     -1
+ Missed         137     117    -20

Review entire Coverage Diff as of 8050f0d

Powered by Codecov. Updated on successful CI builds.

@rtibbles
Copy link
Member Author

rtibbles commented Mar 9, 2016

Woot, the asset-loader module has full code coverage!

@@ -0,0 +1,20 @@
{

This comment was marked as spam.

This comment was marked as spam.

@aronasorman
Copy link
Collaborator

Making the frontend asset naming consistent across JS and Python, some linting config. Changes look OK.

Modify example plugin to use new Plugin object as Base.
Ignore injected global __plugin_name in linting.
In order to extract the events data required for async loading.
…or the core app.

Return async files from plugin registration.
Adds template tags for the base template sync and async frontend hooks.
Adds async example to example plugin.
@rtibbles
Copy link
Member Author

Pushing latest changes in case anyone wants to look at them.

Tests have not been updated, so will break. Documentation needs to be written.

@rtibbles rtibbles force-pushed the frontend_asset_loading branch 4 times, most recently from 6d0264b to fec6aab Compare March 12, 2016 17:26
@rtibbles
Copy link
Member Author

rtibbles commented Apr 9, 2016

After some discussion with @indirectlylit and @MCGallaspy, and due to some issues with the approach taken to inspect the Javascript code and extract the events and once hashes at compilation time to allow for asynchronous loading - I have now changed the events and once hashes to be defined within the classes subclassed from KolibriFrontEndBase.

Configuration of these hashes now happens from within kolibri_plugin.py, and is then injected into the Javascript code at build time.

@MCGallaspy
Copy link
Contributor

Can you also update this section: https://github.com/rtibbles/kolibri/blob/frontend_asset_loading/docs/dev/frontend.rst#writing-frontend-plugins

Also, who is responsible for merging this PR?

@rtibbles
Copy link
Member Author

Good catch. Changing.

@rtibbles
Copy link
Member Author

@aronasorman is assigned - I'll see if he is happy to sign it off.

// The Backbone Model extend method is a standalone function that is used to extend many Backbone objects.
// We use it here in preference to rolling our own to allow for extension of Plugins.

Plugin.extend = Backbone.Model.extend;

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@@ -38,6 +38,7 @@ class KolibriCoreFrontEnd(KolibriFrontEndPluginBase):
"""
entry_file = "assets/src/kolibri_core_app.js"
external = True
core = True

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@rtibbles rtibbles force-pushed the frontend_asset_loading branch 2 times, most recently from e2ca7f7 to 2f50a55 Compare April 11, 2016 19:57
@indirectlylit
Copy link
Contributor

I'm a bit confused by the various webpack config files in the root directory:

  • parse_bundle_plugin.js and karma.conf.js reference webpack.config.base.js
  • webpack.config.dev.js references webpack.config.js
  • webpack.config.base.js and webpack.config.js do not reference each other

Seems like perhaps both webpack.config.base.js and webpack.config.js are trying to play the "base" role?

@rtibbles
Copy link
Member Author

webpack.config.base.js is the base config that gets used for all other webpack configs (so shared across tests, production building, and dev building).

parse_bundle_plugin.js is at the end of a chain of three functions that build the configuration for webpack.config.js, so acts as the point of entry for the base config to get into the webpack configuration.

I will annotate the relevant files to make their roles more clear. Thanks for the feedback!

@rtibbles rtibbles force-pushed the frontend_asset_loading branch 6 times, most recently from 7504170 to c8af859 Compare April 11, 2016 21:13
return frontend_sync(BASE_FRONTEND_SYNC)


def frontend_async(hook):

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

…sions.

Removes unnecessary jsdom dependency.
Adds sourcemaps to karma tests for easier debugging.
if chunk['name'].endswith('.js'):
tags.append('<script type="text/javascript" src="{static}/{url}"></script>'.format(static=static, url=url))
tags.append('<script type="text/javascript" src="{url}"></script>'.format(url=render_as_url(chunk)))

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@rtibbles
Copy link
Member Author

This PR is now a month old. It is also being used in active code development by @MCGallaspy and @DXCanas - I believe all interested parties have had the opportunity to review, and I have responded to all comments.

@aronasorman has said to me that he does not have the time or familiarity to give the go ahead, as such, and due to the foregoing that there has been ample review, I will be merging this at EOD today if there are no strenuous objections raised prior to then.

@MCGallaspy
Copy link
Contributor

Yeah, I think further iteration on this can be addressed in subsequent PRs.

@MCGallaspy MCGallaspy merged commit c57f4e8 into learningequality:master Apr 12, 2016
@rtibbles rtibbles deleted the frontend_asset_loading branch September 8, 2016 17:15
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

6 participants