Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Add asset_sync gem (#67)
Browse files Browse the repository at this point in the history
* Add asset_sync gem

* Update to add dotenv support

* Add FOG_DIRECTORY ENV
  • Loading branch information
dvdgs88 authored and pablorc committed Oct 19, 2018
1 parent fcf106e commit 10fe892
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions recipes/carrier_wave.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@ class CarrierWave < Base

def gems
@template.gem 'carrierwave'
@template.gem 'asset_sync'
@template.gem 'fog-aws'
end

def cook
add_initializer
add_application_config
add_production_env_config
end

private

def add_initializer
@template.initializer 'carrierwave.rb', <<~CODE
require 'carrierwave/storage/fog'
CarrierWave.configure do |config|
Expand All @@ -29,14 +38,23 @@ def cook
}
end
CODE
end

def add_application_config
@template.append_file '.env.sample', "\nAWS_ACCESS_KEY=''"
@template.append_file '.env', "\nAWS_ACCESS_KEY=''"
@template.append_file '.env.sample', "\nAWS_SECRET_KEY=''"
@template.append_file '.env', "\nAWS_SECRET_KEY=''"
@template.append_file '.env.sample', "\nAWS_S3_BUCKET=''"
@template.append_file '.env.sample', "\nFOG_DIRECTORY=''"
@template.append_file '.env', "\nAWS_ACCESS_KEY=''"
@template.append_file '.env', "\nAWS_SECRET_KEY=''"
@template.append_file '.env', "\nAWS_S3_BUCKET=''"
end
@template.append_file '.env', "\nFOG_DIRECTORY=''"
end

def add_production_env_config
@template.gsub_file 'config/environments/production.rb',
'# config.action_controller.asset_host = \'http://assets.example.com\'',
'config.action_controller.asset_host = "//#{ENV[\'FOG_DIRECTORY\']}.s3.amazonaws.com"'
end
end
end

0 comments on commit 10fe892

Please sign in to comment.