Retrospring/app/models/theme.rb

38 lines
1010 B
Ruby
Raw Normal View History

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,
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\//
before_save do
self.css = nil
2015-08-25 13:11:30 -07:00
style = ThemeIO.new(render_theme_with_context(self))
2015-08-25 13:11:30 -07:00
style.instance_variable_set '@content_type', 'text/css'
self.css = style
2015-08-25 13:11:30 -07:00
self.css.instance_write :content_type, 'text/css'
2015-08-25 13:13:08 -07:00
self.css_content_type = 'text/css'
end
end