diff --git a/playbooks/roles/edxapp/tasks/deploy.yml b/playbooks/roles/edxapp/tasks/deploy.yml index d5f5dd1a279..9181734af12 100644 --- a/playbooks/roles/edxapp/tasks/deploy.yml +++ b/playbooks/roles/edxapp/tasks/deploy.yml @@ -364,6 +364,12 @@ - install - install:configuration +- name: import custom tinymce plugins + include_role: + name: "tinymce_plugins" + when: + - celery_worker is not defined + # creates the supervisor jobs for the # service variants configured, runs # gather_assets and db migrations diff --git a/playbooks/roles/tinymce_plugins/README.rst b/playbooks/roles/tinymce_plugins/README.rst new file mode 100644 index 00000000000..35210fa4de7 --- /dev/null +++ b/playbooks/roles/tinymce_plugins/README.rst @@ -0,0 +1,47 @@ +TinyMCE (Visual Text/HTML Editor) Plugins +----------------------------------------- + +The flexibility of the TinyMCE Visual Text and HTML editor makes it possible to configure and extend the editor using different plugins. In order to make use of that modularity in Studio, you'll need to follow two different steps. + +Installing Plugins +================== + +In order to install the needed TinyMCE plugins while setting up the edX platform, you'll need to specify them in ``TINYMCE_ADDITIONAL_PLUGINS_LIST``. It is a list of objects with the following attributes: + +.. list-table:: + :header-rows: 1 + :widths: 15 10 10 65 + + * - attribute + - type + - required + - description + * - ``repo`` + - string + - yes + - The TinyMCE plugin's repository. + * - ``name`` + - string + - yes + - Specifies the name of the cloned repository for the TinyMCE plugin. + * - ``plugin_path`` + - string + - no + - Specifies the plugin's relative path in the repository. It is the directory that directly contains the ``plugin.js`` file. + Default value is ``/``, which indicates that the repository directly contains the ``plugin.js`` file. If the repository doesn't directly contain the ``plugin.js``, then the folder containing it should share the same name as the plugin name. + +Here's an example: + +.. code:: yaml + + TINYMCE_ADDITIONAL_PLUGINS_LIST: + - repo: https://github.com/name/demo-plugin + name: demo-plugin + plugin_path: "/demo-plugin" + +Enabling Plugins +================ + +There's a decent `guide on enabling the plugins through the edX platform`_, specifically using the ``TINYMCE_ADDITIONAL_PLUGINS`` extra JavaScript configuration. + +.. _guide on enabling the plugins through the edX platform: https://github.com/edx/edx-platform/blob/master/docs/guides/extensions/tinymce_plugins.rst diff --git a/playbooks/roles/tinymce_plugins/defaults/main.yml b/playbooks/roles/tinymce_plugins/defaults/main.yml new file mode 100644 index 00000000000..5450e04efc0 --- /dev/null +++ b/playbooks/roles/tinymce_plugins/defaults/main.yml @@ -0,0 +1,10 @@ +--- + +tinymce_plugin_temp_dir: "{{ edxapp_code_dir }}/.temp_tinymce_plugin" + +tinymce_dir: "{{ edxapp_code_dir }}/common/static/js/vendor/tinymce" +tinymce_plugins_dir: "{{ tinymce_dir }}/js/tinymce/plugins" + +edx_jake_package: "{{ edxapp_code_dir }}/vendor_extra/tinymce/JakePackage.zip" + +TINYMCE_ADDITIONAL_PLUGINS_LIST: [] diff --git a/playbooks/roles/tinymce_plugins/tasks/import_tinymce_plugin.yml b/playbooks/roles/tinymce_plugins/tasks/import_tinymce_plugin.yml new file mode 100644 index 00000000000..d562e5389d4 --- /dev/null +++ b/playbooks/roles/tinymce_plugins/tasks/import_tinymce_plugin.yml @@ -0,0 +1,18 @@ +--- + +- name: Add additional tinymce plugins + block: + - name: Clone plugin + git: + repo: "{{ plugin.repo }}" + dest: "{{ tinymce_plugin_temp_dir }}/{{ plugin.name }}" + version: "{{ plugin.version | default('master') }}" + accept_hostkey: true + key_file: "{% if EDXAPP_USE_GIT_IDENTITY %}{{ edxapp_git_identity }}{% endif %}" + - name: Move plugin to tinymce plugins directory + command: "cp -r {{ tinymce_plugin_temp_dir }}/{{ plugin.name }}{{ plugin.plugin_path | default('') }} {{ tinymce_plugins_dir }}" + - name: Clean temporary tinymce plugin repository + file: + state: absent + path: "{{ tinymce_plugin_temp_dir }}/{{ plugin.name }}" + become_user: "{{ edxapp_user }}" diff --git a/playbooks/roles/tinymce_plugins/tasks/main.yml b/playbooks/roles/tinymce_plugins/tasks/main.yml new file mode 100644 index 00000000000..e9382d36a3f --- /dev/null +++ b/playbooks/roles/tinymce_plugins/tasks/main.yml @@ -0,0 +1,14 @@ +--- + +- name: Import additional tinymce plugins + include_tasks: import_tinymce_plugin.yml + loop: "{{ TINYMCE_ADDITIONAL_PLUGINS_LIST }}" + loop_control: + loop_var: plugin + when: + - TINYMCE_ADDITIONAL_PLUGINS_LIST|length > 0 + +- name: Rebuild tinymce files + include_tasks: rebuild_tinymce_files.yml + when: + - TINYMCE_ADDITIONAL_PLUGINS_LIST|length > 0 diff --git a/playbooks/roles/tinymce_plugins/tasks/rebuild_tinymce_files.yml b/playbooks/roles/tinymce_plugins/tasks/rebuild_tinymce_files.yml new file mode 100644 index 00000000000..cebed590242 --- /dev/null +++ b/playbooks/roles/tinymce_plugins/tasks/rebuild_tinymce_files.yml @@ -0,0 +1,22 @@ +--- + +- name: Minify tinymce plugin files + block: + - name: Unarchive JakePackage.zip + unarchive: + src: "{{ edx_jake_package }}" + dest: "{{ tinymce_dir }}" + remote_src: True + - name: Clean install npm dependencies from archive + shell: "npm ci" + args: + chdir: "{{ tinymce_dir }}" + - name: Clean existing tinymce js files with jake + shell: "npx jake clean-js" + args: + chdir: "{{ tinymce_dir }}" + - name: Build tinymce with jake + shell: "npx jake minify bundle[themes:*,plugins:*]" + args: + chdir: "{{ tinymce_dir }}" + become_user: "{{ edxapp_user }}"