Sha256: c595480083c2339cdbb31b8ffd3ffa8eb675d1f2a5b08fd5211ff1a130e01c86

Contents?: true

Size: 1.39 KB

Versions: 10

Compression:

Stored size: 1.39 KB

Contents

require "baidu_ueditor_rails/asset_manifest"

module BaiduUeditorRails
  class AssetInstaller
    ASSETS = Pathname.new(File.expand_path(File.dirname(__FILE__) + "/../../vendor/assets/javascripts/ueditor"))

    def initialize(target, manifest_path)
      @target = target
      @manifest_path = manifest_path || target
    end

    def install
      cleanup_assets
      copy_assets
      append_to_manifest

      manifest.write
    end

  private
    def manifest
      @manifest ||= AssetManifest.load(@manifest_path)
    end

    def cleanup_assets
      manifest.each(/^ueditor\//) do |asset|
        manifest.remove(asset) if index_asset?(asset)

        manifest.remove_digest(asset) do |src, dest|
          move_asset(src, dest)
        end
      end
    end

    def copy_assets
      FileUtils.cp_r(ASSETS, @target, :preserve => true)
    end

    def append_to_manifest
      asset_files.each do |file|
        manifest.append(logical_path(file), file)
      end
    end

    def asset_files
      Pathname.glob("#{ASSETS}/**/*").select(&:file?)
    end

    def logical_path(file)
      file.relative_path_from(ASSETS.parent).to_s
    end

    def move_asset(src, dest)
      src = File.join(@target, src)
      dest = File.join(@target, dest)

      FileUtils.mv(src, dest, :force => true) if src != dest && File.exists?(src)
    end

    def index_asset?(asset)
      asset =~ /\/index\.js$/
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
baidu_ueditor_rails-0.2.3 lib/baidu_ueditor_rails/asset_installer.rb
baidu_ueditor_rails-0.2.2 lib/baidu_ueditor_rails/asset_installer.rb
baidu_ueditor_rails-0.2.1 lib/baidu_ueditor_rails/asset_installer.rb
baidu_ueditor_rails-0.2.0 lib/baidu_ueditor_rails/asset_installer.rb
baidu_ueditor_rails-0.1.0 lib/baidu_ueditor_rails/asset_installer.rb
baidu_ueditor_rails-0.0.5 lib/baidu_ueditor_rails/asset_installer.rb
baidu_ueditor_rails-0.0.4 lib/baidu_ueditor_rails/asset_installer.rb
baidu_ueditor_rails-0.0.3 lib/baidu_ueditor_rails/asset_installer.rb
baidu_ueditor_rails-0.0.2 lib/baidu_ueditor_rails/asset_installer.rb
baidu_ueditor_rails-0.0.1 lib/baidu_ueditor_rails/asset_installer.rb