app/models/skyline/sections/media_section.rb in skylinecms-3.0.8 vs app/models/skyline/sections/media_section.rb in skylinecms-3.1.0
- old
+ new
@@ -1,13 +1,40 @@
# @private
class Skyline::Sections::MediaSection < ActiveRecord::Base
- include Skyline::SectionItem
- include Skyline::ContentItem
+ include Skyline::Sections::Interface
+ include Skyline::BelongsToReferable
ALIGNMENT = %w{left right block_left block_right block_center}
- referable_content :linked
-
+ # The media linked to this section
+ belongs_to_referable :media
+
+ # An optional link
+ belongs_to_referable :link
+
validates_numericality_of :width, :height, :allow_nil => true
- delegate :url, :external?, :to => :linked
+ delegate :url, :external?, :to => :media
+
+ def width
+ self.dimension[0]
+ end
+
+ def height
+ self.dimension[1]
+ end
+
+ def dimension
+ width = self[:width].to_i
+ height = self[:height].to_i
+ if self.media.present?
+ proportional = self.media.proportional_dimension(width,height)
+ if proportional
+ width,height = proportional
+ else
+ width,height = self.media.width,self.media.height
+ end
+ end
+
+ [width,height]
+ end
end