ThemeHelper.render_theme_with_context

This commit is contained in:
Yuki 2015-07-29 22:24:33 +05:30
parent aec452cbd1
commit 47344a5774
3 changed files with 37 additions and 9 deletions

View File

@ -1,4 +1,6 @@
class UserController < ApplicationController
include ThemeHelper
before_filter :authenticate_user!, only: %w(edit update edit_privacy update_privacy data)
def show
@ -92,15 +94,7 @@ class UserController < ApplicationController
def data
end
SCSS_STYLE = if Rails.env == 'production'
:compressed
else
:compact
end.freeze
def theme
txt = render_to_string 'user/theme.css.scss', formats: [:erb]
sass = Sass::Engine.new txt, style: SCSS_STYLE, cache: false, load_paths: [], syntax: :scss
render body: sass.render.to_s, content_type: 'text/css'
render body: render_theme_with_context, content_type: 'text/css'
end
end

View File

@ -0,0 +1,31 @@
module ThemeHelper
def render_theme_with_context(context = {})
klass = Class.new do
def initialize(hash = {})
if hash.is_a? ActiveRecord::Base
hash = hash.serializable_hash
end
if hash.is_a? Hash
hash.each do |k, v|
self.instance_variable_set "@#{k}", v
end
end
end
def render
style = if Rails.env == 'production'
:compressed
else
:compact
end.freeze
erb = ERB.new File.read Rails.root.join 'app/views/user/theme.css.scss.erb'
sass = Sass::Engine.new erb.result(binding), style: style, cache: false, load_paths: [], syntax: :scss
return sass.render.to_s
end
end
return klass.new(context).render
end
end

View File

@ -1,3 +1,5 @@
// TODO: Use canonical colours rather than this test midnight scheme.
// PRIMARY COLOR
$primary_color: <%= @primary_color || "#222222" %>;
$primary_border: <%= @primary_border || "#151515" %>;
@ -28,6 +30,7 @@ $color_color: <%= @color_color || "#222222" %>;
$color_border: <%= @color_border || "#151515" %>;
$color_text: <%= @color_text || "#eeeeee" %>;
// PANEL COLORS
// AUXILIARY COLOR
$link_color: <%= @link_color || "#111111" %>;