about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorDavid Yip <yipdw@member.fsf.org>2017-11-17 14:01:23 -0600
committerGitHub <noreply@github.com>2017-11-17 14:01:23 -0600
commit45f18b8f494153fd63871d60782da992e847ec16 (patch)
tree82b4be5028ec4c8e066c69bdf068ac786104508f /app
parent2a386ad88dad4a076f19dbd1b085ea561868deec (diff)
parent585758a373df05127b0d544ac5971ef67f053e83 (diff)
Merge pull request #218 from glitch-soc/themed-prefetching
Themed preloading
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application_controller.rb5
-rw-r--r--app/controllers/home_controller.rb1
-rw-r--r--app/javascript/themes/default/theme.yml17
-rw-r--r--app/lib/themes.rb9
-rw-r--r--app/views/home/index.html.haml7
5 files changed, 28 insertions, 11 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index a213302cb..f5dbe837e 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -13,6 +13,7 @@ class ApplicationController < ActionController::Base
   helper_method :current_account
   helper_method :current_session
   helper_method :current_theme
+  helper_method :theme_data
   helper_method :single_user_mode?
 
   rescue_from ActionController::RoutingError, with: :not_found
@@ -88,6 +89,10 @@ class ApplicationController < ActionController::Base
     current_user.setting_theme
   end
 
+  def theme_data
+    Themes.instance.get(current_theme)
+  end
+
   def cache_collection(raw, klass)
     return raw unless klass.respond_to?(:with_includes)
 
diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb
index ad7f09f34..21dde20ce 100644
--- a/app/controllers/home_controller.rb
+++ b/app/controllers/home_controller.rb
@@ -6,7 +6,6 @@ class HomeController < ApplicationController
 
   def index
     @body_classes = 'app-body'
-    @frontend     = (params[:frontend] and Rails.configuration.x.available_frontends.include? params[:frontend] + '.js') ? params[:frontend] : 'mastodon'
   end
 
   private
diff --git a/app/javascript/themes/default/theme.yml b/app/javascript/themes/default/theme.yml
index 6a7a872b4..0b262cc82 100644
--- a/app/javascript/themes/default/theme.yml
+++ b/app/javascript/themes/default/theme.yml
@@ -1,9 +1,18 @@
-#  (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]`).
+#  Defaults to the theme directory (`app/javascript/themes/[theme]`),
+#  but in the case of the vanilla Mastodon theme the pack file is
+#  somewhere else.
 pack_directory: app/javascript/packs
+
+#  (OPTIONAL) Additional javascript resources to preload, for use with
+#  lazy-loaded components. It is **STRONGLY RECOMMENDED** that you
+#  derive these pathnames from `themes/[your-theme]` to ensure that
+#  they stay unique. (Of course, vanilla doesn't do this ^^;;)
+preload:
+- features/getting_started
+- features/compose
+- features/home_timeline
+- features/notifications
diff --git a/app/lib/themes.rb b/app/lib/themes.rb
index 2dd188297..f7ec22fd2 100644
--- a/app/lib/themes.rb
+++ b/app/lib/themes.rb
@@ -10,13 +10,18 @@ class Themes
     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
+      name = File.basename(File.dirname(path))
+      if data['pack']
+        result[name] = data
       end
     end
     @conf = result
   end
 
+  def get(name)
+    @conf[name]
+  end
+
   def names
     @conf.keys
   end
diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml
index 878ffb032..63b3a0c26 100644
--- a/app/views/home/index.html.haml
+++ b/app/views/home/index.html.haml
@@ -1,8 +1,7 @@
 - content_for :header_tags do
-  %link{ href: asset_pack_path('features/getting_started.js'), crossorigin: 'anonymous', rel: 'preload', as: 'script' }/
-  %link{ href: asset_pack_path('features/compose.js'), crossorigin: 'anonymous', rel: 'preload', as: 'script' }/
-  %link{ href: asset_pack_path('features/home_timeline.js'), crossorigin: 'anonymous', rel: 'preload', as: 'script' }/
-  %link{ href: asset_pack_path('features/notifications.js'), crossorigin: 'anonymous', rel: 'preload', as: 'script' }/
+  - if theme_data['preload']
+    - theme_data['preload'].each do |link|
+      %link{ href: asset_pack_path("#{link}.js"), crossorigin: 'anonymous', rel: 'preload', as: 'script' }/
   %meta{name: 'applicationServerKey', content: Rails.configuration.x.vapid_public_key}
   %script#initial-state{ type: 'application/json' }!= json_escape(@initial_state_json)