Class: Locomotive::ThemeAsset

Inherits:
Object
  • Object
show all
Includes:
Extensions::Asset::Types, Mongoid::Document
Defined in:
app/models/locomotive/theme_asset.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#performing_plain_textObject

accessors ##



42
43
44
# File 'app/models/locomotive/theme_asset.rb', line 42

def performing_plain_text
  @performing_plain_text
end

#plain_textObject

accessors ##



42
43
44
# File 'app/models/locomotive/theme_asset.rb', line 42

def plain_text
  @plain_text
end

#plain_text_nameObject

accessors ##



42
43
44
# File 'app/models/locomotive/theme_asset.rb', line 42

def plain_text_name
  @plain_text_name
end

#plain_text_typeObject

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

Returns:



84
85
86
# File 'app/models/locomotive/theme_asset.rb', line 84

def performing_plain_text?
  Boolean.set(self.performing_plain_text) || false
end

#siteObject

validations ##



19
# File 'app/models/locomotive/theme_asset.rb', line 19

belongs_to :site, :class_name => 'Locomotive::Site'

#site_idObject

indexes ##



22
# File 'app/models/locomotive/theme_asset.rb', line 22

index :site_id

#store_plain_textObject



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 ##

Returns:



47
48
49
# File 'app/models/locomotive/theme_asset.rb', line 47

def stylesheet_or_javascript?
  self.stylesheet? || self.javascript?
end

#to_liquidObject



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