el_finder 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +23 -0
- data/History.txt +19 -0
- data/Manifest.txt +22 -0
- data/README.txt +98 -0
- data/Rakefile +13 -0
- data/lib/el_finder.rb +11 -0
- data/lib/el_finder/connector.rb +342 -0
- data/lib/el_finder/image_resize.rb +14 -0
- data/lib/el_finder/image_size.rb +17 -0
- data/lib/el_finder/mime_type.rb +78 -0
- data/lib/el_finder/pathname.rb +47 -0
- data/test/files/README.txt +2 -0
- data/test/files/elfinder.png +0 -0
- data/test/files/foo/philip.txt +1 -0
- data/test/files/foo/sam.txt +1 -0
- data/test/files/foo/sandy.txt +1 -0
- data/test/files/foo/tom.txt +1 -0
- data/test/files/pjkh.png +0 -0
- data/test/test_el_finder.rb +265 -0
- data/test/test_el_finder_image_size.rb +23 -0
- data/test/test_el_finder_mime_type.rb +30 -0
- data/test/test_el_finder_pathname.rb +76 -0
- metadata +144 -0
data/.autotest
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'autotest/restart'
|
4
|
+
|
5
|
+
# Autotest.add_hook :initialize do |at|
|
6
|
+
# at.extra_files << "../some/external/dependency.rb"
|
7
|
+
#
|
8
|
+
# at.libs << ":../some/external"
|
9
|
+
#
|
10
|
+
# at.add_exception 'vendor'
|
11
|
+
#
|
12
|
+
# at.add_mapping(/dependency.rb/) do |f, _|
|
13
|
+
# at.files_matching(/test_.*rb$/)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# %w(TestA TestB).each do |klass|
|
17
|
+
# at.extra_class_map[klass] = "test/test_misc.rb"
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
|
21
|
+
# Autotest.add_hook :run_command do |at|
|
22
|
+
# system "rake build"
|
23
|
+
# end
|
data/History.txt
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
CHANGELOG
|
2
|
+
|
3
|
+
2010-10-15 Philip Hallstrom
|
4
|
+
|
5
|
+
* update manifest
|
6
|
+
* test each of the connector methods
|
7
|
+
* use base64 encode/decode for hash to get around javascript unfriendly characters
|
8
|
+
* add image size/resize handling
|
9
|
+
* almost functionally complete
|
10
|
+
* migrate over alpha code from past project
|
11
|
+
|
12
|
+
2010-10-14 Philip Hallstrom
|
13
|
+
|
14
|
+
* begin work on connector
|
15
|
+
* enforce that all pathnames reside beneath the root
|
16
|
+
* initial library and tests for mime_type/pathname
|
17
|
+
* bin/elfinder not necessary
|
18
|
+
* Initial commit
|
19
|
+
|
data/Manifest.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
.autotest
|
2
|
+
History.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
lib/el_finder.rb
|
7
|
+
lib/el_finder/connector.rb
|
8
|
+
lib/el_finder/image_resize.rb
|
9
|
+
lib/el_finder/image_size.rb
|
10
|
+
lib/el_finder/mime_type.rb
|
11
|
+
lib/el_finder/pathname.rb
|
12
|
+
test/files/README.txt
|
13
|
+
test/files/elfinder.png
|
14
|
+
test/files/foo/philip.txt
|
15
|
+
test/files/foo/sam.txt
|
16
|
+
test/files/foo/sandy.txt
|
17
|
+
test/files/foo/tom.txt
|
18
|
+
test/files/pjkh.png
|
19
|
+
test/test_el_finder.rb
|
20
|
+
test/test_el_finder_image_size.rb
|
21
|
+
test/test_el_finder_mime_type.rb
|
22
|
+
test/test_el_finder_pathname.rb
|
data/README.txt
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
== el_finder
|
2
|
+
|
3
|
+
* http://elrte.org/redmine/projects/elfinder
|
4
|
+
|
5
|
+
== Description:
|
6
|
+
|
7
|
+
Ruby library to provide server side functionality for elFinder. elFinder is an
|
8
|
+
open-source file manager for web, written in JavaScript using jQuery UI.
|
9
|
+
|
10
|
+
== Features/Problems:
|
11
|
+
|
12
|
+
* Does not yet support archive/extraction.
|
13
|
+
* Does not yet support thumbnail generation.
|
14
|
+
|
15
|
+
== Todo:
|
16
|
+
|
17
|
+
* Add support for archive/extraction.
|
18
|
+
* Add support for thumbnail generation.
|
19
|
+
* Document library.
|
20
|
+
* Document how to implement custom image size/resize methods.
|
21
|
+
|
22
|
+
== Requirements:
|
23
|
+
|
24
|
+
The gem, by default, relies upon the 'imagesize' ruby gem and ImageMagick's 'mogrify' command.
|
25
|
+
These requirements can be changed by implementing custom methods for determining image size
|
26
|
+
and resizing of an image.
|
27
|
+
|
28
|
+
== Install:
|
29
|
+
|
30
|
+
* Install elFinder (http://elrte.org/redmine/projects/elfinder/wiki/Install_EN)
|
31
|
+
* Install ImageMagick (http://www.imagemagick.org/)
|
32
|
+
* Do whatever is necessary for your Ruby framework to tie it together.
|
33
|
+
|
34
|
+
=== Rails 3
|
35
|
+
|
36
|
+
* Add "gem 'el_finder'" to Gemfile
|
37
|
+
* % bundle install
|
38
|
+
* Switch to using jQuery instead of Prototype
|
39
|
+
* Add the following action to a controller of your choosing.
|
40
|
+
|
41
|
+
skip_before_filter :verify_authenticity_token, :only => ['elfinder']
|
42
|
+
def elfinder
|
43
|
+
h, r = ElFinder::Connector.new(
|
44
|
+
:root => File.join(Rails.public_path, 'system', 'elfinder'),
|
45
|
+
:url => '/system/elfinder'
|
46
|
+
).run(params)
|
47
|
+
headers.merge!(h)
|
48
|
+
render (r.empty? ? {:nothing => true} : {:text => r.to_json}), :layout => false
|
49
|
+
end
|
50
|
+
|
51
|
+
* Add the appropriate route to config/routes.rb such as:
|
52
|
+
|
53
|
+
match 'elfinder' => 'home#elfinder'
|
54
|
+
|
55
|
+
* Add the following to your layout. The paths may be different depending
|
56
|
+
on where you installed the various js/css files.
|
57
|
+
|
58
|
+
<%= stylesheet_link_tag 'jquery-ui/base/jquery.ui.all', 'elfinder' %>
|
59
|
+
<%= javascript_include_tag :defaults, 'elfinder/elfinder.min' %>
|
60
|
+
|
61
|
+
* Add the following to the view that will display elFinder:
|
62
|
+
|
63
|
+
<%= javascript_tag do %>
|
64
|
+
$().ready(function() {
|
65
|
+
$('#elfinder').elfinder({
|
66
|
+
url: '/elfinder',
|
67
|
+
lang: 'en'
|
68
|
+
})
|
69
|
+
})
|
70
|
+
<% end %>
|
71
|
+
<div id='elfinder'></div>
|
72
|
+
|
73
|
+
* That's it. I think. If not, check out the example rails application at http://github.com/phallstrom/el_finder-rails-example.
|
74
|
+
|
75
|
+
== License:
|
76
|
+
|
77
|
+
(The MIT License)
|
78
|
+
|
79
|
+
Copyright (c) 2010 Philip Hallstrom
|
80
|
+
|
81
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
82
|
+
a copy of this software and associated documentation files (the
|
83
|
+
'Software'), to deal in the Software without restriction, including
|
84
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
85
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
86
|
+
permit persons to whom the Software is furnished to do so, subject to
|
87
|
+
the following conditions:
|
88
|
+
|
89
|
+
The above copyright notice and this permission notice shall be
|
90
|
+
included in all copies or substantial portions of the Software.
|
91
|
+
|
92
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
93
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
94
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
95
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
96
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
97
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
98
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/lib/el_finder.rb
ADDED
@@ -0,0 +1,342 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
module ElFinder
|
4
|
+
class Connector
|
5
|
+
|
6
|
+
VALID_COMMANDS = %w[archive duplicate edit extract mkdir mkfile open paste ping read rename resize rm tmb upload]
|
7
|
+
|
8
|
+
DEFAULT_OPTIONS = {
|
9
|
+
:mime_handler => ElFinder::MimeType,
|
10
|
+
:image_size_handler => ElFinder::ImageSize,
|
11
|
+
:image_resize_handler => ElFinder::ImageResize,
|
12
|
+
:original_filename_method => lambda {|file| file.original_filename},
|
13
|
+
:disabled_commands => [],
|
14
|
+
:show_dot_files => true,
|
15
|
+
:upload_max_size => '50M',
|
16
|
+
:archivers => [],
|
17
|
+
:extractors => [],
|
18
|
+
:home => 'Home',
|
19
|
+
}
|
20
|
+
|
21
|
+
#
|
22
|
+
def initialize(options = {})
|
23
|
+
@options = DEFAULT_OPTIONS.merge(options)
|
24
|
+
|
25
|
+
raise(RuntimeError, "Missing required :url option") unless @options.key?(:url)
|
26
|
+
raise(RuntimeError, "Missing required :root option") unless @options.key?(:root)
|
27
|
+
|
28
|
+
@mime_handler = @options.delete(:mime_handler)
|
29
|
+
raise(RuntimeError, "Mime Handler is invalid") unless @mime_handler.respond_to?(:for)
|
30
|
+
|
31
|
+
@image_size_handler = @options.delete(:image_size_handler)
|
32
|
+
raise(RuntimeError, "Image Size Handler is invalid") unless @image_size_handler.nil? || @image_size_handler.respond_to?(:for)
|
33
|
+
|
34
|
+
@image_resize_handler = @options.delete(:image_resize_handler)
|
35
|
+
raise(RuntimeError, "Image Resize Handler is invalid") unless @image_resize_handler.nil? || @image_resize_handler.respond_to?(:resize)
|
36
|
+
|
37
|
+
@root = ElFinder::Pathname.new(options[:root])
|
38
|
+
|
39
|
+
@headers = {}
|
40
|
+
@response = {}
|
41
|
+
end # of initialize
|
42
|
+
|
43
|
+
#
|
44
|
+
def run(params = {})
|
45
|
+
@params = params.dup
|
46
|
+
|
47
|
+
if VALID_COMMANDS.include?(@params[:cmd])
|
48
|
+
|
49
|
+
@current = @params[:current] ? from_hash(@params[:current]) : nil
|
50
|
+
@target = @params[:target] ? from_hash(@params[:target]) : nil
|
51
|
+
if params[:targets]
|
52
|
+
@targets = @params[:targets].map{|t| from_hash(t)}
|
53
|
+
end
|
54
|
+
|
55
|
+
send("_#{@params[:cmd]}")
|
56
|
+
else
|
57
|
+
invalid_request
|
58
|
+
end
|
59
|
+
|
60
|
+
return @headers, @response
|
61
|
+
end # of run
|
62
|
+
|
63
|
+
#
|
64
|
+
def to_hash(pathname)
|
65
|
+
Base64.encode64(pathname == @root ? '/' : pathname.relative_path_from(@root).to_s).chomp
|
66
|
+
end # of to_hash
|
67
|
+
|
68
|
+
#
|
69
|
+
def from_hash(hash)
|
70
|
+
pathname = ElFinder::Pathname.new_with_root(@root, Base64.decode64(hash))
|
71
|
+
end # of from_hash
|
72
|
+
|
73
|
+
################################################################################
|
74
|
+
protected
|
75
|
+
|
76
|
+
#
|
77
|
+
def _open(target = nil)
|
78
|
+
target ||= @target
|
79
|
+
|
80
|
+
if target.nil?
|
81
|
+
_open(@root)
|
82
|
+
elsif target.file?
|
83
|
+
command_not_implemented
|
84
|
+
elsif target.directory?
|
85
|
+
@response[:cwd] = cwd_for(target)
|
86
|
+
@response[:cdc] = target.children.map{|e| cdc_for(e)}
|
87
|
+
|
88
|
+
if @params[:tree]
|
89
|
+
@response[:tree] = {
|
90
|
+
:name => @options[:home],
|
91
|
+
:hash => to_hash(@root),
|
92
|
+
:read => @root.readable?,
|
93
|
+
:write => @root.writable?,
|
94
|
+
:dirs => tree_for(@root)
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
if @params[:init]
|
99
|
+
@response[:disabled] = @options[:disabled_commands]
|
100
|
+
@response[:params] = {
|
101
|
+
:dotFiles => @options[:show_dot_files],
|
102
|
+
:uplMaxSize => @options[:upload_max_size],
|
103
|
+
:archives => @options[:archivers],
|
104
|
+
:extract => @options[:extractors],
|
105
|
+
:url => @options[:url]
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
109
|
+
# FIXME - add 'tmb:true' when necessary
|
110
|
+
|
111
|
+
else
|
112
|
+
@response[:error] = "Directory does not exist"
|
113
|
+
_open(@root)
|
114
|
+
end
|
115
|
+
|
116
|
+
end # of open
|
117
|
+
|
118
|
+
#
|
119
|
+
def _mkdir
|
120
|
+
dir = @current + @params[:name]
|
121
|
+
if !dir.exist? && dir.mkdir
|
122
|
+
@params[:tree] = true
|
123
|
+
@response[:select] = [to_hash(dir)]
|
124
|
+
_open(@current)
|
125
|
+
else
|
126
|
+
@response[:error] = "Unable to create folder"
|
127
|
+
end
|
128
|
+
end # of mkdir
|
129
|
+
|
130
|
+
#
|
131
|
+
def _mkfile
|
132
|
+
file = @current + @params[:name]
|
133
|
+
if !file.exist? && FileUtils.touch(file)
|
134
|
+
@response[:select] = [to_hash(file)]
|
135
|
+
_open(@current)
|
136
|
+
else
|
137
|
+
@response[:error] = "Unable to create file"
|
138
|
+
end
|
139
|
+
end # of mkfile
|
140
|
+
|
141
|
+
#
|
142
|
+
def _rename
|
143
|
+
to = @current + @params[:name]
|
144
|
+
if to.exist?
|
145
|
+
@response[:error] = "Unable to rename #{@target.ftype}. '#{to.basename}' already exists"
|
146
|
+
elsif @target.rename(to)
|
147
|
+
@params[:tree] = to.directory?
|
148
|
+
@response[:select] = [to_hash(to)]
|
149
|
+
_open(@current)
|
150
|
+
else
|
151
|
+
@response[:error] = "Unable to rename #{@target.ftype}"
|
152
|
+
end
|
153
|
+
end # of rename
|
154
|
+
|
155
|
+
#
|
156
|
+
def _upload
|
157
|
+
select = []
|
158
|
+
@params[:upload].to_a.each do |file|
|
159
|
+
dst = @current + @options[:original_filename_method].call(file)
|
160
|
+
File.rename(file.path, dst)
|
161
|
+
select << to_hash(dst)
|
162
|
+
end
|
163
|
+
@response[:select] = select
|
164
|
+
_open(@current)
|
165
|
+
end # of upload
|
166
|
+
|
167
|
+
#
|
168
|
+
def _ping
|
169
|
+
@headers['Connection'] = 'Close'
|
170
|
+
end # of ping
|
171
|
+
|
172
|
+
#
|
173
|
+
def _paste
|
174
|
+
@targets.to_a.each do |src|
|
175
|
+
dst = from_hash(@params[:dst]) + src.basename
|
176
|
+
if dst.exist?
|
177
|
+
@response[:error] = 'Some files were unable to be copied'
|
178
|
+
@response[:errorData] ||= {}
|
179
|
+
@response[:errorData][src.basename] = "already exists in '#{dst.dirname.relative_path_from(@root)}'"
|
180
|
+
else
|
181
|
+
if @params[:cut].to_i > 0
|
182
|
+
File.rename(src, dst)
|
183
|
+
else
|
184
|
+
if src.directory?
|
185
|
+
FileUtils.cp_r(src, dst)
|
186
|
+
else
|
187
|
+
FileUtils.copy(src, dst)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
@params[:tree] = true
|
193
|
+
_open(@current)
|
194
|
+
end # of paste
|
195
|
+
|
196
|
+
#
|
197
|
+
def _rm
|
198
|
+
if @targets.empty?
|
199
|
+
@response[:error] = "No files were selected for removal"
|
200
|
+
else
|
201
|
+
FileUtils.rm_rf(@targets)
|
202
|
+
@params[:tree] = true
|
203
|
+
_open(@current)
|
204
|
+
end
|
205
|
+
end # of rm
|
206
|
+
|
207
|
+
#
|
208
|
+
def _duplicate
|
209
|
+
duplicate = @target.duplicate
|
210
|
+
if @target.directory?
|
211
|
+
FileUtils.cp_r(@target, duplicate)
|
212
|
+
else
|
213
|
+
FileUtils.copy(@target, duplicate)
|
214
|
+
end
|
215
|
+
@response[:select] = [to_hash(duplicate)]
|
216
|
+
_open(@current)
|
217
|
+
end # of duplicate
|
218
|
+
|
219
|
+
#
|
220
|
+
def _read
|
221
|
+
@response[:content] = @target.read
|
222
|
+
end # of read
|
223
|
+
|
224
|
+
#
|
225
|
+
def _edit
|
226
|
+
@target.open('w') { |f| f.write @params[:content] }
|
227
|
+
@response[:file] = cdc_for(@target)
|
228
|
+
end # of edit
|
229
|
+
|
230
|
+
#
|
231
|
+
def _extract
|
232
|
+
command_not_implemented
|
233
|
+
end # of extract
|
234
|
+
|
235
|
+
#
|
236
|
+
def _archive
|
237
|
+
command_not_implemented
|
238
|
+
end # of archive
|
239
|
+
|
240
|
+
#
|
241
|
+
def _tmb
|
242
|
+
command_not_implemented
|
243
|
+
end # of tmb
|
244
|
+
|
245
|
+
#
|
246
|
+
def _resize
|
247
|
+
if @image_resize_handler.nil?
|
248
|
+
command_not_implemented
|
249
|
+
else
|
250
|
+
if @target.file?
|
251
|
+
@image_resize_handler.resize(@target, :width => @params[:width].to_i, :height => @params[:height].to_i)
|
252
|
+
@response[:select] = [to_hash(@target)]
|
253
|
+
_open(@current)
|
254
|
+
else
|
255
|
+
@response[:error] = "Unable to resize file. It does not exist"
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end # of resize
|
259
|
+
|
260
|
+
################################################################################
|
261
|
+
private
|
262
|
+
|
263
|
+
#
|
264
|
+
def cwd_for(pathname)
|
265
|
+
{
|
266
|
+
:name => pathname.basename.to_s,
|
267
|
+
:hash => to_hash(pathname),
|
268
|
+
:mime => 'directory',
|
269
|
+
:rel => (@options[:home] + '/' + pathname.relative_path_from(@root)),
|
270
|
+
:size => 0,
|
271
|
+
:date => pathname.mtime.to_s,
|
272
|
+
:read => pathname.readable?,
|
273
|
+
:write => pathname.writable?,
|
274
|
+
:rm => (pathname != @root && pathname.writable?),
|
275
|
+
}
|
276
|
+
end
|
277
|
+
|
278
|
+
# TODO - Implement link, linkTo, and parent
|
279
|
+
def cdc_for(pathname)
|
280
|
+
response = {
|
281
|
+
:name => pathname.basename.to_s,
|
282
|
+
:hash => to_hash(pathname),
|
283
|
+
:date => pathname.mtime.to_s,
|
284
|
+
:read => pathname.readable?,
|
285
|
+
:write => pathname.writable?,
|
286
|
+
:rm => pathname.writable?,
|
287
|
+
}
|
288
|
+
|
289
|
+
if pathname.directory?
|
290
|
+
response.merge!(
|
291
|
+
:size => 0,
|
292
|
+
:mime => 'directory'
|
293
|
+
)
|
294
|
+
elsif pathname.symlink?
|
295
|
+
response.merge!(
|
296
|
+
:link => 'FIXME',
|
297
|
+
:linkTo => 'FIXME',
|
298
|
+
:parent => 'FIXME'
|
299
|
+
)
|
300
|
+
elsif pathname.file?
|
301
|
+
response.merge!(
|
302
|
+
:size => pathname.size,
|
303
|
+
:mime => @mime_handler.for(pathname),
|
304
|
+
:url => (@options[:url] + '/' + pathname.relative_path_from(@root))
|
305
|
+
)
|
306
|
+
|
307
|
+
if response[:mime] =~ /image/ && !@image_size_handler.nil? && !@image_resize_handler.nil?
|
308
|
+
response.merge!(
|
309
|
+
:resize => true,
|
310
|
+
:dim => @image_size_handler.for(pathname)
|
311
|
+
)
|
312
|
+
end
|
313
|
+
|
314
|
+
end
|
315
|
+
|
316
|
+
return response
|
317
|
+
end
|
318
|
+
|
319
|
+
#
|
320
|
+
def tree_for(root)
|
321
|
+
root.children.select{ |child| child.directory? }.sort_by{|e| e.basename.to_s.downcase}.map { |child|
|
322
|
+
{:name => child.basename.to_s,
|
323
|
+
:hash => to_hash(child),
|
324
|
+
:read => child.readable?,
|
325
|
+
:write => child.writable?,
|
326
|
+
:dirs => tree_for(child),
|
327
|
+
}
|
328
|
+
}
|
329
|
+
end # of tree_for
|
330
|
+
|
331
|
+
#
|
332
|
+
def invalid_request
|
333
|
+
@response[:error] = "Invalid command '#{@params[:cmd]}'"
|
334
|
+
end # of invalid_request
|
335
|
+
|
336
|
+
#
|
337
|
+
def command_not_implemented
|
338
|
+
@response[:error] = "Command '#{@params[:cmd]}' not yet implemented"
|
339
|
+
end # of command_not_implemented
|
340
|
+
|
341
|
+
end # of class Connector
|
342
|
+
end # of module ElFinder
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'shellwords'
|
2
|
+
|
3
|
+
module ElFinder
|
4
|
+
|
5
|
+
class ImageResize
|
6
|
+
|
7
|
+
def self.resize(pathname, options = {})
|
8
|
+
return nil unless File.exist?(pathname)
|
9
|
+
system( ::Shellwords.join(['mogrify', '-resize', "#{options[:width]}x#{options[:height]}!", pathname.to_s]) )
|
10
|
+
end # of self.resize
|
11
|
+
|
12
|
+
end # of class ImageSize
|
13
|
+
|
14
|
+
end # of module ElFinder
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'image_size'
|
3
|
+
|
4
|
+
module ElFinder
|
5
|
+
|
6
|
+
class ImageSize < ::ImageSize
|
7
|
+
|
8
|
+
def self.for(pathname)
|
9
|
+
return nil unless File.exist?(pathname)
|
10
|
+
s = new(File.open(pathname)).get_size.join('x').to_s
|
11
|
+
s = nil if s == 'x'
|
12
|
+
return s
|
13
|
+
end
|
14
|
+
|
15
|
+
end # of class ImageSize
|
16
|
+
|
17
|
+
end # of module ElFinder
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module ElFinder
|
2
|
+
|
3
|
+
class MimeType
|
4
|
+
|
5
|
+
TYPES = {
|
6
|
+
'ai' => 'application/postscript',
|
7
|
+
'eps' => 'application/postscript',
|
8
|
+
'exe' => 'application/octet-stream',
|
9
|
+
'doc' => 'application/vnd.ms-word',
|
10
|
+
'xls' => 'application/vnd.ms-excel',
|
11
|
+
'ppt' => 'application/vnd.ms-powerpoint',
|
12
|
+
'pps' => 'application/vnd.ms-powerpoint',
|
13
|
+
'pdf' => 'application/pdf',
|
14
|
+
'xml' => 'application/xml',
|
15
|
+
'odt' => 'application/vnd.oasis.opendocument.text',
|
16
|
+
'swf' => 'application/x-shockwave-flash',
|
17
|
+
# archives
|
18
|
+
'gz' => 'application/x-gzip',
|
19
|
+
'tgz' => 'application/x-gzip',
|
20
|
+
'bz' => 'application/x-bzip2',
|
21
|
+
'bz2' => 'application/x-bzip2',
|
22
|
+
'tbz' => 'application/x-bzip2',
|
23
|
+
'zip' => 'application/zip',
|
24
|
+
'rar' => 'application/x-rar',
|
25
|
+
'tar' => 'application/x-tar',
|
26
|
+
'7z' => 'application/x-7z-compressed',
|
27
|
+
# texts
|
28
|
+
'txt' => 'text/plain',
|
29
|
+
'php' => 'text/x-php',
|
30
|
+
'html' => 'text/html',
|
31
|
+
'htm' => 'text/html',
|
32
|
+
'js' => 'text/javascript',
|
33
|
+
'css' => 'text/css',
|
34
|
+
'rtf' => 'text/rtf',
|
35
|
+
'rtfd' => 'text/rtfd',
|
36
|
+
'py' => 'text/x-python',
|
37
|
+
'java' => 'text/x-java-source',
|
38
|
+
'rb' => 'text/x-ruby',
|
39
|
+
'sh' => 'text/x-shellscript',
|
40
|
+
'pl' => 'text/x-perl',
|
41
|
+
'sql' => 'text/x-sql',
|
42
|
+
# images
|
43
|
+
'bmp' => 'image/x-ms-bmp',
|
44
|
+
'jpg' => 'image/jpeg',
|
45
|
+
'jpeg' => 'image/jpeg',
|
46
|
+
'gif' => 'image/gif',
|
47
|
+
'png' => 'image/png',
|
48
|
+
'tif' => 'image/tiff',
|
49
|
+
'tiff' => 'image/tiff',
|
50
|
+
'tga' => 'image/x-targa',
|
51
|
+
'psd' => 'image/vnd.adobe.photoshop',
|
52
|
+
# audio
|
53
|
+
'mp3' => 'audio/mpeg',
|
54
|
+
'mid' => 'audio/midi',
|
55
|
+
'ogg' => 'audio/ogg',
|
56
|
+
'mp4a' => 'audio/mp4',
|
57
|
+
'wav' => 'audio/wav',
|
58
|
+
'wma' => 'audio/x-ms-wma',
|
59
|
+
# video
|
60
|
+
'avi' => 'video/x-msvideo',
|
61
|
+
'dv' => 'video/x-dv',
|
62
|
+
'mp4' => 'video/mp4',
|
63
|
+
'mpeg' => 'video/mpeg',
|
64
|
+
'mpg' => 'video/mpeg',
|
65
|
+
'mov' => 'video/quicktime',
|
66
|
+
'wm' => 'video/x-ms-wmv',
|
67
|
+
'flv' => 'video/x-flv',
|
68
|
+
'mkv' => 'video/x-matroska'
|
69
|
+
}
|
70
|
+
|
71
|
+
def self.for(pathname)
|
72
|
+
pathname = ::Pathname.new(pathname) if pathname.is_a?(String)
|
73
|
+
TYPES[pathname.extname.downcase[1..-1]] || 'unknown/unknown'
|
74
|
+
end # of for
|
75
|
+
|
76
|
+
end # of class MimeType
|
77
|
+
|
78
|
+
end # of module ElFinder
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module ElFinder
|
4
|
+
|
5
|
+
class Pathname < ::Pathname
|
6
|
+
|
7
|
+
#
|
8
|
+
def +(other)
|
9
|
+
self.class.new(super(other).to_s)
|
10
|
+
end
|
11
|
+
|
12
|
+
#
|
13
|
+
def join(*args)
|
14
|
+
self.class.new(super(*args).to_s)
|
15
|
+
end
|
16
|
+
|
17
|
+
#
|
18
|
+
def self.new_with_root(root, path = '')
|
19
|
+
new(superclass.new(File.join(root, path)).cleanpath.to_s)
|
20
|
+
end # of self.new_with_root
|
21
|
+
|
22
|
+
#
|
23
|
+
def duplicate
|
24
|
+
_dirname = dirname
|
25
|
+
_extname = extname
|
26
|
+
_basename = basename(_extname)
|
27
|
+
copy = 0
|
28
|
+
if _basename.to_s =~ /^(.*) copy (\d+)$/
|
29
|
+
_basename = $1
|
30
|
+
copy = $2.to_i
|
31
|
+
end
|
32
|
+
|
33
|
+
begin
|
34
|
+
copy += 1
|
35
|
+
duplicate = self.class.superclass.new(_dirname + "#{_basename} copy #{copy}#{_extname}")
|
36
|
+
end while duplicate.exist?
|
37
|
+
duplicate
|
38
|
+
end # of duplicate
|
39
|
+
|
40
|
+
#
|
41
|
+
def relative_to(pathname)
|
42
|
+
self == pathname ? '' : relative_path_from(pathname).to_s
|
43
|
+
end # of relative_to
|
44
|
+
|
45
|
+
end # of class Pathname
|
46
|
+
|
47
|
+
end # of module ElFinder
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
philip
|
@@ -0,0 +1 @@
|
|
1
|
+
sam
|
@@ -0,0 +1 @@
|
|
1
|
+
sandy
|
@@ -0,0 +1 @@
|
|
1
|
+
tom
|
data/test/files/pjkh.png
ADDED
Binary file
|
@@ -0,0 +1,265 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "el_finder"
|
3
|
+
|
4
|
+
class TestElFinder < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@vroot = '/tmp/elfinder'
|
8
|
+
FileUtils.mkdir_p(@vroot)
|
9
|
+
FileUtils.cp_r "#{File.dirname(__FILE__)}/files/.", @vroot
|
10
|
+
@elfinder = ElFinder::Connector.new({
|
11
|
+
:root => @vroot,
|
12
|
+
:url => '/elfinder',
|
13
|
+
:original_filename_method => lambda {|file| File.basename(file.path)}
|
14
|
+
})
|
15
|
+
end
|
16
|
+
|
17
|
+
def teardown
|
18
|
+
FileUtils.rm_rf(@vroot)
|
19
|
+
end
|
20
|
+
|
21
|
+
################################################################################
|
22
|
+
|
23
|
+
def test_should_fail_initialization_if_required_options_not_passed
|
24
|
+
assert_raise RuntimeError do
|
25
|
+
ElFinder::Connector.new()
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_should_fail_initialization_if_no_root_specified
|
30
|
+
assert_raise RuntimeError do
|
31
|
+
ElFinder::Connector.new({:url => '/elfinder'})
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_should_fail_initialization_if_no_url_specified
|
36
|
+
assert_raise RuntimeError do
|
37
|
+
ElFinder::Connector.new({:root => '/tmp/elfinder'})
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_should_fail_initialization_if_mime_handler_is_invalid
|
42
|
+
assert_raise RuntimeError do
|
43
|
+
ElFinder::Connector.new({:root => '/tmp/elfinder', :url => '/elfinder', :mime_handler => Object})
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
################################################################################
|
48
|
+
|
49
|
+
def test_should_return_two_hashes
|
50
|
+
h, r = @elfinder.run({})
|
51
|
+
assert_instance_of Hash, h
|
52
|
+
assert_instance_of Hash, r
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
def test_should_return_invalid_request_if_command_is_invalid
|
57
|
+
h, r = @elfinder.run({:cmd => 'INVALID'})
|
58
|
+
assert_not_nil r[:error]
|
59
|
+
assert_match(/invalid command/i, r[:error])
|
60
|
+
end
|
61
|
+
|
62
|
+
################################################################################
|
63
|
+
|
64
|
+
def test_to_hash_method
|
65
|
+
assert_equal Base64.encode64('foo/bar').chomp, @elfinder.to_hash(ElFinder::Pathname.new_with_root(@vroot, 'foo/bar'))
|
66
|
+
assert_equal Base64.encode64('/').chomp, @elfinder.to_hash(ElFinder::Pathname.new_with_root(@vroot))
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_from_hash_method
|
70
|
+
assert_equal File.join(@vroot, 'foo/bar'), @elfinder.from_hash(Base64.encode64('foo/bar').chomp).to_s
|
71
|
+
assert_equal @vroot, @elfinder.from_hash(Base64.encode64('').chomp).to_s
|
72
|
+
end
|
73
|
+
|
74
|
+
################################################################################
|
75
|
+
|
76
|
+
def test_init_via_open
|
77
|
+
h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
|
78
|
+
assert_not_nil r[:cwd]
|
79
|
+
assert_not_nil r[:cdc]
|
80
|
+
assert_not_nil r[:disabled]
|
81
|
+
assert_not_nil r[:params]
|
82
|
+
r[:cdc].each do |e|
|
83
|
+
case e[:name]
|
84
|
+
when 'foo'
|
85
|
+
assert_nil e[:dim]
|
86
|
+
assert_nil e[:resize]
|
87
|
+
assert_equal 'directory', e[:mime]
|
88
|
+
assert_equal 0, e[:size]
|
89
|
+
when 'pjkh.png'
|
90
|
+
assert_equal '100x100', e[:dim]
|
91
|
+
assert e[:resize]
|
92
|
+
assert_equal 'image/png', e[:mime]
|
93
|
+
assert_equal 1142, e[:size]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_mkdir
|
99
|
+
h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
|
100
|
+
h1, r1 = @elfinder.run(:cmd => 'mkdir', :current => r[:cwd][:hash], :name => 'dir1')
|
101
|
+
assert File.directory?(File.join(@vroot, 'dir1'))
|
102
|
+
assert_not_nil r1[:select]
|
103
|
+
|
104
|
+
h1, r1 = @elfinder.run(:cmd => 'mkdir', :current => r[:cwd][:hash], :name => 'dir1')
|
105
|
+
assert_match(/unable/i, r1[:error])
|
106
|
+
|
107
|
+
h1, r1 = @elfinder.run(:cmd => 'mkdir', :current => r[:cwd][:hash], :name => 'foo')
|
108
|
+
assert_match(/unable/i, r1[:error])
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_mkfile
|
112
|
+
h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
|
113
|
+
h1, r1 = @elfinder.run(:cmd => 'mkfile', :current => r[:cwd][:hash], :name => 'file1')
|
114
|
+
assert File.file?(File.join(@vroot, 'file1'))
|
115
|
+
assert_not_nil r1[:select]
|
116
|
+
|
117
|
+
h1, r1 = @elfinder.run(:cmd => 'mkfile', :current => r[:cwd][:hash], :name => 'file1')
|
118
|
+
assert_match(/unable/i, r1[:error])
|
119
|
+
|
120
|
+
h1, r1 = @elfinder.run(:cmd => 'mkfile', :current => r[:cwd][:hash], :name => 'README.txt')
|
121
|
+
assert_match(/unable/i, r1[:error])
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_rename_ok
|
125
|
+
h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
|
126
|
+
target = r[:cdc].find{|e| e[:name] == 'README.txt'}
|
127
|
+
h1, r1 = @elfinder.run(:cmd => 'rename', :target => target[:hash], :current => r[:cwd][:hash], :name => 'file1')
|
128
|
+
assert File.file?(File.join(@vroot, 'file1'))
|
129
|
+
assert_not_nil r1[:select]
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_rename_fail
|
133
|
+
h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
|
134
|
+
target = r[:cdc].find{|e| e[:name] == 'README.txt'}
|
135
|
+
h1, r1 = @elfinder.run(:cmd => 'rename', :target => target[:hash], :current => r[:cwd][:hash], :name => 'foo')
|
136
|
+
assert_match(/unable.*already exists/i, r1[:error])
|
137
|
+
assert File.file?(File.join(@vroot, 'README.txt'))
|
138
|
+
assert_nil r1[:select]
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_upload
|
142
|
+
h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
|
143
|
+
uploads = []
|
144
|
+
uploads << File.open(File.join(@vroot, 'foo/philip.txt'))
|
145
|
+
uploads << File.open(File.join(@vroot, 'foo/sandy.txt'))
|
146
|
+
h, r = @elfinder.run(:cmd => 'upload', :upload => uploads, :current => r[:cwd][:hash])
|
147
|
+
assert File.exist?(File.join(@vroot, 'philip.txt'))
|
148
|
+
assert File.exist?(File.join(@vroot, 'sandy.txt'))
|
149
|
+
assert_not_nil r[:select]
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_ping
|
153
|
+
h, r = @elfinder.run(:cmd => 'ping')
|
154
|
+
assert r.empty?
|
155
|
+
assert_equal 'Close', h['Connection']
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_paste_copy
|
159
|
+
h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
|
160
|
+
targets = r[:cdc].select{|e| e[:mime] != 'directory'}
|
161
|
+
dst = r[:cdc].find{|e| e[:name] == 'foo'}
|
162
|
+
|
163
|
+
h, r = @elfinder.run(:cmd => 'paste', :targets => targets.map{|e| e[:hash]}, :dst => dst[:hash])
|
164
|
+
assert_not_nil r[:tree]
|
165
|
+
assert File.exist?(File.join(@vroot, 'README.txt'))
|
166
|
+
assert File.exist?(File.join(@vroot, 'pjkh.png'))
|
167
|
+
assert File.exist?(File.join(@vroot, 'elfinder.png'))
|
168
|
+
assert File.exist?(File.join(@vroot, 'foo', 'README.txt'))
|
169
|
+
assert File.exist?(File.join(@vroot, 'foo', 'pjkh.png'))
|
170
|
+
assert File.exist?(File.join(@vroot, 'foo', 'elfinder.png'))
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_paste_cut
|
174
|
+
h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
|
175
|
+
targets = r[:cdc].select{|e| e[:mime] != 'directory'}
|
176
|
+
dst = r[:cdc].find{|e| e[:name] == 'foo'}
|
177
|
+
|
178
|
+
h, r = @elfinder.run(:cmd => 'paste', :targets => targets.map{|e| e[:hash]}, :dst => dst[:hash], :cut => '1')
|
179
|
+
assert_not_nil r[:tree]
|
180
|
+
assert !File.exist?(File.join(@vroot, 'README.txt'))
|
181
|
+
assert !File.exist?(File.join(@vroot, 'pjkh.png'))
|
182
|
+
assert !File.exist?(File.join(@vroot, 'elfinder.png'))
|
183
|
+
assert File.exist?(File.join(@vroot, 'foo', 'README.txt'))
|
184
|
+
assert File.exist?(File.join(@vroot, 'foo', 'pjkh.png'))
|
185
|
+
assert File.exist?(File.join(@vroot, 'foo', 'elfinder.png'))
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_paste_partial_failure
|
189
|
+
h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
|
190
|
+
h, r = @elfinder.run(:cmd => 'mkfile', :current => r[:cwd][:hash], :name => 'philip.txt')
|
191
|
+
h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
|
192
|
+
|
193
|
+
targets = r[:cdc].select{|e| e[:mime] != 'directory'}
|
194
|
+
dst = r[:cdc].find{|e| e[:name] == 'foo'}
|
195
|
+
|
196
|
+
h, r = @elfinder.run(:cmd => 'paste', :targets => targets.map{|e| e[:hash]}, :dst => dst[:hash])
|
197
|
+
assert_not_nil r[:tree]
|
198
|
+
assert_match(/unable to be copied/i, r[:error])
|
199
|
+
assert_not_nil r[:errorData]
|
200
|
+
assert_equal 1, r[:errorData].size
|
201
|
+
assert File.exist?(File.join(@vroot, 'philip.txt'))
|
202
|
+
assert File.exist?(File.join(@vroot, 'foo', 'philip.txt'))
|
203
|
+
assert File.exist?(File.join(@vroot, 'foo', 'README.txt'))
|
204
|
+
assert File.exist?(File.join(@vroot, 'foo', 'pjkh.png'))
|
205
|
+
assert File.exist?(File.join(@vroot, 'foo', 'elfinder.png'))
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_rm
|
209
|
+
h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
|
210
|
+
h, r = @elfinder.run(:cmd => 'rm', :current => r[:cwd][:hash], :targets => [])
|
211
|
+
assert_match(/no files/i, r[:error])
|
212
|
+
|
213
|
+
h, r = @elfinder.run(:cmd => 'rm', :targets => r[:cdc].reject{|e| e[:mime] =~ /image/}.map{|e| e[:hash]})
|
214
|
+
assert !File.exist?(File.join(@vroot, 'README.txt'))
|
215
|
+
assert File.exist?(File.join(@vroot, 'pjkh.png'))
|
216
|
+
assert File.exist?(File.join(@vroot, 'elfinder.png'))
|
217
|
+
assert !File.exist?(File.join(@vroot, 'foo'))
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_duplicate
|
221
|
+
h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
|
222
|
+
duplicate = r[:cdc].find{|e| e[:name] == 'README.txt'}
|
223
|
+
assert File.exist?(File.join(@vroot, 'README.txt'))
|
224
|
+
h, r = @elfinder.run(:cmd => 'duplicate', :target => duplicate[:hash])
|
225
|
+
assert File.exist?(File.join(@vroot, 'README copy 1.txt'))
|
226
|
+
assert_not_nil r[:select]
|
227
|
+
h, r = @elfinder.run(:cmd => 'duplicate', :target => duplicate[:hash])
|
228
|
+
assert File.exist?(File.join(@vroot, 'README copy 2.txt'))
|
229
|
+
end
|
230
|
+
|
231
|
+
def test_read
|
232
|
+
h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
|
233
|
+
file = r[:cdc].find{|e| e[:name] == 'README.txt'}
|
234
|
+
h, r = @elfinder.run(:cmd => 'read', :target => file[:hash])
|
235
|
+
assert_equal r[:content], File.read(File.join(@vroot, 'README.txt'))
|
236
|
+
end
|
237
|
+
|
238
|
+
def test_edit
|
239
|
+
h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
|
240
|
+
file = r[:cdc].find{|e| e[:name] == 'README.txt'}
|
241
|
+
h, r = @elfinder.run(:cmd => 'edit', :target => file[:hash], :content => 'Hello')
|
242
|
+
assert_equal 'Hello', File.read(File.join(@vroot, 'README.txt'))
|
243
|
+
assert_not_nil r[:file]
|
244
|
+
end
|
245
|
+
|
246
|
+
def test_resize
|
247
|
+
h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
|
248
|
+
file = r[:cdc].find{|e| e[:name] == 'pjkh.png'}
|
249
|
+
h, r = @elfinder.run(:cmd => 'resize', :target => file[:hash], :current => r[:cwd][:hash], :width => '50', :height => '25')
|
250
|
+
assert File.exist?(File.join(@vroot, 'pjkh.png'))
|
251
|
+
assert_equal '50x25', ElFinder::ImageSize.for(File.join(@vroot, 'pjkh.png')).to_s
|
252
|
+
end
|
253
|
+
|
254
|
+
end
|
255
|
+
|
256
|
+
__END__
|
257
|
+
/Users/philip/Desktop/el_finder/test/files
|
258
|
+
14615625 16 -rw-r--r-- 1 philip staff 7718 Oct 15 14:19 ./elfinder.png
|
259
|
+
14569851 0 drwxr-xr-x 6 philip staff 204 Oct 15 11:19 ./foo
|
260
|
+
14605469 8 -rw-r--r-- 1 philip staff 7 Oct 15 11:19 ./foo/philip.txt
|
261
|
+
14605474 8 -rw-r--r-- 1 philip staff 4 Oct 15 11:19 ./foo/sam.txt
|
262
|
+
14605479 8 -rw-r--r-- 1 philip staff 6 Oct 15 11:19 ./foo/sandy.txt
|
263
|
+
14605486 8 -rw-r--r-- 1 philip staff 4 Oct 15 11:19 ./foo/tom.txt
|
264
|
+
14569820 8 -rw-r--r-- 1 philip staff 1142 Dec 6 2007 ./pjkh.png
|
265
|
+
14605515 8 -rw-r--r-- 1 philip staff 186 Oct 15 11:20 ./README.txt
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "el_finder"
|
3
|
+
|
4
|
+
class TestElFinderImageSize < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_that_method_exists
|
7
|
+
assert_respond_to ElFinder::ImageSize, :for
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_that_logos_are_correct_size
|
11
|
+
assert_equal '70x66', ElFinder::ImageSize.for( File.join(File.dirname(__FILE__), 'files/elfinder.png') )
|
12
|
+
assert_equal '100x100', ElFinder::ImageSize.for( File.join(File.dirname(__FILE__), 'files/pjkh.png') )
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_that_nil_is_returned_on_non_images
|
16
|
+
assert_equal nil, ElFinder::ImageSize.for( File.join(File.dirname(__FILE__), 'files/README.txt') )
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_that_nil_is_returned_on_nonexistint_files
|
20
|
+
assert_equal nil, ElFinder::ImageSize.for( File.join(File.dirname(__FILE__), 'files/NON_EXIST') )
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "el_finder"
|
3
|
+
|
4
|
+
class TestElFinderMimeType < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_that_method_exists
|
7
|
+
assert_respond_to ElFinder::MimeType, :for
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_known_mime_types
|
11
|
+
assert_equal 'image/jpeg', ElFinder::MimeType.for('image.jpg')
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_unknown_mime_types
|
15
|
+
assert_equal 'unknown/unknown', ElFinder::MimeType.for('image.foo')
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_uppercase_extensions
|
19
|
+
assert_equal 'image/jpeg', ElFinder::MimeType.for('image.JPG')
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_missing_extension
|
23
|
+
assert_equal 'unknown/unknown', ElFinder::MimeType.for('README')
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_passing_pathname
|
27
|
+
assert_equal 'text/plain', ElFinder::MimeType.for(ElFinder::Pathname.new('README.txt'))
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "el_finder"
|
3
|
+
require "fileutils"
|
4
|
+
|
5
|
+
class TestElFinderPathname < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@vroot = '/tmp/elfinder'
|
9
|
+
FileUtils.mkdir_p(@vroot)
|
10
|
+
FileUtils.cp_r "#{File.dirname(__FILE__)}/files/.", @vroot
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
FileUtils.rm_rf(@vroot)
|
15
|
+
end
|
16
|
+
|
17
|
+
################################################################################
|
18
|
+
|
19
|
+
def test_paths_are_always_clean
|
20
|
+
assert_equal File.join(@vroot, 'foo/bar'), ElFinder::Pathname.new_with_root(@vroot, File.join('foo', '..', 'foo', 'bar')).to_s
|
21
|
+
assert_equal @vroot, ElFinder::Pathname.new_with_root(@vroot, '').to_s
|
22
|
+
assert_equal File.join(@vroot, 'foo/bar'), ElFinder::Pathname.new_with_root(@vroot, File.join('/foo', 'bar')).to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_duplication_without_extension
|
26
|
+
assert_equal File.join(@vroot, 'README copy 1'), ElFinder::Pathname.new_with_root(@vroot,'README').duplicate.to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_2nd_duplication_without_extension
|
30
|
+
::FileUtils.touch(File.join(@vroot, 'README copy 1'))
|
31
|
+
assert_equal File.join(@vroot, 'README copy 2'), ElFinder::Pathname.new_with_root(@vroot,'README').duplicate.to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_duplication_with_extension
|
35
|
+
assert_equal File.join(@vroot, 'README copy 1.txt'), ElFinder::Pathname.new_with_root(@vroot,'README.txt').duplicate.to_s
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_2nd_duplication_with_extension
|
39
|
+
::FileUtils.touch(File.join(@vroot, 'README copy 1.txt'))
|
40
|
+
assert_equal File.join(@vroot, 'README copy 2.txt'), ElFinder::Pathname.new_with_root(@vroot,'README.txt').duplicate.to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_duplication_of_duplication_lookalike
|
44
|
+
assert_equal File.join(@vroot, 'README copy A copy 1.txt'), ElFinder::Pathname.new_with_root(@vroot,'README copy A.txt').duplicate.to_s
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_duplication_of_duplication_lookalike2
|
48
|
+
assert_equal File.join(@vroot, 'README copy copy 1.txt'), ElFinder::Pathname.new_with_root(@vroot,'README copy.txt').duplicate.to_s
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_on_disk_duplication
|
52
|
+
file = ElFinder::Pathname.new_with_root(@vroot, 'README.txt')
|
53
|
+
FileUtils.touch(file)
|
54
|
+
assert_equal true, File.exist?(File.join(@vroot, 'README.txt'))
|
55
|
+
duplicate = file.duplicate
|
56
|
+
FileUtils.touch(duplicate)
|
57
|
+
assert_equal true, File.exist?(File.join(@vroot, 'README copy 1.txt'))
|
58
|
+
end
|
59
|
+
|
60
|
+
################################################################################
|
61
|
+
|
62
|
+
def test_relative_to_method
|
63
|
+
assert_equal "", ElFinder::Pathname.new_with_root(@vroot).relative_to(::Pathname.new(@vroot)).to_s
|
64
|
+
assert_equal "foo.txt", ElFinder::Pathname.new_with_root(@vroot, 'foo.txt').relative_to(::Pathname.new(@vroot)).to_s
|
65
|
+
assert_equal "foo/bar.txt", ElFinder::Pathname.new_with_root(@vroot, 'foo/bar.txt').relative_to(::Pathname.new(@vroot)).to_s
|
66
|
+
end
|
67
|
+
|
68
|
+
################################################################################
|
69
|
+
|
70
|
+
def test_class_type
|
71
|
+
assert_kind_of ElFinder::Pathname, ElFinder::Pathname.new_with_root(@vroot, 'foo')
|
72
|
+
assert_kind_of ElFinder::Pathname, ElFinder::Pathname.new_with_root(@vroot, 'foo') + 'bar'
|
73
|
+
assert_kind_of ElFinder::Pathname, ElFinder::Pathname.new_with_root(@vroot, 'foo').join('bar')
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: el_finder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Philip Hallstrom
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-15 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: imagesize
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 25
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 1
|
33
|
+
- 1
|
34
|
+
version: 0.1.1
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rubyforge
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 7
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 0
|
49
|
+
- 4
|
50
|
+
version: 2.0.4
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: hoe
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 19
|
62
|
+
segments:
|
63
|
+
- 2
|
64
|
+
- 6
|
65
|
+
- 2
|
66
|
+
version: 2.6.2
|
67
|
+
type: :development
|
68
|
+
version_requirements: *id003
|
69
|
+
description: |-
|
70
|
+
Ruby library to provide server side functionality for elFinder. elFinder is an
|
71
|
+
open-source file manager for web, written in JavaScript using jQuery UI.
|
72
|
+
email:
|
73
|
+
- philip@pjkh.com
|
74
|
+
executables: []
|
75
|
+
|
76
|
+
extensions: []
|
77
|
+
|
78
|
+
extra_rdoc_files:
|
79
|
+
- History.txt
|
80
|
+
- Manifest.txt
|
81
|
+
- README.txt
|
82
|
+
files:
|
83
|
+
- .autotest
|
84
|
+
- History.txt
|
85
|
+
- Manifest.txt
|
86
|
+
- README.txt
|
87
|
+
- Rakefile
|
88
|
+
- lib/el_finder.rb
|
89
|
+
- lib/el_finder/connector.rb
|
90
|
+
- lib/el_finder/image_resize.rb
|
91
|
+
- lib/el_finder/image_size.rb
|
92
|
+
- lib/el_finder/mime_type.rb
|
93
|
+
- lib/el_finder/pathname.rb
|
94
|
+
- test/files/README.txt
|
95
|
+
- test/files/elfinder.png
|
96
|
+
- test/files/foo/philip.txt
|
97
|
+
- test/files/foo/sam.txt
|
98
|
+
- test/files/foo/sandy.txt
|
99
|
+
- test/files/foo/tom.txt
|
100
|
+
- test/files/pjkh.png
|
101
|
+
- test/test_el_finder.rb
|
102
|
+
- test/test_el_finder_image_size.rb
|
103
|
+
- test/test_el_finder_mime_type.rb
|
104
|
+
- test/test_el_finder_pathname.rb
|
105
|
+
has_rdoc: true
|
106
|
+
homepage: http://elrte.org/redmine/projects/elfinder
|
107
|
+
licenses: []
|
108
|
+
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options:
|
111
|
+
- --main
|
112
|
+
- README.txt
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
hash: 3
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
version: "0"
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
hash: 3
|
130
|
+
segments:
|
131
|
+
- 0
|
132
|
+
version: "0"
|
133
|
+
requirements: []
|
134
|
+
|
135
|
+
rubyforge_project: el_finder
|
136
|
+
rubygems_version: 1.3.7
|
137
|
+
signing_key:
|
138
|
+
specification_version: 3
|
139
|
+
summary: Ruby library to provide server side functionality for elFinder
|
140
|
+
test_files:
|
141
|
+
- test/test_el_finder.rb
|
142
|
+
- test/test_el_finder_image_size.rb
|
143
|
+
- test/test_el_finder_mime_type.rb
|
144
|
+
- test/test_el_finder_pathname.rb
|