From a7c3acea76c84682a1791670555a842c65ae3c84 Mon Sep 17 00:00:00 2001 From: Yuki Date: Wed, 26 Aug 2015 02:14:14 +0530 Subject: [PATCH] ISHYGDDT --- app/controllers/user_controller.rb | 2 +- app/helpers/theme_helper.rb | 10 ------- config/late_initializers/costanza.rb | 41 ++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 config/late_initializers/costanza.rb diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 525f3230..92a3b601 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -1,7 +1,7 @@ class UserController < ApplicationController include ThemeHelper - before_filter :authenticate_user!, only: %w(edit update edit_privacy update_privacy data) + before_filter :authenticate_user!, only: %w(edit update edit_privacy update_privacy edit_theme update_theme preview_theme data) def show @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first! diff --git a/app/helpers/theme_helper.rb b/app/helpers/theme_helper.rb index 679221f1..019c13d1 100644 --- a/app/helpers/theme_helper.rb +++ b/app/helpers/theme_helper.rb @@ -1,14 +1,4 @@ module ThemeHelper - class ThemeIO < StringIO - def content_type - 'text/css' - end - - def original_filename - 'theme.css' - end - end - def render_theme_with_context(context = {}) klass = Class.new do def initialize(hash = {}) diff --git a/config/late_initializers/costanza.rb b/config/late_initializers/costanza.rb new file mode 100644 index 00000000..d2aba2c6 --- /dev/null +++ b/config/late_initializers/costanza.rb @@ -0,0 +1,41 @@ +# I seriously hope you guys don't do this. + +class Paperclip::FileCommandContentTypeDetector + alias stupid_type_from_file_command type_from_file_command + def type_from_file_command + default = stupid_type_from_file_command + if default == 'text/x-c' and File.extname(@filename) == '.css' + 'text/css' + else + default + end + end +end + +class ThemeIO < StringIO + def content_type + 'text/css' + end + + def original_filename + 'theme.css' + end +end + +class ThemeAdapter < Paperclip::StringioAdapter + def cache_current_values + @content_type = 'text/css' + @original_filename = 'theme.css' + @size = @target.size + end + + def extension_for(x) + 'css' + end +end + +Paperclip.io_adapters.register ThemeAdapter do |target| + ThemeIO === target +end + +# Here be monkey patches.