diff --git a/webapp/alembic/versions/058f970b85db_added_css_variables_column.py b/webapp/alembic/versions/058f970b85db_added_css_variables_column.py new file mode 100644 index 0000000..fa6dc62 --- /dev/null +++ b/webapp/alembic/versions/058f970b85db_added_css_variables_column.py @@ -0,0 +1,28 @@ +"""Added CSS Variables Column + +Revision ID: 058f970b85db +Revises: 95ab6a63135d +Create Date: 2017-06-04 22:51:34.297399 + +""" + +# revision identifiers, used by Alembic. +revision = '058f970b85db' +down_revision = '95ab6a63135d' +branch_labels = None +depends_on = None + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('user_css', sa.Column('css_variables', sa.Text(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('user_css', 'css_variables') + # ### end Alembic commands ### diff --git a/webapp/titanembeds/blueprints/embed/embed.py b/webapp/titanembeds/blueprints/embed/embed.py index 8d3f2dd..79c982b 100644 --- a/webapp/titanembeds/blueprints/embed/embed.py +++ b/webapp/titanembeds/blueprints/embed/embed.py @@ -4,6 +4,7 @@ from titanembeds.oauth import generate_guild_icon_url, generate_avatar_url from titanembeds.database import db, Guilds, UserCSS from config import config import random +import json embed = Blueprint("embed", __name__) @@ -26,6 +27,28 @@ def get_custom_css(): css = db.session.query(UserCSS).filter(UserCSS.id == css).first() return css +def parse_css_variable(css): + CSS_VARIABLES_TEMPLATE = """:root { + /*--: */ + --modal: %(modal)s; + --noroleusers: %(noroleusers)s; + --main: %(main)s; + --placeholder: %(placeholder)s; + --sidebardivider: %(sidebardivider)s; + --leftsidebar: %(leftsidebar)s; + --rightsidebar: %(rightsidebar)s; + --header: %(header)s; + --chatmessage: %(chatmessage)s; + --discrim: %(discrim)s; + --chatbox: %(chatbox)s; + }""" + if not css: + return None + else: + variables = css.css_variables + variables = json.loads(variables) + return CSS_VARIABLES_TEMPLATE % variables + @embed.route("/") def guild_embed(guild_id): if check_guild_existance(guild_id): @@ -37,13 +60,15 @@ def guild_embed(guild_id): "icon": guild.icon, "discordio": guild.discordio, } + customcss = get_custom_css() return render_template("embed.html.j2", login_greeting=get_logingreeting(), guild_id=guild_id, guild=guild_dict, generate_guild_icon=generate_guild_icon_url, unauth_enabled=guild_query_unauth_users_bool(guild_id), client_id=config['client-id'], - css=get_custom_css() + css=customcss, + cssvariables=parse_css_variable(customcss) ) abort(404) diff --git a/webapp/titanembeds/blueprints/user/user.py b/webapp/titanembeds/blueprints/user/user.py index 558a3bb..bea781c 100644 --- a/webapp/titanembeds/blueprints/user/user.py +++ b/webapp/titanembeds/blueprints/user/user.py @@ -5,6 +5,7 @@ from titanembeds.database import db, Guilds, UnauthenticatedUsers, Unauthenticat from titanembeds.oauth import authorize_url, token_url, make_authenticated_session, get_current_authenticated_user, get_user_managed_servers, check_user_can_administrate_guild, check_user_permission, generate_avatar_url, generate_guild_icon_url, generate_bot_invite_url import time import datetime +import json user = Blueprint("user", __name__) @@ -95,7 +96,7 @@ def new_custom_css_post(): else: name = name.strip() css = css.strip() - css = UserCSS(name, user_id, css) + css = UserCSS(name, user_id, None, css) db.session.add(css) db.session.commit() return jsonify({"id": css.id}) @@ -111,7 +112,8 @@ def edit_custom_css_get(css_id): abort(404) if css.user_id != session['user_id']: abort(403) - return render_template("usercss.html.j2", new=False, css=css) + variables = json.loads(css.css_variables) + return render_template("usercss.html.j2", new=False, css=css, variables=variables) @user.route("/custom_css/edit/", methods=["POST"]) @discord_users_only() @@ -126,6 +128,7 @@ def edit_custom_css_post(css_id): abort(403) name = request.form.get("name", None) css = request.form.get("css", "") + variables = request.form.get("variables", None) if not name: abort(400) else: @@ -133,6 +136,7 @@ def edit_custom_css_post(css_id): css = css.strip() dbcss.name = name dbcss.css = css + dbcss.css_variables = variables db.session.commit() return jsonify({"id": dbcss.id}) diff --git a/webapp/titanembeds/database/user_css.py b/webapp/titanembeds/database/user_css.py index e9905be..06cc8e1 100644 --- a/webapp/titanembeds/database/user_css.py +++ b/webapp/titanembeds/database/user_css.py @@ -5,9 +5,11 @@ class UserCSS(db.Model): id = db.Column(db.Integer, primary_key=True) # Auto increment id name = db.Column(db.String(255), nullable=False) # CSS Name user_id = db.Column(db.String(255), nullable=False) # Discord client ID of the owner of the css (can edit) + css_variables = db.Column(db.Text()) # Customizeable CSS Variables css = db.Column(db.Text()) # CSS contents - def __init__(self, name, user_id, css=None): + def __init__(self, name, user_id, css_variables=None, css=None): self.name = name self.user_id = user_id + self.css_variables = css_variables self.css = css diff --git a/webapp/titanembeds/static/js/usercss.js b/webapp/titanembeds/static/js/usercss.js index 68f9a6b..efff530 100644 --- a/webapp/titanembeds/static/js/usercss.js +++ b/webapp/titanembeds/static/js/usercss.js @@ -4,11 +4,12 @@ function postForm() { var name = $('#css_name').val(); + var variables = JSON.stringify(formatCSSVars()); var css = editor.getValue(); var funct = $.ajax({ dataType: "json", method: "POST", - data: {"name": name, "css": css} + data: {"name": name, "variables": variables, "css": css} }); return funct.promise(); } @@ -23,6 +24,22 @@ } }); + function formatCSSVars() { + return { + "modal": $("#css_var_modal").val(), + "noroleusers": $("#css_var_noroleusers").val(), + "main": $("#css_var_main").val(), + "placeholder": $("#css_var_placeholder").val(), + "sidebardivider": $("#css_var_sidebardivider").val(), + "leftsidebar": $("#css_var_leftsidebar").val(), + "rightsidebar": $("#css_var_rightsidebar").val(), + "header": $("#css_var_header").val(), + "chatmessage": $("#css_var_chatmessage").val(), + "discrim": $("#css_var_discrim").val(), + "chatbox": $("#css_var_chatbox").val(), + }; + } + function submitForm() { var formPost = postForm(); formPost.done(function (data) { diff --git a/webapp/titanembeds/templates/embed.html.j2 b/webapp/titanembeds/templates/embed.html.j2 index 535e2e0..7212184 100644 --- a/webapp/titanembeds/templates/embed.html.j2 +++ b/webapp/titanembeds/templates/embed.html.j2 @@ -17,7 +17,7 @@ {% include 'google_analytics.html.j2' %} {% if css is not none %} - + {% endif %} diff --git a/webapp/titanembeds/templates/usercss.html.j2 b/webapp/titanembeds/templates/usercss.html.j2 index 164029d..c443247 100644 --- a/webapp/titanembeds/templates/usercss.html.j2 +++ b/webapp/titanembeds/templates/usercss.html.j2 @@ -27,6 +27,56 @@ will have CSS cosmetic privilages removed, if caught. Please don't, we check the +
+

Propose Predefined CSS variables here

+
+
+ Modal Background Color (--modal): + +
+
+ Uncategorized Discord Users (--noroleusers): + +
+
+ Main Background Color (--main): + +
+
+ Text input placeholder (--placeholder): + +
+
+ Sidebar Dividers (--sidebardivider): + +
+
+ Left Sidebar/Guild Navigation Background (--leftsidebar): + +
+
+ Right Sidebar/Member List Background (--rightsidebar): + +
+
+ Header Background (--header): + +
+
+ Chat Message (--chatmessage): + +
+
+ Discriminator Text (--discrim): + +
+
+ Message Box Background (--chatbox): + +
+
+

TIP! You can use the variables in your CSS below! Something like color: var(--leftsidebar); would work!

+

Edit your CSS code here

@@ -45,6 +95,7 @@ will have CSS cosmetic privilages removed, if caught. Please don't, we check the {% block script %} +