Class: FrontendGenerators::AssetsCopier
- Inherits:
-
Object
- Object
- FrontendGenerators::AssetsCopier
- Defined in:
- lib/frontend_generators/assets_copier.rb
Instance Attribute Summary collapse
-
#local_asset_dirname ⇒ Object
readonly
Returns the value of attribute local_asset_dirname.
Instance Method Summary collapse
- #copy_asset(local_asset_path) ⇒ Object
- #copy_assets ⇒ Object
- #destination_asset_dirname(local_asset_path) ⇒ Object
- #destination_root ⇒ Object
- #destination_truncated_path(local_asset_path) ⇒ Object
-
#initialize(local_asset_dirname, destination_root = Rails.root) ⇒ AssetsCopier
constructor
local_asset_dirname is assets/bootstrap/ or assets/font_awesome/.
- #local_assets ⇒ Object
- #local_assets_root ⇒ Object
- #message(local_asset_path) ⇒ Object
- #root ⇒ Object
Constructor Details
#initialize(local_asset_dirname, destination_root = Rails.root) ⇒ AssetsCopier
local_asset_dirname is assets/bootstrap/ or assets/font_awesome/
7 8 9 10 |
# File 'lib/frontend_generators/assets_copier.rb', line 7 def initialize(local_asset_dirname, destination_root = Rails.root) @local_asset_dirname = local_asset_dirname @destination_root = destination_root end |
Instance Attribute Details
#local_asset_dirname ⇒ Object (readonly)
Returns the value of attribute local_asset_dirname.
3 4 5 |
# File 'lib/frontend_generators/assets_copier.rb', line 3 def local_asset_dirname @local_asset_dirname end |
Instance Method Details
#copy_asset(local_asset_path) ⇒ Object
42 43 44 45 |
# File 'lib/frontend_generators/assets_copier.rb', line 42 def copy_asset(local_asset_path) destination = destination_asset_dirname(local_asset_path) FileUtils.cp(local_asset_path, destination) end |
#copy_assets ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/frontend_generators/assets_copier.rb', line 12 def copy_assets local_assets.each do |local_asset_path| d = destination_asset_dirname(local_asset_path) p (local_asset_path) FileUtils.mkdir_p(d) copy_asset(local_asset_path) end end |
#destination_asset_dirname(local_asset_path) ⇒ Object
33 34 35 36 |
# File 'lib/frontend_generators/assets_copier.rb', line 33 def destination_asset_dirname(local_asset_path) p = local_asset_path.gsub(local_assets_root, destination_root) File.dirname(p) end |
#destination_root ⇒ Object
51 52 53 |
# File 'lib/frontend_generators/assets_copier.rb', line 51 def destination_root "#{@destination_root}/" end |
#destination_truncated_path(local_asset_path) ⇒ Object
38 39 40 |
# File 'lib/frontend_generators/assets_copier.rb', line 38 def destination_truncated_path(local_asset_path) local_asset_path.gsub(local_assets_root, "") end |
#local_assets ⇒ Object
29 30 31 |
# File 'lib/frontend_generators/assets_copier.rb', line 29 def local_assets Dir.glob("#{local_assets_root}**/*").select{|f| File.file?(f)} end |
#local_assets_root ⇒ Object
25 26 27 |
# File 'lib/frontend_generators/assets_copier.rb', line 25 def local_assets_root "#{root}/#{local_asset_dirname}" end |
#message(local_asset_path) ⇒ Object
21 22 23 |
# File 'lib/frontend_generators/assets_copier.rb', line 21 def (local_asset_path) puts "#{Rainbow("create").green} #{destination_truncated_path(local_asset_path)}" end |
#root ⇒ Object
47 48 49 |
# File 'lib/frontend_generators/assets_copier.rb', line 47 def root File.("../../", File.dirname(__FILE__)) end |