1 module CollectionsHelper
4 {source: x.tail_uuid, target: x.head_uuid, type: x.name}
9 # Regex match for collection UUIDs, returns a regex match object with the
10 # hash in group 1, (optional) size in group 2, (optional) subsequent uuid
11 # fields in group 3, and (optional) file path within the collection as group
12 # 4; or nil for no match.
14 # +uuid+ the uuid string to match
17 /^([a-f0-9]{32})(\+[0-9]+)?(\+.*?)?(\/.*)?$/.match(uuid.to_s)
21 # Regex match for common image file extensions, returns a regex match object
22 # with the matched extension in group 1; or nil for no match.
24 # +file+ the file string to match
26 def self.is_image file
27 /\.(jpg|jpeg|gif|png|svg)$/i.match(file)
31 # Generates a relative file path than can be appended to the URL of a
32 # collection to get a file download link without adding a spurious ./ at the
33 # beginning for files in the default stream.
35 # +file+ an entry in the Collection.files list in the form [stream, name, size]
37 def self.file_path file
40 f0 = f0[2..-1] if f0[0..1] == './'
41 f0 += '/' if not f0.empty?
42 file_path = "#{f0}#{file[1]}"