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

Themes (bootswatch + codemirror) #991

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ inginious/backup
# Build files
build/lib
build/scripts-*

# frontend
inginious/frontend/themes/Makefile
inginious/frontend/themes/test.html
inginious/frontend/themes/package-lock.json
inginious/frontend/themes/node_modules
inginious/frontend/themes/codemirror_scrapper.py
15 changes: 15 additions & 0 deletions inginious/frontend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ def get_app(config):
available_languages = {"en": "English"}
available_languages.update(available_translations)

available_themes = [
theme_dir for theme_dir in os.listdir(os.path.join(get_root_path(), 'frontend', 'static', 'css', 'themes'))
if theme_dir not in ('codemirror', ) and not theme_dir.startswith(('.', '_'))
]
available_codemirror_themes= [
file.split('.')[0] for file in os.listdir(os.path.join(get_root_path(), 'frontend', 'static', 'css', 'themes', 'codemirror'))
if file.endswith('.css') and not file.startswith('main')
]

l10n_manager = L10nManager()

l10n_manager.translations["en"] = gettext.NullTranslations() # English does not need translation ;-)
Expand All @@ -189,6 +198,8 @@ def get_app(config):
template_helper.add_to_template_globals("get_homepath", get_homepath)
template_helper.add_to_template_globals("pkg_version", __version__)
template_helper.add_to_template_globals("available_languages", available_languages)
template_helper.add_to_template_globals("available_themes", available_themes)
template_helper.add_to_template_globals("available_codemirror_themes", available_codemirror_themes)
template_helper.add_to_template_globals("_", _)
flask_app.template_helper = template_helper
init_flask_maintenance_mapping(flask_app)
Expand Down Expand Up @@ -242,6 +253,8 @@ def get_app(config):
template_helper.add_to_template_globals("_", _)
template_helper.add_to_template_globals("str", str)
template_helper.add_to_template_globals("available_languages", available_languages)
template_helper.add_to_template_globals("available_themes", available_themes)
template_helper.add_to_template_globals("available_codemirror_themes", available_codemirror_themes)
template_helper.add_to_template_globals("get_homepath", get_homepath)
template_helper.add_to_template_globals("pkg_version", __version__)
template_helper.add_to_template_globals("allow_registration", config.get("allow_registration", True))
Expand Down Expand Up @@ -302,6 +315,8 @@ def flask_internalerror(e):
flask_app.allow_registration = config.get("allow_registration", True)
flask_app.allow_deletion = config.get("allow_deletion", True)
flask_app.available_languages = available_languages
flask_app.available_themes = available_themes
flask_app.available_codemirror_themes = available_codemirror_themes
flask_app.welcome_page = config.get("welcome_page", None)
flask_app.terms_page = config.get("terms_page", None)
flask_app.privacy_page = config.get("privacy_page", None)
Expand Down
23 changes: 23 additions & 0 deletions inginious/frontend/pages/preferences/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,29 @@ def save_profile(self, userdata, data):
else:
self.user_manager.set_session_language(language)

if data["theme"] != userdata.get('theme', 'default'):
theme = data["theme"] if data["theme"] in self.app.available_themes else "default"
result = self.database.users.find_one_and_update({"username": self.user_manager.session_username()},
{"$set": {"theme": theme}},
return_document=ReturnDocument.AFTER)
if not result:
error = True
msg = _("Incorrect username.")
return result, msg, error
else:
self.user_manager.set_session_theme(theme)

