Class: Cms::Asset
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Cms::Asset
- Includes:
- Taggable
- Defined in:
- app/models/cms/asset.rb
Defined Under Namespace
Classes: Meta
Class Method Summary collapse
Instance Method Summary collapse
- #assign_ordered_attributes(params) ⇒ Object
- #editable? ⇒ Boolean
- #file_content ⇒ Object
- #file_content=(content) ⇒ Object
- #icon? ⇒ Boolean
- #image? ⇒ Boolean
- #meta ⇒ Object
- #meta=(data) ⇒ Object
- #to_liquid ⇒ Object
- #to_s ⇒ Object
Methods included from Taggable
Class Method Details
.context_tags(context) ⇒ Object
66 67 68 69 70 71 72 |
# File 'app/models/cms/asset.rb', line 66 def self.(context) if context Tag.all :joins => 'inner join taggings on taggings.tag_id = tags.id inner join cms_assets on taggings.taggable_id = cms_assets.id', :conditions => {'cms_assets.context_id' => context.id} else Tag.all end end |
Instance Method Details
#assign_ordered_attributes(params) ⇒ Object
58 59 60 61 62 63 64 |
# File 'app/models/cms/asset.rb', line 58 def assign_ordered_attributes(params) # force the custom dimensions to be assigned first so that when the asset is assigned, the custom dims are present # if the custom dims aren't set before the asset is assigned, the custom size won't be generated properly # this can occur if the attribute hash is iterated with the asset coming before the dims self.attributes = params.slice(:custom_height, :custom_width) self.attributes = params end |
#editable? ⇒ Boolean
83 84 85 |
# File 'app/models/cms/asset.rb', line 83 def editable? Cms::Component.editable?(asset_file_name) end |
#file_content ⇒ Object
87 88 89 |
# File 'app/models/cms/asset.rb', line 87 def file_content read end |
#file_content=(content) ⇒ Object
91 92 93 |
# File 'app/models/cms/asset.rb', line 91 def file_content=(content) write content end |
#icon? ⇒ Boolean
78 79 80 81 |
# File 'app/models/cms/asset.rb', line 78 def icon? # accepts ico or icon !(asset_content_type =~ /icon?$/).blank? end |
#image? ⇒ Boolean
74 75 76 |
# File 'app/models/cms/asset.rb', line 74 def image? !(asset_content_type =~ /^image.*/).blank? end |
#meta ⇒ Object
95 96 97 98 |
# File 'app/models/cms/asset.rb', line 95 def return @_meta if @_meta.present? @_meta = ( || []).collect{|m| Meta.new(m)} end |
#meta=(data) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/models/cms/asset.rb', line 100 def (data) # reset the cached meta collection @_meta = nil # data ex: # {"new_1301457489798"=>{"name"=>"test1", "value"=>"test1"}, "new_1301457493800"=>{"name"=>"test2", "value"=>"test2"}} # converted to: # [{"name"=>"test1", "value"=>"test1"}, {"name"=>"test2", "value"=>"test2"}] # strip spaces of name and value temp_data = data.to_a.sort{|a,b| a.first <=> b.first}.collect{|a| h = a[1]; {:name => h[:name].strip, :value => h[:value].strip} } # remove any elements that have both name and value blank temp_data = temp_data.reject{|d| d[:name].blank? && d[:value].blank?} self. = temp_data end |
#to_liquid ⇒ Object
116 117 118 |
# File 'app/models/cms/asset.rb', line 116 def to_liquid Cms::AssetDrop.new(self) end |
#to_s ⇒ Object
54 55 56 |
# File 'app/models/cms/asset.rb', line 54 def to_s asset_file_name end |