-
Notifications
You must be signed in to change notification settings - Fork 745
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1092 from learningequality/release-v0.3.x
v0.3.0
- Loading branch information
Showing
205 changed files
with
23,108 additions
and
1,606 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
- repo: git://github.com/pre-commit/pre-commit-hooks | ||
sha: 97b88d9610bcc03982ddac33caba98bb2b751f5f | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: flake8 | ||
- id: check-yaml | ||
- id: check-added-large-files | ||
- id: debug-statements | ||
- id: end-of-file-fixer | ||
- repo: git://github.com/FalconSocial/pre-commit-python-sorter | ||
sha: d044ff27300a6dc8b1a56cd22552e3a810dc6f49 | ||
hooks: | ||
- id: python-import-sorter | ||
args: | ||
- --silent-overwrite | ||
- repo: git://github.com/pre-commit/pre-commit-hooks | ||
sha: a11d9314b22d8f8c7556443875b731ef05965464 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: flake8 | ||
- id: check-yaml | ||
- id: check-added-large-files | ||
- id: debug-statements | ||
- id: end-of-file-fixer | ||
- repo: git://github.com/FalconSocial/pre-commit-python-sorter | ||
sha: 5991d2aea26858d3c3538e0b4e09255b6b99413e | ||
hooks: | ||
- id: python-import-sorter | ||
args: | ||
- --silent-overwrite | ||
- repo: git://github.com/pre-commit/mirrors-eslint | ||
sha: v3.14.0 | ||
hooks: | ||
- id: eslint | ||
additional_dependencies: [ 'eslint', 'eslint-plugin-html', 'eslint-config-airbnb', 'eslint-plugin-import', 'eslint-plugin-jsx-a11y'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
""" | ||
Kolibri Content hooks | ||
--------------------- | ||
Hooks for managing the display and rendering of content. | ||
""" | ||
|
||
from __future__ import absolute_import, print_function, unicode_literals | ||
|
||
import json | ||
import logging | ||
import os | ||
|
||
from django.conf import settings as django_settings | ||
from django.utils.functional import cached_property | ||
from django.utils.safestring import mark_safe | ||
from kolibri.core.webpack.hooks import WebpackBundleHook | ||
from le_utils.constants import content_kinds | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
_JSON_CONTENT_TYPES_CACHE = {} | ||
|
||
class ContentRendererHook(WebpackBundleHook): | ||
""" | ||
An inheritable hook that allows special behaviour for a frontend module that defines | ||
a content renderer. | ||
Reads a JSON file of this format: | ||
{ | ||
"kinds": [ | ||
{ | ||
"name": "kind_name", | ||
"extensions": [ | ||
"file_extension" | ||
] | ||
} | ||
] | ||
} | ||
e.g. | ||
{ | ||
"kinds": [ | ||
{ | ||
"name": "video", | ||
"extensions": [ | ||
"mp4", | ||
"ogg", | ||
"wmv" | ||
] | ||
} | ||
] | ||
} | ||
Detailing the kinds and file extensions that the renderer can handle. | ||
""" | ||
|
||
# Set local path to content type JSON that details the kind, extension pairs this deals with. | ||
content_types_file = "" | ||
|
||
class Meta: | ||
abstract = True | ||
|
||
@cached_property | ||
def _content_type_json(self): | ||
global _JSON_CONTENT_TYPES_CACHE | ||
if not _JSON_CONTENT_TYPES_CACHE.get(self.unique_slug): | ||
try: | ||
file_path = os.path.join(self._module_file_path, self.content_types_file) | ||
with open(file_path) as f: | ||
content_types = json.load(f) | ||
for kind_data in content_types.get('kinds', []): | ||
if kind_data.get("name") not in dict(content_kinds.choices): | ||
logger.debug("{kind} not found in valid content kinds for plugin {name}".format( | ||
kind=kind_data.get("name"), name=self.unique_slug)) | ||
_JSON_CONTENT_TYPES_CACHE[self.unique_slug] = content_types | ||
except IOError: | ||
raise IOError("Content types file not found at {}".format(self.content_types_file)) | ||
return _JSON_CONTENT_TYPES_CACHE.get(self.unique_slug, {}) | ||
|
||
def render_to_page_load_async_html(self): | ||
""" | ||
Generates script tag containing Javascript to register a content renderer. | ||
:returns: HTML of a script tag to insert into a page. | ||
""" | ||
urls = [chunk['url'] for chunk in self.bundle] | ||
tags = self.frontend_message_tag() +\ | ||
['<script>{kolibri_name}.registerContentRenderer("{bundle}", ["{urls}"], {content_types});</script>'.format( | ||
kolibri_name=django_settings.KOLIBRI_CORE_JS_NAME, | ||
bundle=self.unique_slug, | ||
urls='","'.join(urls), | ||
content_types=json.dumps(self._content_type_json), | ||
)] | ||
return mark_safe('\n'.join(tags)) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
""" | ||
Content template tags | ||
===================== | ||
To use | ||
.. code-block:: html | ||
{% load webpack_tags %} | ||
<!-- Render on-demand async inclusion tag for content renderers --> | ||
{% content_renderer_assets %} | ||
""" | ||
from __future__ import absolute_import, print_function, unicode_literals | ||
|
||
from django import template | ||
from kolibri.core.webpack.utils import webpack_asset_render | ||
|
||
from .. import hooks | ||
|
||
register = template.Library() | ||
|
||
@register.simple_tag() | ||
def content_renderer_assets(): | ||
""" | ||
This is a script tag for all ``ContentRendererInclusionHook`` hooks that implement a | ||
render_to_html() method - this is used in in any template to | ||
register any content renderers with the frontend so that they can be dynamically loaded | ||
on demand. | ||
:return: HTML of script tags to insert into template | ||
""" | ||
return webpack_asset_render(hooks.ContentRendererHook, async=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
const KolibriModule = require('kolibri_module'); | ||
|
||
module.exports = class ContentRenderer extends KolibriModule { | ||
render() { | ||
this.emit(`component_render:${this.contentType}`, this.rendererComponent); | ||
} | ||
get rendererComponent() { | ||
return null; | ||
} | ||
get contentType() { | ||
get contentTypes() { | ||
return null; | ||
} | ||
}; |
Oops, something went wrong.