Class: FileManager

Inherits:
Zarchitect show all
Defined in:
lib/zarchitect/file_manager.rb

Constant Summary

Constants inherited from Zarchitect

Zarchitect::ASSETDIR, Zarchitect::ASSETSDIR, Zarchitect::BUILDIR, Zarchitect::CONFIGDIR, Zarchitect::DEBUGSDIR, Zarchitect::DRAFTDIR, Zarchitect::FILEDIR, Zarchitect::FILESDIR, Zarchitect::HTMLDIR, Zarchitect::LAYOUTDIR, Zarchitect::NODEDIR, Zarchitect::SHARESDIR, Zarchitect::VERSION

Instance Method Summary collapse

Methods inherited from Zarchitect

#main, #rss

Constructor Details

#initializeFileManager

Returns a new instance of FileManager.



3
4
5
6
7
8
9
10
11
# File 'lib/zarchitect/file_manager.rb', line 3

def initialize
  @from = FILEDIR # where user puts files
  @to = File.join(HTMLDIR, FILESDIR) # files in website dir tree

  @img = Array.new
  @audio = Array.new
  @video = Array.new
  @misc  = Array.new
end

Instance Method Details

#cleanObject



59
60
61
62
# File 'lib/zarchitect/file_manager.rb', line 59

def clean
  # remove all files in _html/files
  %x{rm -r _html/files/*} 
end

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/zarchitect/file_manager.rb', line 13

def run
  # iterate FROM 
  Dir[ File.join(@from, '**', '*') ].reject do |fullpath|
    path = fullpath[(@from.length)..-1]
    realpath = File.join(@to, path) # path of new dir/symlink
    
    # dir handling / create copies in TO
    Util.mkdir(realpath) if File.directory?(fullpath)
    next if File.directory?(fullpath)
    # file handling
    # handle file types embedded in posts
    if Image.is_valid?(fullpath)
      GPI.print "processing #{fullpath} as image file",
        GPI::CLU.check_option('v')
      @img.push ImageSet.new(path, fullpath, realpath)
    elsif Audio.is_valid?(fullpath)
      GPI.print "processing #{fullpath} as audio file",
        GPI::CLU.check_option('v')
      @audio.push Audio.new(fullpath)
    elsif Video.is_valid?(fullpath)
      GPI.print "processing #{fullpath} as video file",
        GPI::CLU.check_option('v')
      @video.push Video.new(fullpath)
    else
      GPI.print "processing #{fullpath} as any file",
        GPI::CLU.check_option('v')
      @misc.push MiscFile.new(fullpath)
    end
    # create symlink in _html/files to physical files _files (if process did
    # not abort)
    unless File.symlink?(realpath)
      rrealpath = File.join(Dir.getwd, fullpath)
      symlink(rrealpath, realpath)
    end

  end
end


51
52
53
54
55
56
57
# File 'lib/zarchitect/file_manager.rb', line 51

def symlink(from, to)
  GPI.print "creating symlink #{to} ~> #{from}", 
    GPI::CLU.check_option('v')
  File.symlink(from, to)
  GPI.print "created symlink #{to} ~> #{from}",
    GPI::CLU.check_option('v')
end