Class: Workarea::Storefront::ContentBlocks::SuperHeroViewModel

Inherits:
ContentBlockViewModel
  • Object
show all
Defined in:
app/view_models/workarea/storefront/content_blocks/super_hero_view_model.rb

Instance Method Summary collapse

Instance Method Details

#alt_textObject



29
30
31
# File 'app/view_models/workarea/storefront/content_blocks/super_hero_view_model.rb', line 29

def alt_text
  model.data[:alt_text].presence
end

#breakpointsObject



21
22
23
# File 'app/view_models/workarea/storefront/content_blocks/super_hero_view_model.rb', line 21

def breakpoints
  Workarea.config.storefront_break_points
end

#content_classObject



60
61
62
63
64
65
66
# File 'app/view_models/workarea/storefront/content_blocks/super_hero_view_model.rb', line 60

def content_class
  content_class = 'content-position '
  model.data[:content_position].split(',').each do |pos|
    content_class << "content-position--#{pos.optionize} "
  end
  return content_class
end

#content_stylesObject



68
69
70
71
72
73
74
75
# File 'app/view_models/workarea/storefront/content_blocks/super_hero_view_model.rb', line 68

def content_styles
  background_color = ColorTools.new(
    hex: model.data[:background_color],
    alpha: model.data[:background_alpha]
  )

  "color: #{model.data[:text_color]}; background-color: rgba(#{background_color.rgba});"
end

#imageObject



25
26
27
# File 'app/view_models/workarea/storefront/content_blocks/super_hero_view_model.rb', line 25

def image
  @image ||= find_asset(data[:asset])
end

#image_medium_urlObject



5
6
7
8
9
10
11
# File 'app/view_models/workarea/storefront/content_blocks/super_hero_view_model.rb', line 5

def image_medium_url
  if data[:asset_medium].present?
    find_asset(data[:asset_medium]).url
  else
    image.url
  end
end

#image_small_urlObject



13
14
15
16
17
18
19
# File 'app/view_models/workarea/storefront/content_blocks/super_hero_view_model.rb', line 13

def image_small_url
  if data[:asset_small].present?
    find_asset(data[:asset_small]).url
  else
    image.url
  end
end

#media_classObject



33
34
35
36
37
38
39
# File 'app/view_models/workarea/storefront/content_blocks/super_hero_view_model.rb', line 33

def media_class
  if model.data[:media_mode] == 'crop'
    "crop super-hero-content-block__media--crop-#{model.data[:crop_side]}"
  else
    model.data[:media_mode]
  end
end

#media_stylesObject



41
42
43
44
45
46
47
# File 'app/view_models/workarea/storefront/content_blocks/super_hero_view_model.rb', line 41

def media_styles
  if model.data[:media_mode] == 'resize'
    "padding-bottom: #{image.file_inverse_aspect_ratio * 100}%"
  elsif model.data[:media_mode] == 'crop'
    "padding-bottom: #{image.height}px"
  end
end

#video_iframe_attrsObject



49
50
51
52
53
54
55
56
57
58
# File 'app/view_models/workarea/storefront/content_blocks/super_hero_view_model.rb', line 49

def video_iframe_attrs
  return unless model.data[:video].present?
  embed_code = VideoEmbedder.new(
    model.data[:video],
    autoplay: model.data[:autoplay],
    loop_playback: model.data[:loop],
    mute: model.data[:mute]
  )
  embed_code.iframe_attrs
end