Module: EL::FinderHelpers
- Defined in:
- lib/el-finder/el-finder.rb
Constant Summary collapse
- ASSETS_PATH =
File.('../../../assets', __FILE__).freeze
- ASSETS_EXT =
'.el-finder'.freeze
- ASSETS_REGEXP =
/#{Regexp.escape ASSETS_EXT}\Z/.freeze
- IMAGE_FILES =
image_files.concat(image_files.map(&:upcase)).freeze
- VIDEO_FILES =
video_files.concat(video_files.map(&:upcase)).freeze
Instance Method Summary collapse
- #asset_url(file) ⇒ Object
- #browseable?(file) ⇒ Boolean
-
#editable?(file) ⇒ Boolean
TODO: find a more cross-platform way of detecting editable files.
-
#image?(file) ⇒ Boolean
Array#include is slow enough, so building a Hash on first request then using hash lookup which is a lot faster.
- #parent_route(action = nil, params = {}) ⇒ Object
- #root ⇒ Object
- #video?(file) ⇒ Boolean
Instance Method Details
#asset_url(file) ⇒ Object
195 196 197 |
# File 'lib/el-finder/el-finder.rb', line 195 def asset_url file route(:assets, file + self.class::ASSETS_EXT) end |
#browseable?(file) ⇒ Boolean
181 182 183 |
# File 'lib/el-finder/el-finder.rb', line 181 def browseable? file image?(file) || video?(file) end |
#editable?(file) ⇒ Boolean
TODO: find a more cross-platform way of detecting editable files
167 168 169 |
# 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) ⇒ Boolean
Array#include is slow enough, so building a Hash on first request then using hash lookup which is a lot faster
173 174 175 |
# 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 = {}) ⇒ Object
185 186 187 188 189 |
# 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 ⇒ Object
191 192 193 |
# File 'lib/el-finder/el-finder.rb', line 191 def root env[:ROOT].to_s end |
#video?(file) ⇒ Boolean
177 178 179 |
# File 'lib/el-finder/el-finder.rb', line 177 def video? file (@@video_files ||= Hash[VIDEO_FILES.zip(VIDEO_FILES)])[File.extname(file)] end |