Sha256: 86dbcaf68e8296495857a73510e732ed927feee5acb7381c39f867746219770f

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

module FrontendGenerators; class AssetsCopier

  attr_reader :local_asset_dirname

  # local_asset_dirname is assets/bootstrap/ or assets/font_awesome/

  def initialize(local_asset_dirname, destination_root = Rails.root)
    @local_asset_dirname = local_asset_dirname
    @destination_root = destination_root
  end

  def copy_assets
    local_assets.each do |local_asset_path|
      d = destination_asset_dirname(local_asset_path)
      p message(local_asset_path)
      FileUtils.mkdir_p(d)
      copy_asset(local_asset_path)
    end
  end

  def message(local_asset_path)
    puts "#{Rainbow("create").green}    #{destination_truncated_path(local_asset_path)}"
  end

  def local_assets_root
    "#{root}/#{local_asset_dirname}"
  end

  def local_assets
    Dir.glob("#{local_assets_root}**/*").select{|f| File.file?(f)}
  end

  def destination_asset_dirname(local_asset_path)
    p = local_asset_path.gsub(local_assets_root, destination_root)
    File.dirname(p)
  end

  def destination_truncated_path(local_asset_path)
    local_asset_path.gsub(local_assets_root, "")
  end

  def copy_asset(local_asset_path)
    destination = destination_asset_dirname(local_asset_path)
    FileUtils.cp(local_asset_path, destination)
  end

  def root
    File.expand_path("../../", File.dirname(__FILE__))
  end

  def destination_root
    "#{@destination_root}/"
  end

end; end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
frontend-generators-0.0.2 lib/frontend_generators/assets_copier.rb