if data["codemirror_theme"] != userdata.get('codemirror_theme', 'default'):
codemirror_theme = data["codemirror_theme"] if data["codemirror_theme"] in self.app.available_codemirror_themes else "default"
result = self.database.users.find_one_and_update({"username": self.user_manager.session_username()},
{"$set": {"codemirror_theme": codemirror_theme}},
return_document=ReturnDocument.AFTER)
if not result:
error = True
msg = _("Incorrect username.")
return result, msg, error
else:
self.user_manager.set_session_codemirror_theme(codemirror_theme)
# Checks if updating name
if len(data["realname"]) > 0:
result = self.database.users.find_one_and_update({"username": self.user_manager.session_username()},
Expand Down
3 changes: 3 additions & 0 deletions inginious/frontend/parsable_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def run(self):
if not self.content:
translation = _get_inginious_translation()
self.content = [translation.gettext("[no content]")]

self.options.setdefault('classes', []).append('theme:{}'.format(flask.current_app.user_manager.session_codemirror_theme()))
return super(EmptiableCodeBlock, self).run()


Expand Down Expand Up @@ -327,3 +329,4 @@ class GenAdm(CustomBaseAdmonition):
directives.register_directive("warning", _gen_admonition_cls(nodes.warning))
directives.register_directive("hidden-until", HiddenUntilDirective)
directives.register_directive("code-block", EmptiableCodeBlock)
directives.register_directive("code", EmptiableCodeBlock)
41 changes: 41 additions & 0 deletions inginious/frontend/static/css/themes/codemirror/3024-day.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*

Name: 3024 day
Author: Jan T. Sott (http://github.com/idleberg)

CodeMirror template by Jan T. Sott (https://github.com/idleberg/base16-codemirror)
Original Base16 color scheme by Chris Kempson (https://github.com/chriskempson/base16)

*/

.cm-s-3024-day.CodeMirror { background: #f7f7f7; color: #3a3432; }
.cm-s-3024-day div.CodeMirror-selected { background: #d6d5d4; }

.cm-s-3024-day .CodeMirror-line::selection, .cm-s-3024-day .CodeMirror-line > span::selection, .cm-s-3024-day .CodeMirror-line > span > span::selection { background: #d6d5d4; }
.cm-s-3024-day .CodeMirror-line::-moz-selection, .cm-s-3024-day .CodeMirror-line > span::-moz-selection, .cm-s-3024-day .CodeMirror-line > span > span::selection { background: #d9d9d9; }

.cm-s-3024-day .CodeMirror-gutters { background: #f7f7f7; border-right: 0px; }
.cm-s-3024-day .CodeMirror-guttermarker { color: #db2d20; }
.cm-s-3024-day .CodeMirror-guttermarker-subtle { color: #807d7c; }
.cm-s-3024-day .CodeMirror-linenumber { color: #807d7c; }

.cm-s-3024-day .CodeMirror-cursor { border-left: 1px solid #5c5855; }

.cm-s-3024-day span.cm-comment { color: #cdab53; }
.cm-s-3024-day span.cm-atom { color: #a16a94; }
.cm-s-3024-day span.cm-number { color: #a16a94; }

.cm-s-3024-day span.cm-property, .cm-s-3024-day span.cm-attribute { color: #01a252; }
.cm-s-3024-day span.cm-keyword { color: #db2d20; }
.cm-s-3024-day span.cm-string { color: #fded02; }

.cm-s-3024-day span.cm-variable { color: #01a252; }
.cm-s-3024-day span.cm-variable-2 { color: #01a0e4; }
.cm-s-3024-day span.cm-def { color: #e8bbd0; }
.cm-s-3024-day span.cm-bracket { color: #3a3432; }
.cm-s-3024-day span.cm-tag { color: #db2d20; }
.cm-s-3024-day span.cm-link { color: #a16a94; }
.cm-s-3024-day span.cm-error { background: #db2d20; color: #5c5855; }

.cm-s-3024-day .CodeMirror-activeline-background { background: #e8f2ff; }
.cm-s-3024-day .CodeMirror-matchingbracket { text-decoration: underline; color: #a16a94 !important; }
39 changes: 39 additions & 0 deletions inginious/frontend/static/css/themes/codemirror/3024-night.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*

Name: 3024 night
Author: Jan T. Sott (http://github.com/idleberg)

CodeMirror template by Jan T. Sott (https://github.com/idleberg/base16-codemirror)
Original Base16 color scheme by Chris Kempson (https://github.com/chriskempson/base16)

*/

.cm-s-3024-night.CodeMirror { background: #090300; color: #d6d5d4; }
.cm-s-3024-night div.CodeMirror-selected { background: #3a3432; }
.cm-s-3024-night .CodeMirror-line::selection, .cm-s-3024-night .CodeMirror-line > span::selection, .cm-s-3024-night .CodeMirror-line > span > span::selection { background: rgba(58, 52, 50, .99); }
.cm-s-3024-night .CodeMirror-line::-moz-selection, .cm-s-3024-night .CodeMirror-line > span::-moz-selection, .cm-s-3024-night .CodeMirror-line > span > span::-moz-selection { background: rgba(58, 52, 50, .99); }
.cm-s-3024-night .CodeMirror-gutters { background: #090300; border-right: 0px; }
.cm-s-3024-night .CodeMirror-guttermarker { color: #db2d20; }
.cm-s-3024-night .CodeMirror-guttermarker-subtle { color: #5c5855; }
.cm-s-3024-night .CodeMirror-linenumber { color: #5c5855; }

.cm-s-3024-night .CodeMirror-cursor { border-left: 1px solid #807d7c; }

.cm-s-3024-night span.cm-comment { color: #cdab53; }
.cm-s-3024-night span.cm-atom { color: #a16a94; }
.cm-s-3024-night span.cm-number { color: #a16a94; }

.cm-s-3024-night span.cm-property, .cm-s-3024-night span.cm-attribute { color: #01a252; }
.cm-s-3024-night span.cm-keyword { color: #db2d20; }
.cm-s-3024-night span.cm-string { color: #fded02; }

.cm-s-3024-night span.cm-variable { color: #01a252; }
.cm-s-3024-night span.cm-variable-2 { color: #01a0e4; }
.cm-s-3024-night span.cm-def { color: #e8bbd0; }
.cm-s-3024-night span.cm-bracket { color: #d6d5d4; }
.cm-s-3024-night span.cm-tag { color: #db2d20; }
.cm-s-3024-night span.cm-link { color: #a16a94; }
.cm-s-3024-night span.cm-error { background: #db2d20; color: #807d7c; }

.cm-s-3024-night .CodeMirror-activeline-background { background: #2F2F2F; }
.cm-s-3024-night .CodeMirror-matchingbracket { text-decoration: underline; color: white !important; }
Loading