]> cat aescling's git repositories - mastodon.git/commitdiff
Better themeing support!!
authorkibigo! <marrus-sh@users.noreply.github.com>
Tue, 26 Sep 2017 02:24:32 +0000 (19:24 -0700)
committerkibigo! <marrus-sh@users.noreply.github.com>
Tue, 26 Sep 2017 02:24:32 +0000 (19:24 -0700)
25 files changed:
app/controllers/application_controller.rb
app/controllers/settings/preferences_controller.rb
app/javascript/glitch/components/local_settings/navigation/item/style.scss
app/javascript/glitch/components/local_settings/navigation/style.scss
app/javascript/glitch/components/local_settings/page/item/style.scss
app/javascript/glitch/components/local_settings/page/style.scss
app/javascript/glitch/components/local_settings/style.scss
app/javascript/packs/application.js
app/javascript/packs/frontends/mastodon.js [deleted file]
app/javascript/styles/custom.scss [deleted file]
app/javascript/themes/default/theme.yml [new file with mode: 0644]
app/javascript/themes/spin/pack.js [new file with mode: 0644]
app/javascript/themes/spin/style.scss [new file with mode: 0644]
app/javascript/themes/spin/theme.yml [new file with mode: 0644]
app/lib/themes.rb [new file with mode: 0644]
app/lib/user_settings_decorator.rb
app/models/user.rb
app/views/home/index.html.haml
app/views/settings/preferences/show.html.haml
config/initializers/frontends.rb [deleted file]
config/locales/simple_form.en.yml
config/settings.yml
config/webpack/configuration.js
config/webpack/loaders/sass.js
config/webpack/shared.js

index 0b40fb05b730f349790785781294e529cf06f541..d5eca6ffb601254cb991ef67c62c18b108e8d7bf 100644 (file)
@@ -12,6 +12,7 @@ class ApplicationController < ActionController::Base
 
   helper_method :current_account
   helper_method :current_session
+  helper_method :current_theme
   helper_method :single_user_mode?
 
   rescue_from ActionController::RoutingError, with: :not_found
@@ -77,6 +78,11 @@ class ApplicationController < ActionController::Base
     @current_session ||= SessionActivation.find_by(session_id: cookies.signed['_session_id'])
   end
 
+  def current_theme
+    return Setting.default_settings['theme'] unless Themes.instance.names.include? current_user&.setting_theme
+    current_user.setting_theme
+  end
+
   def cache_collection(raw, klass)
     return raw unless klass.respond_to?(:with_includes)
 
index f107f2b165f844e2f2d16f14e0c4804a688dea83..207c7b3240b4c5b9a78c8a933c26554045a15116 100644 (file)
@@ -41,6 +41,7 @@ class Settings::PreferencesController < ApplicationController
       :setting_auto_play_gif,
       :setting_system_font_ui,
       :setting_noindex,
+      :setting_theme,
       notification_emails: %i(follow follow_request reblog favourite mention digest),
       interactions: %i(must_be_follower must_be_following)
     )
