Sha256: 26629a3faf42ccfbfe8e4de405580be20fd6d1410fe20424828f45b113200906

Contents?: true

Size: 1.41 KB

Versions: 25

Compression:

Stored size: 1.41 KB

Contents

module RedmineCrm
  class AssetsManager
    def self.install_assets
      return unless Gem.loaded_specs[GEM_NAME]
      source = File.join(Gem.loaded_specs[GEM_NAME].full_gem_path, 'vendor', 'assets')
      destination = File.join(Dir.pwd, 'public', 'plugin_assets', GEM_NAME)
      return unless File.directory?(source)

      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|
        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
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
redmine_crm-0.0.63 lib/redmine_crm/assets_manager.rb
redmine_crm-0.0.62 lib/redmine_crm/assets_manager.rb
redmine_crm-0.0.61 lib/redmine_crm/assets_manager.rb
redmine_crm-0.0.60 lib/redmine_crm/assets_manager.rb
redmine_crm-0.0.59 lib/redmine_crm/assets_manager.rb
redmine_crm-0.0.58 lib/redmine_crm/assets_manager.rb
redmine_crm-0.0.57 lib/redmine_crm/assets_manager.rb
redmine_crm-0.0.56 lib/redmine_crm/assets_manager.rb
redmine_crm-0.0.55 lib/redmine_crm/assets_manager.rb
redmine_crm-0.0.54 lib/redmine_crm/assets_manager.rb
redmine_crm-0.0.53 lib/redmine_crm/assets_manager.rb
redmine_crm-0.0.52 lib/redmine_crm/assets_manager.rb
redmine_crm-0.0.51 lib/redmine_crm/assets_manager.rb
redmine_crm-0.0.50 lib/redmine_crm/assets_manager.rb
redmine_crm-0.0.49 lib/redmine_crm/assets_manager.rb
redmine_crm-0.0.48 lib/redmine_crm/assets_manager.rb
redmine_crm-0.0.47 lib/redmine_crm/assets_manager.rb
redmine_crm-0.0.46 lib/redmine_crm/assets_manager.rb
redmine_crm-0.0.45 lib/redmine_crm/assets_manager.rb
redmine_crm-0.0.44 lib/redmine_crm/assets_manager.rb