Module: RedminePluginAssetPipeline::PluginPatch::InstanceMethods

Defined in:
lib/redmine_plugin_asset_pipeline/plugin_patch.rb

Instance Method Summary collapse

Instance Method Details

#mirror_assets_to_privateObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/redmine_plugin_asset_pipeline/plugin_patch.rb', line 28

def mirror_assets_to_private
  source = assets_directory
  destination = private_directory

  unless File.exist?(self.class.private_directory)
    FileUtils.mkdir_p(self.class.private_directory)
  end

  if File.exist?(destination)
    FileUtils.rm_rf(destination)
  end
  return unless File.directory?(source)

  if RedminePluginAssetPipeline.config.use_ln
    if File.exist?(source)
      FileUtils.ln_s(source, destination)
    end
  else
    source_files = Dir[source + "/**/*"]
    source_dirs = source_files.select { |d| File.directory?(d) }
    source_files -= source_dirs
    unless source_files.empty?
      base_target_dir = File.join(destination, File.dirname(source_files.first).gsub(source, ''))
      begin
        FileUtils.mkdir_p(base_target_dir)
      rescue Exception => e
        raise "Could not create directory #{base_target_dir}: " + e.message
      end
    end
    source_dirs.each do |dir|
      # strip down these paths so we have simple, relative paths we can
      # add to the destination
      target_dir = File.join(destination, dir.gsub(source, ''))
      begin
        FileUtils.mkdir_p(target_dir)
      rescue Exception => e
        raise "Could not create directory #{target_dir}: " + e.message
      end
    end

    source_files.each do |file|
      begin
        target = File.join(destination, file.gsub(source, ''))
        unless File.exist?(target) && FileUtils.identical?(file, target)
          FileUtils.cp(file, target)
        end
      rescue Exception => e
        raise "Could not copy #{file} to #{target}: " + e.message
      end
    end
  end
end

#private_directoryObject



24
25
26
# File 'lib/redmine_plugin_asset_pipeline/plugin_patch.rb', line 24

def private_directory
  File.join(self.class.private_directory, id.to_s)
end