index 505c869126ad48caf0f2e89d46bbe6deb9ddcbe0..33d7d3744156028e973373317600737961bffde4 100644 (file)
@@ -1,4 +1,4 @@
-@import 'variables';
+@import 'styles/variables';
 
 .glitch.local-settings__navigation__item {
   display: block;
index 1cc39e3e95e21572875f912f10cdc4c27827f7ba..a610a12121f5c0067068786dd7146da89f06549b 100644 (file)
@@ -1,4 +1,4 @@
-@import 'variables';
+@import 'styles/variables';
 
 .glitch.local-settings__navigation {
   background: $primary-text-color;
index e614030c02dbae1a97a8e576f60595d10e47d53a..da1941b998cdac93573d68b467451d8dcb265a9a 100644 (file)
@@ -1,4 +1,4 @@
-@import 'variables';
+@import 'styles/variables';
 
 .glitch.local-settings__page__item {
   select {
index 7269056c3d69205ebca62fa5d64d6e594dcc7111..53c95ea4026f6d50b655025760000071e7b52222 100644 (file)
@@ -1,4 +1,4 @@
-@import 'variables';
+@import 'styles/variables';
 
 .glitch.local-settings__page {
   display: block;
index 6f7fcbaa4ea268a301e8c298a6c5c4c632c6b109..54fec47bd9139203db4c30414ddb5f80351ba1f7 100644 (file)
@@ -1,4 +1,4 @@
-@import 'variables';
+@import 'styles/variables';
 
 .glitch.local-settings {
   position: relative;
index c06714dc149dbdd5d36ef4f408b26df8e32cccc5..aa94006c63feb75529c62ede7e22b6e90ae2cb32 100644 (file)
@@ -2,7 +2,7 @@ import loadPolyfills from '../mastodon/load_polyfills';
 
 // import default stylesheet with variables
 require('font-awesome/css/font-awesome.css');
-require('mastodon-application-style');
+import 'styles/application';
 
 require.context('../images/', true);
 
diff --git a/app/javascript/packs/frontends/mastodon.js b/app/javascript/packs/frontends/mastodon.js
deleted file mode 100644 (file)
index a983de3..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-// This file replaces `app/javascript/packs/application.js` for use
-// with multiple frontends.
-
-import loadPolyfills from '../../mastodon/load_polyfills';
-
-// import default stylesheet with variables
-require('font-awesome/css/font-awesome.css');
-require('mastodon-application-style');
-
-require.context('../../images/', true);
-
-loadPolyfills().then(() => {
-  require('../../mastodon/main').default();
-}).catch(e => {
-  console.error(e);
-});
diff --git a/app/javascript/styles/custom.scss b/app/javascript/styles/custom.scss
deleted file mode 100644 (file)
index 97a9812..0000000
+++ /dev/null
@@ -1 +0,0 @@
-@import 'application';
diff --git a/app/javascript/themes/default/theme.yml b/app/javascript/themes/default/theme.yml
new file mode 100644 (file)
index 0000000..6a7a872
--- /dev/null
@@ -0,0 +1,9 @@
+#  (REQUIRED) Name must be unique across all installed themes.
+name: default
+
+#  (REQUIRED) The location of the pack file inside `pack_directory`.
+pack: application.js
+
+#  (OPTIONAL) The directory which contains the pack file.
+#  Defaults to the theme directory (`app/javascript/themes/[theme]`).
+pack_directory: app/javascript/packs
diff --git a/app/javascript/themes/spin/pack.js b/app/javascript/themes/spin/pack.js
new file mode 100644 (file)
index 0000000..dab0e93
--- /dev/null
@@ -0,0 +1,2 @@
+import 'packs/application';
+import 'themes/spin/style';
diff --git a/app/javascript/themes/spin/style.scss b/app/javascript/themes/spin/style.scss
new file mode 100644 (file)
index 0000000..1a9381f
--- /dev/null
@@ -0,0 +1,14 @@
+:root:root:root {
+  .button, .icon-button, .emoji-button, .account__avatar, .account__avatar-overlay {
+    animation: spin 4s linear infinite;
+  }
+}
+
+@keyframes spin {
+  from {
+    transform: rotate(0deg);
+  }
+  to {
+    transform: rotate(360deg);
+  }
+}
diff --git a/app/javascript/themes/spin/theme.yml b/app/javascript/themes/spin/theme.yml
new file mode 100644 (file)
index 0000000..a684997
--- /dev/null
@@ -0,0 +1,2 @@
+name: spin
+pack: pack.js
\ No newline at end of file
diff --git a/app/lib/themes.rb b/app/lib/themes.rb
new file mode 100644 (file)
index 0000000..2dd1882
--- /dev/null
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+require 'singleton'
+require 'yaml'
+
+class Themes
+  include Singleton
+
+  def initialize
+    result = Hash.new
+    Dir.glob(Rails.root.join('app', 'javascript', 'themes', '*', 'theme.yml')) do |path|
+      data = YAML.load_file(path)
+      if data['pack'] && data['name']
+        result[data['name']] = data
+      end
+    end
+    @conf = result
+  end
+
+  def names
+    @conf.keys
+  end
+end
index 62046ed7262a23ccfed8a183df66d8b2a3539a04..3b156b98ceee9f9d0b717e09e8824319dd3f2166 100644 (file)
@@ -25,6 +25,7 @@ class UserSettingsDecorator
     user.settings['auto_play_gif'] = auto_play_gif_preference
     user.settings['system_font_ui'] = system_font_ui_preference
     user.settings['noindex'] = noindex_preference
+    user.settings['theme'] = theme_preference
   end
 
   def merged_notification_emails
@@ -67,6 +68,10 @@ class UserSettingsDecorator
     boolean_cast_setting 'setting_noindex'
   end
 
+  def theme_preference
+    settings['setting_theme']
+  end
+  
   def boolean_cast_setting(key)
     settings[key] == '1'
   end
index 5e548c1efb0d6852eb69c183c5d4bc4642e5a3e3..3bf069a315d78acc267bde09f3b0be3a2a455b9e 100644 (file)
@@ -110,6 +110,10 @@ class User < ApplicationRecord
     settings.noindex
   end
 
+  def setting_theme
+    settings.theme
+  end
+
   def token_for_app(a)
     return nil if a.nil? || a.owner != self
     Doorkeeper::AccessToken
index a13d0702bf4833184c679bebf9af4fb5c718cd87..3b4219c561a929e37c7607e3802bd705000e508d 100644 (file)
@@ -2,8 +2,8 @@
   %meta{name: 'applicationServerKey', content: Rails.configuration.x.vapid_public_key}
   %script#initial-state{ type: 'application/json' }!= json_escape(@initial_state_json)
 
-  = javascript_pack_tag "frontends/#{@frontend}", integrity: true, crossorigin: 'anonymous'
-  = stylesheet_pack_tag "frontends/#{@frontend}", integrity: true, media: 'all'
+  = javascript_pack_tag "themes/#{current_theme}", integrity: true, crossorigin: 'anonymous'
+  = stylesheet_pack_tag "themes/#{current_theme}", integrity: true, media: 'all'
 
 .app-holder#mastodon{ data: { props: Oj.dump(default_props) } }
   %noscript
index f42f92508075effedcb2cb2cc9bf2ee680edc0ca..5efd538e4e8f3164b9e050627fd2d03beae0f484 100644 (file)
@@ -5,6 +5,8 @@
   = render 'shared/error_messages', object: current_user
 
   .fields-group
+    = f.input :setting_theme, collection: Themes.instance.names, label_method: lambda { |theme| safe_join([I18n.t("themes.#{theme}", default: theme)])}, wrapper: :with_label, include_blank: false
+
     = f.input :locale,
       collection: I18n.available_locales,
       wrapper: :with_label,
diff --git a/config/initializers/frontends.rb b/config/initializers/frontends.rb
deleted file mode 100644 (file)
index 2cb68cc..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-# Be sure to restart your server when you modify this file.
-
-Rails.application.configure do
-  frontends = []
-  Rails.root.join('app', 'javascript', 'packs', 'frontends').each_child(false) { |f| frontends.push f.to_s }
-  config.x.available_frontends = frontends
-end
index fb8524a24c0f0dffc555fc5ae577b22cb77f6d78..f9d4e2e52eeafff3bbd2d4993f1a39d084a166d7 100644 (file)
@@ -13,6 +13,7 @@ en:
           one: <span class="note-counter">1</span> character left
           other: <span class="note-counter">%{count}</span> characters left
         setting_noindex: Affects your public profile and status pages
+        setting_theme: Affects how Mastodon looks when you're logged in from any device.
       imports:
         data: CSV file exported from another Mastodon instance
       sessions:
@@ -44,6 +45,7 @@ en:
         setting_noindex: Opt-out of search engine indexing
         setting_system_font_ui: Use system's default font
         setting_unfollow_modal: Show confirmation dialog before unfollowing someone
+        setting_theme: Site theme
         severity: Severity
         type: Import type
         username: Username
index 39dfb8f552c8a708350d0fd163c45482b5e1f04e..3cd3307f40d19e6f3ec6a325a02499873e3ca82c 100644 (file)
@@ -24,6 +24,7 @@ defaults: &defaults
   auto_play_gif: false
   system_font_ui: false
   noindex: false
+  theme: 'default'
   notification_emails:
     follow: false
     reblog: false
index 6ef484c3a62917681324e6225c8e622ca6e89150..606eb97f1acff8eb525965a99a72f5bef864d459 100644 (file)
@@ -1,13 +1,27 @@
 // Common configuration for webpacker loaded from config/webpacker.yml
 
-const { join, resolve } = require('path');
+const { dirname, join, resolve } = require('path');
 const { env } = require('process');
 const { safeLoad } = require('js-yaml');
 const { readFileSync } = require('fs');
+const glob = require('glob');
 
 const configPath = resolve('config', 'webpacker.yml');
 const loadersDir = join(__dirname, 'loaders');
 const settings = safeLoad(readFileSync(configPath), 'utf8')[env.NODE_ENV];
+const themeFiles = glob.sync('app/javascript/themes/*/theme.yml');
+const themes = {};
+
+for (let i = 0; i < themeFiles.length; i++) {
+  const themeFile = themeFiles[i];
+  const data = safeLoad(readFileSync(themeFile), 'utf8');
+  if (!data.pack_directory) {
+    data.pack_directory = dirname(themeFile);
+  }
+  if (data.name && data.pack) {
+    themes[data.name] = data;
+  }
+}
 
 function removeOuterSlashes(string) {
   return string.replace(/^\/*/, '').replace(/\/*$/, '');
@@ -29,6 +43,7 @@ const output = {
 
 module.exports = {
   settings,
+  themes,
   env,
   loadersDir,
   output,
index 40e81b43b9f6de4425eebb789cb3070a3f0c3f8f..96ad7abe8c3120b2a15a45af04b33e382bf81c7a 100644 (file)
@@ -9,7 +9,7 @@ module.exports = {
       { loader: 'css-loader', options: { minimize: env.NODE_ENV === 'production' } },
       { loader: 'postcss-loader', options: { sourceMap: true } },
       'resolve-url-loader',
-      { loader: 'sass-loader', options: { includePaths: ['app/javascript/styles'] } },
+      { loader: 'sass-loader', options: { includePaths: ['app/javascript'] } },
     ],
   }),
 };
index be1b494217de38ffc5c23c88954a5225b3888327..ab925b02096e630e4b9685cc61b30aaad9328559 100644 (file)
@@ -1,13 +1,12 @@
 // Note: You must restart bin/webpack-dev-server for changes to take effect
 
-const { existsSync } = require('fs');
 const webpack = require('webpack');
 const { basename, dirname, join, relative, resolve } = require('path');
 const { sync } = require('glob');
 const ExtractTextPlugin = require('extract-text-webpack-plugin');
 const ManifestPlugin = require('webpack-manifest-plugin');
 const extname = require('path-complete-extname');
-const { env, settings, output, loadersDir } = require('./configuration.js');
+const { env, settings, themes, output, loadersDir } = require('./configuration.js');
 const localePackPaths = require('./generateLocalePacks');
 
 const extensionGlob = `**/*{${settings.extensions.join(',')}}*`;
@@ -18,17 +17,27 @@ const entryPacks = [...packPaths, ...localePackPaths].filter(path => path !== jo
 const customApplicationStyle = resolve(join(settings.source_path, 'styles/custom.scss'));
 const originalApplicationStyle = resolve(join(settings.source_path, 'styles/application.scss'));
 
+const themePaths = Object.keys(themes).reduce(
+  (themePaths, name) => {
+    themeData = themes[name];
+    themePaths[`themes/${name}`] = resolve(themeData.pack_directory, themeData.pack);
+    return themePaths;
+  }, {}
+);
+
 module.exports = {
-  entry: entryPacks.reduce(
-    (map, entry) => {
-      const localMap = map;
-      let namespace = relative(join(entryPath), dirname(entry));
-      if (namespace === join('..', '..', '..', 'tmp', 'packs')) {
-        namespace = ''; // generated by generateLocalePacks.js
-      }
-      localMap[join(namespace, basename(entry, extname(entry)))] = resolve(entry);
-      return localMap;
-    }, {}
+  entry: Object.assign(
+    entryPacks.reduce(
+      (map, entry) => {
+        const localMap = map;
+        let namespace = relative(join(entryPath), dirname(entry));
+        if (namespace === join('..', '..', '..', 'tmp', 'packs')) {
+          namespace = ''; // generated by generateLocalePacks.js
+        }
+        localMap[join(namespace, basename(entry, extname(entry)))] = resolve(entry);
+        return localMap;
+      }, {}
+    ), themePaths
   ),
 
   output: {
@@ -59,10 +68,6 @@ module.exports = {
   ],
 
   resolve: {
-    alias: {
-      'mastodon-application-style': existsSync(customApplicationStyle) ?
-                                    customApplicationStyle : originalApplicationStyle,
-    },
     extensions: settings.extensions,
     modules: [
       resolve(settings.source_path),
This page took 0.055147 seconds and 3 git commands to generate.