Module: Pageflow::FilesHelper

Includes:
RenderJsonHelper
Included in:
Editor::FilesHelper, EntryJsonSeedHelper
Defined in:
app/helpers/pageflow/files_helper.rb

Overview

Format and generate seed data for files

Constant Summary

Constants included from RenderJsonHelper

RenderJsonHelper::ESCAPED_CHARS, RenderJsonHelper::ESCAPED_CHARS_REGEX

Instance Method Summary collapse

Methods included from RenderJsonHelper

#render_html_partial, #render_json, #render_json_partial, #render_json_seed, #sanitize_json

Instance Method Details

#file_dimensions(file) ⇒ Object



10
11
12
13
14
15
16
# File 'app/helpers/pageflow/files_helper.rb', line 10

def file_dimensions(file)
  if file.width && file.height
    "#{file.width} x #{file.height}px"
  else
    "-"
  end
end

#file_duration(file) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/pageflow/files_helper.rb', line 18

def file_duration(file)
  if file.duration_in_ms
    total_seconds = file.duration_in_ms / 1000
    seconds = total_seconds % 60
    minutes = (total_seconds / 60) % 60
    hours = total_seconds / (60 * 60)

    format("%02d:%02d:%02d", hours, minutes, seconds)
  else
    "-"
  end
end

#file_format(file) ⇒ Object



6
7
8
# File 'app/helpers/pageflow/files_helper.rb', line 6

def file_format(file)
  file.format.presence || '-'
end

#files_json_seed(json, entry) ⇒ Object

Render seed data for all files of the revision.

Parameters:

Since:

  • 15.1



36
37
38
39
40
41
42
43
44
# File 'app/helpers/pageflow/files_helper.rb', line 36

def files_json_seed(json, entry)
  Pageflow.config.file_types.each do |file_type|
    json.set!(file_type.collection_name) do
      json.array!(entry.find_files(file_type.model)) do |file|
        json.partial!('pageflow/files/file', file: file, file_type: file_type)
      end
    end
  end
end