module EL::FinderHelpers
Constants
- ASSETS_EXT
- ASSETS_PATH
- ASSETS_REGEXP
- IMAGE_FILES
- VIDEO_FILES
Public Instance Methods
asset_url(file)
click to toggle source
# File lib/el-finder/el-finder.rb, line 195 def asset_url file route(:assets, file + self.class::ASSETS_EXT) end
browseable?(file)
click to toggle source
# File lib/el-finder/el-finder.rb, line 181 def browseable? file image?(file) || video?(file) end
editable?(file)
click to toggle source
TODO: find a more cross-platform way of detecting editable files
# File lib/el-finder/el-finder.rb, line 167 def editable? file %x[file -b --mime "#{file}"].split(';').first.to_s =~ /text|empty/i end
image?(file)
click to toggle source
Array#include is slow enough, so building a Hash on first request then using hash lookup which is a lot faster
# File lib/el-finder/el-finder.rb, line 173 def image? file (@@image_files ||= Hash[IMAGE_FILES.zip(IMAGE_FILES)])[File.extname(file)] end
parent_route(action = nil, params = {})
click to toggle source
# File lib/el-finder/el-finder.rb, line 185 def parent_route(action = nil, params = {}) action.is_a?(Hash) && (params = action) && (action = nil) params = params.merge(action: action.to_s) if action env[:PARENT_ROUTE] + (params.any? ? '?' << build_nested_query(params) : '') end
root()
click to toggle source
# File lib/el-finder/el-finder.rb, line 191 def root env[:ROOT].to_s end
video?(file)
click to toggle source
# File lib/el-finder/el-finder.rb, line 177 def video? file (@@video_files ||= Hash[VIDEO_FILES.zip(VIDEO_FILES)])[File.extname(file)] end