forked from overhangio/tutor-indigo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.py
206 lines (180 loc) · 6.51 KB
/
plugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
from __future__ import annotations
import os
import typing as t
import importlib_resources
from tutor import hooks
from tutor.__about__ import __version_suffix__
from .__about__ import __version__
# Handle version suffix in nightly mode, just like tutor core
if __version_suffix__:
__version__ += "-" + __version_suffix__
################# Configuration
config: t.Dict[str, t.Dict[str, t.Any]] = {
# Add here your new settings
"defaults": {
"VERSION": __version__,
"WELCOME_MESSAGE": "The place for all your online learning",
"PRIMARY_COLOR": "#15376D", # Indigo
"ENABLE_DARK_TOGGLE": True,
# Footer links are dictionaries with a "title" and "url"
# To remove all links, run:
# tutor config save --set INDIGO_FOOTER_NAV_LINKS=[]
"FOOTER_NAV_LINKS": [
{"title": "About Us", "url": "/about"},
{"title": "Blog", "url": "/blog"},
{"title": "Donate", "url": "/donate"},
{"title": "Terms of Service", "url": "/tos"},
{"title": "Privacy Policy", "url": "/privacy"},
{"title": "Help", "url": "/help"},
{"title": "Contact Us", "url": "/contact"},
],
},
"unique": {},
"overrides": {},
}
# Theme templates
hooks.Filters.ENV_TEMPLATE_ROOTS.add_item(
str(importlib_resources.files("tutorindigo") / "templates")
)
# This is where the theme is rendered in the openedx build directory
hooks.Filters.ENV_TEMPLATE_TARGETS.add_items(
[
("indigo", "build/openedx/themes"),
("indigo/env.config.jsx", "plugins/mfe/build/mfe"),
],
)
# Force the rendering of scss files, even though they are included in a "partials" directory
hooks.Filters.ENV_PATTERNS_INCLUDE.add_items(
[
r"indigo/lms/static/sass/partials/lms/theme/",
r"indigo/cms/static/sass/partials/cms/theme/",
]
)
# init script: set theme automatically
with open(
os.path.join(
str(importlib_resources.files("tutorindigo") / "templates"),
"indigo",
"tasks",
"init.sh",
),
encoding="utf-8",
) as task_file:
hooks.Filters.CLI_DO_INIT_TASKS.add_item(("lms", task_file.read()))
# Override openedx & mfe docker image names
@hooks.Filters.CONFIG_DEFAULTS.add(priority=hooks.priorities.LOW)
def _override_openedx_docker_image(
items: list[tuple[str, t.Any]]
) -> list[tuple[str, t.Any]]:
openedx_image = ""
mfe_image = ""
for k, v in items:
if k == "DOCKER_IMAGE_OPENEDX":
openedx_image = v
elif k == "MFE_DOCKER_IMAGE":
mfe_image = v
if openedx_image:
items.append(("DOCKER_IMAGE_OPENEDX", f"{openedx_image}-indigo"))
if mfe_image:
items.append(("MFE_DOCKER_IMAGE", f"{mfe_image}-indigo"))
return items
# Load all configuration entries
hooks.Filters.CONFIG_DEFAULTS.add_items(
[(f"INDIGO_{key}", value) for key, value in config["defaults"].items()]
)
hooks.Filters.CONFIG_UNIQUE.add_items(
[(f"INDIGO_{key}", value) for key, value in config["unique"].items()]
)
hooks.Filters.CONFIG_OVERRIDES.add_items(list(config["overrides"].items()))
hooks.Filters.ENV_PATCHES.add_items(
[
# MFE will install header version 3.0.x and will include indigo-footer as a
# separate package for use in env.config.jsx
(
"mfe-dockerfile-post-npm-install-learning",
"""
RUN npm install '@edx/brand@npm:@edly-io/indigo-brand-openedx@^2.1.1'
RUN npm install '@edx/frontend-component-header@npm:@edly-io/indigo-frontend-component-header@^3.1.3'
RUN npm install @edly-io/indigo-frontend-component-footer@^2.0.0
COPY indigo/env.config.jsx /openedx/app/
""",
),
(
"mfe-dockerfile-post-npm-install-authn",
"""
RUN npm install '@edx/brand@npm:@edly-io/indigo-brand-openedx@^2.1.1'
""",
),
# Tutor-Indigo v2.1 targets the styling updates in discussions and learner-dashboard MFE
# brand-openedx is related to styling updates while others are for header and footer updates
(
"mfe-dockerfile-post-npm-install-discussions",
"""
RUN npm install '@edx/brand@npm:@edly-io/indigo-brand-openedx@^2.1.1'
RUN npm install '@edx/frontend-component-header@npm:@edly-io/indigo-frontend-component-header@^3.1.3'
RUN npm install @edly-io/indigo-frontend-component-footer@^2.0.0
COPY indigo/env.config.jsx /openedx/app/
""",
),
(
"mfe-dockerfile-post-npm-install-learner-dashboard",
"""
RUN npm install '@edx/brand@npm:@edly-io/indigo-brand-openedx@^2.1.1'
RUN npm install @edly-io/indigo-frontend-component-footer@^2.0.0
COPY indigo/env.config.jsx /openedx/app/
""",
),
(
"mfe-dockerfile-post-npm-install-profile",
"""
RUN npm install '@edx/brand@npm:@edly-io/indigo-brand-openedx@^2.1.1'
RUN npm install '@edx/frontend-component-header@npm:@edly-io/indigo-frontend-component-header@^3.1.3'
RUN npm install @edly-io/indigo-frontend-component-footer@^2.0.0
COPY indigo/env.config.jsx /openedx/app/
""",
),
(
"mfe-dockerfile-post-npm-install-account",
"""
RUN npm install '@edx/brand@npm:@edly-io/indigo-brand-openedx@^2.1.1'
RUN npm install '@edx/frontend-component-header@npm:@edly-io/indigo-frontend-component-header@^3.1.3'
RUN npm install @edly-io/indigo-frontend-component-footer@^2.0.0
COPY indigo/env.config.jsx /openedx/app/
""",
),
]
)
# Include js file in lms main.html, main_django.html, and certificate.html
hooks.Filters.ENV_PATCHES.add_items(
[
# for production
(
"openedx-common-assets-settings",
"""
javascript_files = ['base_application', 'application', 'certificates_wv']
dark_theme_filepath = ['indigo/js/dark-theme.js']
for filename in javascript_files:
if filename in PIPELINE['JAVASCRIPT']:
PIPELINE['JAVASCRIPT'][filename]['source_filenames'] += dark_theme_filepath
""",
),
# for development
(
"openedx-lms-development-settings",
"""
javascript_files = ['base_application', 'application', 'certificates_wv']
dark_theme_filepath = ['indigo/js/dark-theme.js']
for filename in javascript_files:
if filename in PIPELINE['JAVASCRIPT']:
PIPELINE['JAVASCRIPT'][filename]['source_filenames'] += dark_theme_filepath
MFE_CONFIG['INDIGO_ENABLE_DARK_TOGGLE'] = {{ INDIGO_ENABLE_DARK_TOGGLE }}
""",
),
(
"openedx-lms-production-settings",
"""
MFE_CONFIG['INDIGO_ENABLE_DARK_TOGGLE'] = {{ INDIGO_ENABLE_DARK_TOGGLE }}
""",
),
]
)