Class: Locomotive::ThemeAsset
- Inherits:
-
Object
- Object
- Locomotive::ThemeAsset
- Includes:
- Extensions::Asset::Types, Mongoid::Document
- Defined in:
- app/models/locomotive/theme_asset.rb
Instance Attribute Summary collapse
-
#performing_plain_text ⇒ Object
accessors ##.
-
#plain_text ⇒ Object
accessors ##.
-
#plain_text_name ⇒ Object
accessors ##.
-
#plain_text_type ⇒ Object
accessors ##.
Class Method Summary collapse
Instance Method Summary collapse
-
#local_path(short = false) ⇒ Object
fields ##.
- #performing_plain_text? ⇒ Boolean
-
#site ⇒ Object
validations ##.
-
#site_id ⇒ Object
indexes ##.
- #store_plain_text ⇒ Object
-
#stylesheet_or_javascript? ⇒ Boolean
methods ##.
- #to_liquid ⇒ Object
Instance Attribute Details
#performing_plain_text ⇒ Object
accessors ##
42 43 44 |
# File 'app/models/locomotive/theme_asset.rb', line 42 def performing_plain_text @performing_plain_text end |
#plain_text ⇒ Object
accessors ##
42 43 44 |
# File 'app/models/locomotive/theme_asset.rb', line 42 def plain_text @plain_text end |
#plain_text_name ⇒ Object
accessors ##
42 43 44 |
# File 'app/models/locomotive/theme_asset.rb', line 42 def plain_text_name @plain_text_name end |
#plain_text_type ⇒ Object
accessors ##
42 43 44 |
# File 'app/models/locomotive/theme_asset.rb', line 42 def plain_text_type @plain_text_type end |
Class Method Details
.all_grouped_by_folder(site) ⇒ Object
107 108 109 110 |
# File 'app/models/locomotive/theme_asset.rb', line 107 def self.all_grouped_by_folder(site) assets = site.theme_assets.order_by([[:slug, :asc]]) assets.group_by { |a| a.folder.split('/').first.to_sym } end |
Instance Method Details
#local_path(short = false) ⇒ Object
fields ##
10 |
# File 'app/models/locomotive/theme_asset.rb', line 10 field :local_path |
#performing_plain_text? ⇒ Boolean
84 85 86 |
# File 'app/models/locomotive/theme_asset.rb', line 84 def performing_plain_text? Boolean.set(self.performing_plain_text) || false end |
#site ⇒ Object
validations ##
19 |
# File 'app/models/locomotive/theme_asset.rb', line 19 belongs_to :site, :class_name => 'Locomotive::Site' |
#site_id ⇒ Object
indexes ##
22 |
# File 'app/models/locomotive/theme_asset.rb', line 22 index :site_id |
#store_plain_text ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/models/locomotive/theme_asset.rb', line 88 def store_plain_text return if self.persisted? && !self.stylesheet_or_javascript? self.content_type ||= @plain_text_type if self.performing_plain_text? data = self.performing_plain_text? ? self.plain_text : self.source.read return if !self.stylesheet_or_javascript? || self.plain_text_name.blank? || data.blank? sanitized_source = self.escape_shortcut_urls(data) self.source = ::CarrierWave::SanitizedFile.new({ :tempfile => StringIO.new(sanitized_source), :filename => "#{self.plain_text_name}.#{self.stylesheet? ? 'css' : 'js'}" }) @plain_text = sanitized_source # no need to reset the plain_text instance variable to have the last version end |
#stylesheet_or_javascript? ⇒ Boolean
methods ##
47 48 49 |
# File 'app/models/locomotive/theme_asset.rb', line 47 def stylesheet_or_javascript? self.stylesheet? || self.javascript? end |
#to_liquid ⇒ Object
112 113 114 |
# File 'app/models/locomotive/theme_asset.rb', line 112 def to_liquid { :url => self.source.url }.merge(self.attributes).stringify_keys end |