Module: Pageflow::PagesHelper

Defined in:
app/helpers/pageflow/pages_helper.rb

Constant Summary collapse

CSS_RENDERED_THUMBNAIL_STYLES =
[:link_thumbnail, :link_thumbnail_large]

Instance Method Summary collapse

Instance Method Details

#lookup_video_tag(video_id, poster_image_id, options = {}) ⇒ Object


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/helpers/pageflow/pages_helper.rb', line 64

def lookup_video_tag(video_id, poster_image_id, options = {})

  defaults = {:class => ['player video-js video-viewport vjs-default-skin', options.delete(:class)].compact * ' ',
    :preload =>  options.delete(:preload) ? 'metadata' : 'none'}

  options.reverse_merge! defaults
  url_options = {:unique_id => options.delete(:unique_id)}

  video_file = VideoFile.find_by_id(video_id)
  poster = ImageFile.find_by_id(poster_image_id)
  mobile_poster = ImageFile.find_by_id(options.delete(:mobile_poster_image_id))

  options[:data] = {}
  script_tag_data = {:template => 'video'}

  if mobile_poster
    options[:data][:mobile_poster] = mobile_poster.attachment.url(:medium)
    options[:data][:mobile_large_poster] = mobile_poster.attachment.url(:large)
  end

  if poster
    options[:data][:poster] = poster.attachment.url(:medium)
    options[:data][:large_poster] = poster.attachment.url(:large)
  elsif video_file
    options[:data][:poster] = video_file.poster.url(:medium)
    options[:data][:large_poster] = video_file.poster.url(:large)
  end

  if video_file && video_file.width.present? && video_file.height.present?
    script_tag_data[:video_width] = options[:data][:width] = video_file.width
    script_tag_data[:video_height] = options[:data][:height] = video_file.height
  end

  render('pageflow/pages/video_tag',
         :video_file => video_file, :script_tag_data => script_tag_data,
         :options => options, :url_options => url_options)
end

#mobile_poster_image_div(config = {}) ⇒ Object


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/helpers/pageflow/pages_helper.rb', line 25

def mobile_poster_image_div(config = {})
  classes = ['background', 'background_image']
  position = {x: 50, y: 50}

  if config['mobile_poster_image_id']
    classes << "image_#{config['mobile_poster_image_id']}"
    position[:x] = config['mobile_poster_image_x'] || 50
    position[:y] = config['mobile_poster_image_y'] || 50
  elsif config['poster_image_id']
    classes << "image_#{config['poster_image_id']}"
    position[:x] = config['poster_image_x'] || 50
    position[:y] = config['poster_image_y'] || 50
  elsif config['video_file_id']
    classes << "video_poster_#{config['video_file_id']}"
    position[:x] = config['video_file_x'] || 50
    position[:y] = config['video_file_y'] || 50
  else
    classes << 'video_poster_none'
  end

  (:div, '', :class => classes.join(' '),
              :style => "background-position: #{position[:x]}% #{position[:y]}%;")
end

#page_css_class(page) ⇒ Object


3
4
5
6
7
8
9
10
# File 'app/helpers/pageflow/pages_helper.rb', line 3

def page_css_class(page)
  classes = ['page']
  classes << 'invert' if page.configuration['invert']
  classes << 'hide_title' if page.configuration['hide_title']
  classes << "text_position_#{page.configuration['text_position']}" if page.configuration['text_position'].present?
  classes << 'chapter_beginning' if page.position == 0
  classes.join(' ')
end

#page_media_breakpointsObject


120
121
122
123
124
125
# File 'app/helpers/pageflow/pages_helper.rb', line 120

def page_media_breakpoints
  {
    :large => :default,
    :medium => 'max-width: 900px'
  }
end

12
13
14
15
16
17
18
# File 'app/helpers/pageflow/pages_helper.rb', line 12

def page_navigation_css_class(page)
  classes = [page.template]
  classes << 'chapter_beginning' if page.position == 0
  classes << "chapter_#{page.chapter.position}"
  page.chapter.position % 2 == 0 ? classes << 'chapter_even' : classes << 'chapter_odd'
  classes.join(' ')
end

#page_thumbnail_hero?(index, layout_name) ⇒ Boolean

Returns:

  • (Boolean)

137
138
139
140
141
142
# File 'app/helpers/pageflow/pages_helper.rb', line 137

def page_thumbnail_hero?(index, layout_name)
  index == {
    'hero_top_left' => 1,
    'hero_top_right' => 1
  }[layout_name]
end

#page_thumbnail_image_class(page, hero) ⇒ Object


152
153
154
# File 'app/helpers/pageflow/pages_helper.rb', line 152

def page_thumbnail_image_class(page, hero)
  file_thumbnail_css_class(page.thumbnail_file, hero ? :link_thumbnail : :link_thumbnail_large)
end

#page_thumbnail_item(page_ids, index, layout_name) ⇒ Object


127
128
129
130
131
132
133
134
135
# File 'app/helpers/pageflow/pages_helper.rb', line 127

def page_thumbnail_item(page_ids, index, layout_name)
  page_ids ||= {}
  page = @entry.pages.find_by_perma_id(page_ids[index.to_s])

  (:li,
              page ? page_thumbnail_link(page, page_thumbnail_hero?(index, layout_name)) : '',
              :data => {:reference_key => index},
              :class => page ? 'title_hover' : 'title_hover empty')
end

144
145
146
147
148
149
150
# File 'app/helpers/pageflow/pages_helper.rb', line 144

def page_thumbnail_link(page, hero = false)
  link_to((:span, raw(page.configuration['description']), :class => 'title'),
          "##{page.perma_id}",
          :title => page.title,
          :data => {:page => page.id},
          :class => ['thumbnail', page_thumbnail_image_class(page, hero)] * ' ')
end

#poster_image_tag(video_id, poster_image_id, options = {}) ⇒ Object


49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/helpers/pageflow/pages_helper.rb', line 49

def poster_image_tag(video_id, poster_image_id, options = {})
  video_file = VideoFile.find_by_id(video_id)
  poster = ImageFile.find_by_id(poster_image_id)

  if poster
    options = options.merge('data-src' => poster.attachment.url(:medium))
    options = options.merge('data-printsrc' => poster.attachment.url(:print))
  elsif video_file
    options = options.merge('data-src' => video_file.poster.url(:medium))
    options = options.merge('data-printsrc' => video_file.poster.url(:print))
  end

  image_tag('', options)
end

#shadow_div(options = {}) ⇒ Object


20
21
22
23
# File 'app/helpers/pageflow/pages_helper.rb', line 20

def shadow_div(options = {})
  style = options[:opacity] ? "opacity: #{options[:opacity] / 100.0};" : nil
  (:div, '', :class => 'shadow', :style => style)
end

#video_file_sources(video_file, options = {}) ⇒ Object


102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'app/helpers/pageflow/pages_helper.rb', line 102

def video_file_sources(video_file, options = {})
  [{
      :type => 'video/webm',
      :src => video_file.webm_medium.url(options),
      :high_src => video_file.webm_high.url(options)
    },
    {
      :type => 'application/x-mpegURL',
      :src => video_file.hls_playlist.url(options),
      :high_src => video_file.hls_playlist.url(options)
    },
    {
      :type => 'video/mp4',
      :src => video_file.mp4_medium.url(options),
      :high_src => video_file.mp4_high.url(options)
    }]
end