1 module CollectionsHelper
4 {source: x.tail_uuid, target: x.head_uuid, type: x.name}
9 # Regex match for collection portable data hash, 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
13 # returns nil for no match.
15 # +pdh+ the portable data hash string to match
18 /^([a-f0-9]{32})(\+\d+)(\+[^+]+)*?(\/.*)?$/.match(pdh.to_s)
22 # Regex match for collection UUIDs, returns a regex match object with the
23 # uuid in group 1, empty groups 2 and 3 (for consistency with the match
24 # method above), and (optional) file path within the collection as group
26 # returns nil for no match.
28 def self.match_uuid_with_optional_filepath(uuid_with_optional_file)
29 /^([0-9a-z]{5}-4zz18-[0-9a-z]{15})()()(\/.*)?$/.match(uuid_with_optional_file.to_s)
33 # Regex match for common image file extensions, returns a regex match object
34 # with the matched extension in group 1; or nil for no match.
36 # +file+ the file string to match
38 def self.is_image file
39 /\.(jpg|jpeg|gif|png|svg)$/i.match(file)
43 # Generates a relative file path than can be appended to the URL of a
44 # collection to get a file download link without adding a spurious ./ at the
45 # beginning for files in the default stream.
47 # +file+ an entry in the Collection.files list in the form [stream, name, size]
49 def self.file_path file
52 f0 = f0[2..-1] if f0[0..1] == './'
53 f0 += '/' if not f0.empty?
54 file_path = "#{f0}#{file[1]}"
58 # Check if collection preview is allowed for the given filename with extension
60 def preview_allowed_for file_name
61 file_type = MIME::Types.type_for(file_name).first
64 elsif (file_type.raw_media_type == "text") || (file_type.raw_media_type == "image")
66 elsif (file_type.raw_media_type == "application") &&
67 (Rails.configuration.application_mimetypes_with_view_icon.include? (file_type.sub_type))