alchemy-custom-model 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +147 -0
- data/Rakefile +32 -0
- data/app/assets/config/alchemy_custom_model_manifest.js +3 -0
- data/app/assets/images/alchemy-custom-model/no_image.png +0 -0
- data/app/assets/javascripts/alchemy-custom-model/change_language.js +11 -0
- data/app/assets/javascripts/alchemy-custom-model/common_init.js +16 -0
- data/app/assets/javascripts/alchemy-custom-model/custom_admin_element_editor.js.coffee +25 -0
- data/app/assets/javascripts/alchemy-custom-model/custom_tiny_mce.js.coffee.erb +95 -0
- data/app/assets/javascripts/alchemy-custom-model/el_finder.js.coffee.erb +241 -0
- data/app/assets/javascripts/alchemy-custom-model/elfinder_ui_manifest.js +4 -0
- data/app/assets/javascripts/alchemy-custom-model/manifest.js +23 -0
- data/app/assets/javascripts/alchemy-custom-model/nested_attributes_sortable.js.coffee +25 -0
- data/app/assets/javascripts/alchemy-custom-model/select2filter.js +51 -0
- data/app/assets/javascripts/alchemy-custom-model/subobjects.js +98 -0
- data/app/assets/javascripts/alchemy-custom-model/total_page_elfinder.js.coffee +15 -0
- data/app/assets/stylesheets/alchemy-custom-model/custom_elfinder.css.scss +130 -0
- data/app/assets/stylesheets/alchemy-custom-model/custom_style.css.scss +228 -0
- data/app/assets/stylesheets/alchemy-custom-model/custom_tiny_mce.scss +6 -0
- data/app/assets/stylesheets/alchemy-custom-model/manifest.css +16 -0
- data/app/controllers/alchemy/custom/model/admin/base_controller.rb +189 -0
- data/app/controllers/alchemy/custom/model/admin/files_controller.rb +106 -0
- data/app/controllers/alchemy/pages_controller_decorator.rb +1 -0
- data/app/helpers/alchemy/custom/model/admin/base_helper.rb +379 -0
- data/app/helpers/alchemy/custom/model/base_helper.rb +18 -0
- data/app/helpers/alchemy/custom/model/custom_model_helper.rb +112 -0
- data/app/helpers/alchemy/pages_helper_decorator.rb +95 -0
- data/app/models/admin_override_to_param.rb +9 -0
- data/app/models/application_record.rb +9 -0
- data/app/views/alchemy/custom/model/admin/base/_buttons_tool.html.erb +16 -0
- data/app/views/alchemy/custom/model/admin/base/_gallery_item.html.erb +4 -0
- data/app/views/alchemy/custom/model/admin/base/_language_tree_select.html.erb +9 -0
- data/app/views/alchemy/custom/model/admin/base/_search_box.html.erb +19 -0
- data/app/views/alchemy/custom/model/admin/base/_seo.html.erb +8 -0
- data/app/views/alchemy/custom/model/admin/base/_table.html.erb +33 -0
- data/app/views/alchemy/custom/model/admin/base/_title.html.erb +3 -0
- data/app/views/alchemy/custom/model/admin/base/edit.html.erb +18 -0
- data/app/views/alchemy/custom/model/admin/base/index.html.erb +39 -0
- data/app/views/alchemy/custom/model/admin/base/new.html.erb +19 -0
- data/app/views/alchemy/custom/model/admin/files/error_notice.json.jbuilder +1 -0
- data/app/views/alchemy/custom/model/admin/files/ui.html.erb +13 -0
- data/config/initializers/elfinder_abilities.rb +1 -0
- data/config/locales/en.yml +11 -0
- data/config/locales/it.yml +21 -0
- data/config/routes.rb +8 -0
- data/lib/alchemy-custom-model.rb +29 -0
- data/lib/alchemy/custom/model/el_finder.rb +17 -0
- data/lib/alchemy/custom/model/el_finder/ability.rb +16 -0
- data/lib/alchemy/custom/model/el_finder/connector.rb +435 -0
- data/lib/alchemy/custom/model/el_finder/image.rb +35 -0
- data/lib/alchemy/custom/model/el_finder/path_name.rb +220 -0
- data/lib/alchemy/custom/model/el_finder/paths.rb +21 -0
- data/lib/alchemy/custom/model/el_finder/paths/active_record_reference.rb +50 -0
- data/lib/alchemy/custom/model/el_finder/paths/base.rb +298 -0
- data/lib/alchemy/custom/model/el_finder/paths/component_file.rb +59 -0
- data/lib/alchemy/custom/model/el_finder/paths/component_files.rb +34 -0
- data/lib/alchemy/custom/model/el_finder/paths/file.rb +23 -0
- data/lib/alchemy/custom/model/el_finder/paths/files.rb +25 -0
- data/lib/alchemy/custom/model/el_finder/paths/image.rb +42 -0
- data/lib/alchemy/custom/model/el_finder/paths/images.rb +31 -0
- data/lib/alchemy/custom/model/el_finder/paths/root.rb +24 -0
- data/lib/alchemy/custom/model/el_finder/volumes.rb +18 -0
- data/lib/alchemy/custom/model/el_finder/volumes/alchemy_file.rb +197 -0
- data/lib/alchemy/custom/model/el_finder/volumes/alchemy_files.rb +51 -0
- data/lib/alchemy/custom/model/el_finder/volumes/alchemy_images.rb +69 -0
- data/lib/alchemy/custom/model/el_finder/volumes/base.rb +149 -0
- data/lib/alchemy/custom/model/el_finder/volumes/component_attribute.rb +130 -0
- data/lib/alchemy/custom/model/engine.rb +40 -0
- data/lib/alchemy/custom/model/global_id_setter.rb +35 -0
- data/lib/alchemy/custom/model/model_decoration.rb +82 -0
- data/lib/alchemy/custom/model/pages_controller_dec.rb +132 -0
- data/lib/alchemy/custom/model/translation_scope.rb +18 -0
- data/lib/alchemy/custom/model/version.rb +7 -0
- data/lib/alchemy/touching_decorator.rb +12 -0
- data/lib/tasks/alchemy_custom_model_tasks.rake +41 -0
- data/vendor/elfinder/css/elfinder.full.css +5117 -0
- data/vendor/elfinder/css/elfinder.min.css +9 -0
- data/vendor/elfinder/css/theme.css +349 -0
- data/vendor/elfinder/js/elfinder.full.js +34270 -0
- data/vendor/elfinder/js/elfinder.min.js +25 -0
- metadata +194 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'shellwords'
|
3
|
+
require 'image_size'
|
4
|
+
|
5
|
+
|
6
|
+
module Alchemy::Custom::Model::ElFinder
|
7
|
+
|
8
|
+
# Represents default image handler.
|
9
|
+
# It uses *mogrify* to resize images and *convert* to create thumbnails.
|
10
|
+
class Image
|
11
|
+
|
12
|
+
def self.size(pathname)
|
13
|
+
return nil unless File.exist?(pathname)
|
14
|
+
s = ::ImageSize.new(File.open(pathname)).size.to_s
|
15
|
+
s = nil if s.empty?
|
16
|
+
return s
|
17
|
+
rescue
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.resize(pathname, options = {})
|
22
|
+
return nil unless File.exist?(pathname)
|
23
|
+
system(::Shellwords.join(['mogrify', '-resize', "#{options[:width]}x#{options[:height]}!", pathname.to_s]))
|
24
|
+
end
|
25
|
+
|
26
|
+
# of self.resize
|
27
|
+
|
28
|
+
def self.thumbnail(src, dst, options = {})
|
29
|
+
return nil unless File.exist?(src)
|
30
|
+
system(::Shellwords.join(['convert', '-resize', "#{options[:width]}x#{options[:height]}", '-background', 'white', '-gravity', 'center', '-extent', "#{options[:width]}x#{options[:height]}", src.to_s, dst.to_s]))
|
31
|
+
end # of self.resize
|
32
|
+
|
33
|
+
end # of class Image
|
34
|
+
|
35
|
+
end # of module ElFinder
|
@@ -0,0 +1,220 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
module Alchemy::Custom::Model::ElFinder
|
5
|
+
|
6
|
+
class PathName
|
7
|
+
attr_reader :root, :path
|
8
|
+
|
9
|
+
#
|
10
|
+
def initialize(root, path = '.')
|
11
|
+
@root = root.is_a?(PathName) ? root.root : ::Pathname.new(root)
|
12
|
+
|
13
|
+
@path = ::Pathname.new(path)
|
14
|
+
@path = path.is_a?(PathName) ? path.path : ::Pathname.new(path)
|
15
|
+
if absolute?
|
16
|
+
if @path.cleanpath.to_s.start_with?(@root.to_s)
|
17
|
+
@path = ::Pathname.new @path.to_s.slice((@root.to_s.length + 1)..-1)
|
18
|
+
elsif @path.cleanpath.to_s.start_with?(@root.realpath.to_s)
|
19
|
+
@path = ::Pathname.new @path.to_s.slice((@root.realpath.to_s.length + 1)..-1)
|
20
|
+
else
|
21
|
+
raise SecurityError, "Absolute paths are not allowed"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
raise SecurityError, "Paths outside the root are not allowed" if outside_of_root?
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
# of initialize
|
29
|
+
|
30
|
+
#
|
31
|
+
def +(other)
|
32
|
+
if other.is_a? PathN ame
|
33
|
+
other = other.path
|
34
|
+
end
|
35
|
+
self.class.new(@root, (@path + other).to_s)
|
36
|
+
end
|
37
|
+
|
38
|
+
# of +
|
39
|
+
|
40
|
+
#
|
41
|
+
def is_root?
|
42
|
+
@path.to_s == '.'
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
def absolute?
|
47
|
+
@path.absolute?
|
48
|
+
end
|
49
|
+
|
50
|
+
# of absolute?
|
51
|
+
|
52
|
+
#
|
53
|
+
def relative?
|
54
|
+
@path.relative?
|
55
|
+
end
|
56
|
+
|
57
|
+
# of relative?
|
58
|
+
|
59
|
+
#
|
60
|
+
def outside_of_root?
|
61
|
+
!cleanpath.to_s.start_with?(@root.to_s)
|
62
|
+
end
|
63
|
+
|
64
|
+
# of outside_of_root?
|
65
|
+
|
66
|
+
#
|
67
|
+
def fullpath
|
68
|
+
@path.nil? ? @root : @root + @path
|
69
|
+
end
|
70
|
+
|
71
|
+
# of fullpath
|
72
|
+
|
73
|
+
#
|
74
|
+
def cleanpath
|
75
|
+
fullpath.cleanpath
|
76
|
+
end
|
77
|
+
|
78
|
+
# of cleanpath
|
79
|
+
|
80
|
+
#
|
81
|
+
def realpath
|
82
|
+
fullpath.realpath
|
83
|
+
end
|
84
|
+
|
85
|
+
# of realpath
|
86
|
+
|
87
|
+
#
|
88
|
+
def basename(*args)
|
89
|
+
@path.basename(*args)
|
90
|
+
end
|
91
|
+
|
92
|
+
# of basename
|
93
|
+
|
94
|
+
#
|
95
|
+
def basename_sans_extension
|
96
|
+
@path.basename(@path.extname)
|
97
|
+
end
|
98
|
+
|
99
|
+
# of basename
|
100
|
+
|
101
|
+
#
|
102
|
+
def basename(*args)
|
103
|
+
@path.basename(*args)
|
104
|
+
end
|
105
|
+
|
106
|
+
# of basename
|
107
|
+
|
108
|
+
#
|
109
|
+
def dirname
|
110
|
+
self.class.new(@root, @path.dirname)
|
111
|
+
end
|
112
|
+
|
113
|
+
# of basename
|
114
|
+
|
115
|
+
#
|
116
|
+
def extname
|
117
|
+
@path.nil? ? '' : @path.extname
|
118
|
+
end
|
119
|
+
|
120
|
+
# of extname
|
121
|
+
|
122
|
+
#
|
123
|
+
def to_s
|
124
|
+
cleanpath.to_s
|
125
|
+
end
|
126
|
+
|
127
|
+
# of to_s
|
128
|
+
alias_method :to_str, :to_s
|
129
|
+
|
130
|
+
#
|
131
|
+
def child_directories(with_directory = true)
|
132
|
+
realpath.children(with_directory).select {|child| child.directory?}.map {|e| self.class.new(@root, e)}
|
133
|
+
end
|
134
|
+
|
135
|
+
#
|
136
|
+
def children(with_directory = true)
|
137
|
+
realpath.children(with_directory).map {|e| self.class.new(@root, e)}
|
138
|
+
end
|
139
|
+
|
140
|
+
#
|
141
|
+
def touch(options = {})
|
142
|
+
FileUtils.touch(cleanpath, options)
|
143
|
+
end
|
144
|
+
|
145
|
+
#
|
146
|
+
def relative_to(other)
|
147
|
+
@path.relative_path_from(other)
|
148
|
+
end
|
149
|
+
|
150
|
+
#
|
151
|
+
def unique
|
152
|
+
return self.dup unless self.file?
|
153
|
+
copy = 1
|
154
|
+
begin
|
155
|
+
new_file = self.class.new(@root, dirname + "#{basename_sans_extension} #{copy}#{extname}")
|
156
|
+
copy += 1
|
157
|
+
end while new_file.exist?
|
158
|
+
new_file
|
159
|
+
end
|
160
|
+
|
161
|
+
# of unique
|
162
|
+
|
163
|
+
#
|
164
|
+
def duplicate
|
165
|
+
_basename = basename_sans_extension
|
166
|
+
copy = 1
|
167
|
+
if _basename.to_s =~ /^(.*) copy (\d+)$/
|
168
|
+
_basename = $1
|
169
|
+
copy = $2.to_i
|
170
|
+
end
|
171
|
+
begin
|
172
|
+
new_file = self.class.new(@root, dirname + "#{_basename} copy #{copy}#{extname}")
|
173
|
+
copy += 1
|
174
|
+
end while new_file.exist?
|
175
|
+
new_file
|
176
|
+
end
|
177
|
+
|
178
|
+
# of duplicate
|
179
|
+
|
180
|
+
#
|
181
|
+
def rename(to)
|
182
|
+
to = self.class.new(@root, to.to_s)
|
183
|
+
realpath.rename(to.fullpath.to_s)
|
184
|
+
rescue Errno::EXDEV
|
185
|
+
FileUtils.move(realpath.to_s, to.fullpath.to_s)
|
186
|
+
ensure
|
187
|
+
@path = to.path
|
188
|
+
end
|
189
|
+
|
190
|
+
# of rename
|
191
|
+
|
192
|
+
{
|
193
|
+
'directory?' => {:path => 'realpath', :rescue => true},
|
194
|
+
'exist?' => {:path => 'realpath', :rescue => true},
|
195
|
+
'file?' => {:path => 'realpath', :rescue => true},
|
196
|
+
'ftype' => {:path => 'realpath', },
|
197
|
+
'mkdir' => {:path => 'fullpath', :args => '(*args)'},
|
198
|
+
'mtime' => {:path => 'realpath', },
|
199
|
+
'open' => {:path => 'fullpath', :args => '(*args, &block)'},
|
200
|
+
'read' => {:path => 'fullpath', :args => '(*args)'},
|
201
|
+
'readlink' => {:path => 'fullpath', },
|
202
|
+
'readable?' => {:path => 'realpath', :rescue => true},
|
203
|
+
'size' => {:path => 'realpath', },
|
204
|
+
'symlink?' => {:path => 'fullpath', },
|
205
|
+
'unlink' => {:path => 'realpath', },
|
206
|
+
'writable?' => {:path => 'realpath', :rescue => true},
|
207
|
+
}.each_pair do |meth, opts|
|
208
|
+
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
209
|
+
def #{meth}#{opts[:args]}
|
210
|
+
#{opts[:path]}.#{meth}#{opts[:args]}
|
211
|
+
#{"rescue Errno::ENOENT\nfalse" if opts[:rescue]}
|
212
|
+
end
|
213
|
+
METHOD
|
214
|
+
end
|
215
|
+
|
216
|
+
|
217
|
+
end # of class Pathname
|
218
|
+
|
219
|
+
end # of module ElFinder
|
220
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Alchemy
|
2
|
+
module Custom
|
3
|
+
module Model
|
4
|
+
module ElFinder::Paths
|
5
|
+
extend ActiveSupport::Autoload
|
6
|
+
|
7
|
+
autoload :ActiveRecordReference
|
8
|
+
autoload :Base
|
9
|
+
autoload :ComponentFile
|
10
|
+
autoload :ComponentFiles
|
11
|
+
autoload :File
|
12
|
+
autoload :Files
|
13
|
+
autoload :Image
|
14
|
+
autoload :Images
|
15
|
+
autoload :Root
|
16
|
+
# eager_autoload do
|
17
|
+
# end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Alchemy::Custom::Model::ElFinder
|
2
|
+
module Paths
|
3
|
+
class ActiveRecordReference < Base
|
4
|
+
|
5
|
+
|
6
|
+
URI_SPACER = '___'
|
7
|
+
|
8
|
+
def file?
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
12
|
+
def directory?
|
13
|
+
false
|
14
|
+
end
|
15
|
+
|
16
|
+
def active_record_class
|
17
|
+
raise "ToOverride"
|
18
|
+
end
|
19
|
+
|
20
|
+
def active_record_instance=(v)
|
21
|
+
@_active_record_instance = v
|
22
|
+
end
|
23
|
+
|
24
|
+
def active_record_instance
|
25
|
+
return @_active_record_instance if @_active_record_instance
|
26
|
+
id = self.path.basename.to_s.split(URI_SPACER).first
|
27
|
+
@_active_record_instance = self.active_record_class.find(id)
|
28
|
+
|
29
|
+
# gid = "gid://#{self.path.basename.to_s}"#.split(URI_SPACER)
|
30
|
+
# @_active_record_instance = GlobalID::Locator.locate gid# self.active_record_class.find(id)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.file_to_uri(p)
|
34
|
+
#p.to_global_id.uri.to_s.gsub(/^gid\:\/\//,'')
|
35
|
+
"#{p.id}#{URI_SPACER}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def file
|
39
|
+
active_record_instance.file
|
40
|
+
end
|
41
|
+
|
42
|
+
def fisical_path
|
43
|
+
file.path
|
44
|
+
end
|
45
|
+
|
46
|
+
delegate :name, :mime_type, :size, to: :file
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,298 @@
|
|
1
|
+
module Alchemy::Custom::Model::ElFinder
|
2
|
+
module Paths
|
3
|
+
class Base
|
4
|
+
|
5
|
+
attr_reader :root, :path, :volume
|
6
|
+
|
7
|
+
#
|
8
|
+
def initialize(root, path = '.', opts = {})
|
9
|
+
|
10
|
+
Rails.logger.debug {root.inspect}
|
11
|
+
Rails.logger.debug {path.inspect}
|
12
|
+
|
13
|
+
@volume = opts.delete(:volume)
|
14
|
+
|
15
|
+
@root = root.is_a?(PathName) ? root.root : ::Pathname.new(root)
|
16
|
+
|
17
|
+
@path = ::Pathname.new(path)
|
18
|
+
@path = path.is_a?(PathName) ? path.path : ::Pathname.new(path)
|
19
|
+
if absolute?
|
20
|
+
if @path.cleanpath.to_s.start_with?(@root.to_s)
|
21
|
+
@path = ::Pathname.new @path.to_s.slice((@root.to_s.length + 1)..-1)
|
22
|
+
elsif @path.cleanpath.to_s.start_with?(@root.realpath.to_s)
|
23
|
+
@path = ::Pathname.new @path.to_s.slice((@root.realpath.to_s.length + 1)..-1)
|
24
|
+
else
|
25
|
+
raise SecurityError, "Absolute paths are not allowed"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
raise SecurityError, "Paths outside the root are not allowed" if outside_of_root?
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
# of initialize
|
33
|
+
|
34
|
+
#
|
35
|
+
# def +(other)
|
36
|
+
# if other.is_a? ::ElFinder::Pathname
|
37
|
+
# other = other.path
|
38
|
+
# end
|
39
|
+
# self.class.new(@root, (@path + other).to_s)
|
40
|
+
# end
|
41
|
+
|
42
|
+
# of +
|
43
|
+
|
44
|
+
#
|
45
|
+
def is_root?
|
46
|
+
Rails.logger.debug {"IS_ROOT?:#{@path} - #{ @path.to_s == '.'}"}
|
47
|
+
@path.to_s == '.'
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
def absolute?
|
52
|
+
@path.absolute?
|
53
|
+
end
|
54
|
+
|
55
|
+
# of absolute?
|
56
|
+
|
57
|
+
#
|
58
|
+
def relative?
|
59
|
+
@path.relative?
|
60
|
+
end
|
61
|
+
|
62
|
+
# of relative?
|
63
|
+
|
64
|
+
#
|
65
|
+
def outside_of_root?
|
66
|
+
!cleanpath.to_s.start_with?(@root.to_s)
|
67
|
+
end
|
68
|
+
|
69
|
+
# of outside_of_root?
|
70
|
+
|
71
|
+
#
|
72
|
+
def fullpath
|
73
|
+
@path.nil? ? @root : @root + @path
|
74
|
+
end
|
75
|
+
|
76
|
+
# of fullpath
|
77
|
+
|
78
|
+
#
|
79
|
+
def cleanpath
|
80
|
+
fullpath.cleanpath
|
81
|
+
end
|
82
|
+
|
83
|
+
# of cleanpath
|
84
|
+
|
85
|
+
#
|
86
|
+
def realpath
|
87
|
+
fullpath
|
88
|
+
end
|
89
|
+
|
90
|
+
# of realpath
|
91
|
+
|
92
|
+
#
|
93
|
+
def basename(*args)
|
94
|
+
@path.basename(*args)
|
95
|
+
end
|
96
|
+
|
97
|
+
# of basename
|
98
|
+
|
99
|
+
#
|
100
|
+
def basename_sans_extension
|
101
|
+
@path.basename(@path.extname)
|
102
|
+
end
|
103
|
+
|
104
|
+
# of basename
|
105
|
+
|
106
|
+
#
|
107
|
+
def basename(*args)
|
108
|
+
Rails.logger.debug {"BASE_NAME:#{@path.inspect}"}
|
109
|
+
@path.basename(*args)
|
110
|
+
end
|
111
|
+
|
112
|
+
# of basename
|
113
|
+
|
114
|
+
#
|
115
|
+
def dirname
|
116
|
+
self.class.new(@root, @path.dirname, volume: @volume)
|
117
|
+
end
|
118
|
+
|
119
|
+
# of basename
|
120
|
+
|
121
|
+
#
|
122
|
+
def extname
|
123
|
+
@path.nil? ? '' : @path.extname
|
124
|
+
end
|
125
|
+
|
126
|
+
# of extname
|
127
|
+
|
128
|
+
#
|
129
|
+
def to_s
|
130
|
+
cleanpath.to_s
|
131
|
+
end
|
132
|
+
|
133
|
+
# of to_s
|
134
|
+
alias_method :to_str, :to_s
|
135
|
+
|
136
|
+
#
|
137
|
+
def child_directories(with_directory = true)
|
138
|
+
realpath.children(with_directory).select {|child| child.directory?}.map {|e| self.class.new(@root, e, volume: @volume)}
|
139
|
+
end
|
140
|
+
|
141
|
+
#
|
142
|
+
# def children(with_directory = true)
|
143
|
+
# realpath.children(with_directory).map {|e| self.class.new(@root, e)}
|
144
|
+
# end
|
145
|
+
|
146
|
+
#
|
147
|
+
# def touch(options = {})
|
148
|
+
# FileUtils.touch(cleanpath, options)
|
149
|
+
# end
|
150
|
+
|
151
|
+
#
|
152
|
+
def relative_to(other)
|
153
|
+
@path.relative_path_from(other)
|
154
|
+
end
|
155
|
+
|
156
|
+
#
|
157
|
+
def unique
|
158
|
+
return self.dup unless self.file?
|
159
|
+
copy = 1
|
160
|
+
begin
|
161
|
+
new_file = self.class.new(@root, dirname + "#{basename_sans_extension} #{copy}#{extname}", volume: @volume)
|
162
|
+
copy += 1
|
163
|
+
end while new_file.exist?
|
164
|
+
new_file
|
165
|
+
end
|
166
|
+
|
167
|
+
# of unique
|
168
|
+
|
169
|
+
#
|
170
|
+
def duplicate
|
171
|
+
_basename = basename_sans_extension
|
172
|
+
copy = 1
|
173
|
+
if _basename.to_s =~ /^(.*) copy (\d+)$/
|
174
|
+
_basename = $1
|
175
|
+
copy = $2.to_i
|
176
|
+
end
|
177
|
+
begin
|
178
|
+
new_file = self.class.new(@root, dirname + "#{_basename} copy #{copy}#{extname}", volume: @volume)
|
179
|
+
copy += 1
|
180
|
+
end while new_file.exist?
|
181
|
+
new_file
|
182
|
+
end
|
183
|
+
|
184
|
+
# of duplicate
|
185
|
+
|
186
|
+
#
|
187
|
+
def rename(to)
|
188
|
+
to = self.class.new(@root, to.to_s, volume: @volume)
|
189
|
+
realpath.rename(to.fullpath.to_s)
|
190
|
+
rescue Errno::EXDEV
|
191
|
+
FileUtils.move(realpath.to_s, to.fullpath.to_s)
|
192
|
+
ensure
|
193
|
+
@path = to.path
|
194
|
+
end
|
195
|
+
|
196
|
+
# of rename
|
197
|
+
|
198
|
+
# {
|
199
|
+
# 'directory?' => {:path => 'realpath', :rescue => true},
|
200
|
+
# 'exist?' => {:path => 'realpath', :rescue => true},
|
201
|
+
# 'file?' => {:path => 'realpath', :rescue => true},
|
202
|
+
# 'ftype' => {:path => 'realpath', },
|
203
|
+
# 'mkdir' => {:path => 'fullpath', :args => '(*args)'},
|
204
|
+
# 'mtime' => {:path => 'realpath', },
|
205
|
+
# 'open' => {:path => 'fullpath', :args => '(*args, &block)'},
|
206
|
+
# 'read' => {:path => 'fullpath', :args => '(*args)'},
|
207
|
+
# 'readlink' => {:path => 'fullpath', },
|
208
|
+
# 'readable?' => {:path => 'realpath', :rescue => true},
|
209
|
+
# 'size' => {:path => 'realpath', },
|
210
|
+
# 'symlink?' => {:path => 'fullpath', },
|
211
|
+
# 'unlink' => {:path => 'realpath', },
|
212
|
+
# 'writable?' => {:path => 'realpath', :rescue => true},
|
213
|
+
# }.each_pair do |meth, opts|
|
214
|
+
# class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
215
|
+
# def #{meth}#{opts[:args]}
|
216
|
+
# #{opts[:path]}.#{meth}#{opts[:args]}
|
217
|
+
# #{"rescue Errno::ENOENT\nfalse" if opts[:rescue]}
|
218
|
+
# end
|
219
|
+
# METHOD
|
220
|
+
# end
|
221
|
+
|
222
|
+
#
|
223
|
+
def file?
|
224
|
+
false
|
225
|
+
end
|
226
|
+
|
227
|
+
def is_image?
|
228
|
+
false
|
229
|
+
end
|
230
|
+
|
231
|
+
def directory?
|
232
|
+
true
|
233
|
+
end
|
234
|
+
|
235
|
+
# def is_root?
|
236
|
+
# false
|
237
|
+
# end
|
238
|
+
#
|
239
|
+
def with_sub_dirs?
|
240
|
+
false
|
241
|
+
end
|
242
|
+
|
243
|
+
#
|
244
|
+
# def basename
|
245
|
+
# ''
|
246
|
+
# end
|
247
|
+
#
|
248
|
+
# def parent_path
|
249
|
+
# self.root
|
250
|
+
# end
|
251
|
+
#
|
252
|
+
# def path
|
253
|
+
# File.join(self.root, basename)
|
254
|
+
# end
|
255
|
+
#
|
256
|
+
# ##
|
257
|
+
# # Data Di modifica della cartella
|
258
|
+
def mtime
|
259
|
+
DateTime.now
|
260
|
+
end
|
261
|
+
|
262
|
+
#
|
263
|
+
def children(with_directory = true)
|
264
|
+
[]
|
265
|
+
end
|
266
|
+
|
267
|
+
#
|
268
|
+
# url per la thumb
|
269
|
+
def tmb
|
270
|
+
nil
|
271
|
+
end
|
272
|
+
|
273
|
+
##
|
274
|
+
# Nome visualizzato in interfaccia
|
275
|
+
def name
|
276
|
+
self.basename.to_s
|
277
|
+
end
|
278
|
+
|
279
|
+
def mime_type
|
280
|
+
'directory'
|
281
|
+
end
|
282
|
+
|
283
|
+
def fisical_path
|
284
|
+
''
|
285
|
+
end
|
286
|
+
|
287
|
+
def global_id
|
288
|
+
nil
|
289
|
+
end
|
290
|
+
|
291
|
+
def full_fill_paylod(payload)
|
292
|
+
payload
|
293
|
+
end
|
294
|
+
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|