2015-08-25 01:26:36 -07:00
|
|
|
class Theme < ActiveRecord::Base
|
|
|
|
include ThemeHelper
|
|
|
|
|
|
|
|
belongs_to :user
|
|
|
|
|
|
|
|
validates_numericality_of :primary_color, :primary_text,
|
|
|
|
:danger_color, :danger_text,
|
|
|
|
:success_color, :success_text,
|
|
|
|
:warning_color, :warning_text,
|
|
|
|
:info_color, :info_text,
|
|
|
|
:default_color, :default_text,
|
|
|
|
:panel_color, :panel_text,
|
|
|
|
:link_color, :background_color,
|
|
|
|
:background_text, :background_muted,
|
2015-08-26 16:56:07 -07:00
|
|
|
:input_color, :input_text,
|
|
|
|
:outline_color,
|
2015-08-25 01:26:36 -07:00
|
|
|
greater_than_or_equal_to: 0, less_than_or_equal_to: 0xFFFFFF,
|
|
|
|
allow_nil: true, only_integer: true
|
|
|
|
|
2015-08-25 12:34:40 -07:00
|
|
|
has_attached_file :css, use_timestamp: false, s3_headers: {
|
2015-08-25 13:14:17 -07:00
|
|
|
'Content-Type' => 'text/css'
|
2015-08-25 12:33:57 -07:00
|
|
|
}, fog_file: {
|
2015-08-25 13:14:17 -07:00
|
|
|
content_type: 'text/css'
|
2015-08-25 12:33:57 -07:00
|
|
|
}
|
2015-08-25 12:54:07 -07:00
|
|
|
validates_attachment_content_type :css, content_type: /^text\//
|
2015-08-25 11:27:06 -07:00
|
|
|
|
2015-08-25 01:26:36 -07:00
|
|
|
before_save do
|
2015-08-25 11:27:06 -07:00
|
|
|
self.css = nil
|
|
|
|
|
2015-08-25 13:56:47 -07:00
|
|
|
style = StringIO.new(render_theme_with_context(self))
|
2015-08-25 11:27:06 -07:00
|
|
|
|
2015-08-25 13:56:47 -07:00
|
|
|
style.class.class_eval { attr_accessor :original_filename, :content_type }
|
2015-08-25 01:26:36 -07:00
|
|
|
|
2015-08-25 13:56:47 -07:00
|
|
|
style.content_type = 'text/css'
|
|
|
|
style.original_filename = 'theme.css'
|
2015-08-25 13:11:30 -07:00
|
|
|
|
2015-08-25 13:56:47 -07:00
|
|
|
self.css = style
|
2015-08-25 01:26:36 -07:00
|
|
|
end
|
2015-08-26 16:56:07 -07:00
|
|
|
|
|
|
|
def theme_color
|
|
|
|
('#' + ('0000000' + primary_color.to_s(16))[-6, 6])
|
|
|
|
end
|
2015-08-25 01:26:36 -07:00
|
|
|
end
|