Module: FacebookCoverResize::ViewHelpers

Defined in:
lib/facebook_cover_resize/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#account_cover_tag(args) ⇒ Object



7
8
9
# File 'lib/facebook_cover_resize/view_helpers.rb', line 7

def (args)
  tag_generator(args.update(ratio: 2.66))
end

#event_cover_tag(args) ⇒ Object



3
4
5
# File 'lib/facebook_cover_resize/view_helpers.rb', line 3

def event_cover_tag(args)
  tag_generator(args.update(ratio: 1.91))
end

#tag_generator(args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/facebook_cover_resize/view_helpers.rb', line 11

def tag_generator(args)
  dims = FacebookCoverResize.compute(original: args[:original], offsets: args[:offsets], width: args[:width], ratio: args[:ratio])
  width = args[:width].to_i
  height = (width / args[:ratio]).ceil
  source = args[:source]

  (:div,
    image_tag(source,
      style: "position: absolute !important;top: #{dims[0]}px !important;left: #{dims[1]}px !important;width: #{dims[2]}px !important;height:#{dims[3]}px !important; margin: 0 !important"
    ),
    style: "width: #{width}px !important; height: #{height}px !important; overflow: hidden !important;position: relative !important; padding:0 !important"
  )
end