Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add include_manifest feature #365

Merged
merged 3 commits into from
Dec 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ AssetSync.configure do |config|
# upload instead of searching the assets directory.
# config.manifest = true
#
# Upload the manifest file also.
# config.include_manifest = false
#
# Fail silently. Useful for environments such as Heroku
# config.fail_silently = true
#
Expand Down Expand Up @@ -318,6 +321,7 @@ AssetSync.config.gzip_compression == ENV['ASSET_SYNC_GZIP_COMPRESSION']
* **existing_remote_files**: (`'keep', 'delete', 'ignore'`) what to do with previously precompiled files. **default:** `'keep'`
* **gzip\_compression**: (`true, false`) when enabled, will automatically replace files that have a gzip compressed equivalent with the compressed version. **default:** `'false'`
* **manifest**: (`true, false`) when enabled, will use the `manifest.yml` generated by Rails to get the list of local files to upload. **experimental**. **default:** `'false'`
* **include_manifest**: (`true, false`) when enabled, will upload the `manifest.yml` generated by Rails. **default:** `'false'`
* **enabled**: (`true, false`) when false, will disable asset sync. **default:** `'true'` (enabled)
* **ignored\_files**: an array of files to ignore e.g. `['ignore_me.js', %r(ignore_some/\d{32}\.css)]` Useful if there are some files that are created dynamically on the server and you don't want to upload on deploy **default**: `[]`
* **cache\_asset\_regexps**: an array of files to add cache headers e.g. `['cache_me.js', %r(cache_some\.\d{8}\.css)]` Useful if there are some files that are added to sprockets assets list and need to be set as 'Cacheable' on uploaded server. Only rails compiled regexp is matched internally **default**: `[]`
Expand Down
3 changes: 3 additions & 0 deletions lib/asset_sync/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Invalid < StandardError; end
attr_accessor :invalidate
attr_accessor :cdn_distribution_id
attr_accessor :cache_asset_regexps
attr_accessor :include_manifest

# FOG configuration
attr_accessor :fog_provider # Currently Supported ['AWS', 'Rackspace']
Expand Down Expand Up @@ -73,6 +74,7 @@ def initialize
self.cdn_distribution_id = nil
self.invalidate = []
self.cache_asset_regexps = []
self.include_manifest = false
@additional_local_file_paths_procs = []

load_yml! if defined?(::Rails) && yml_exists?
Expand Down Expand Up @@ -182,6 +184,7 @@ def load_yml!
self.invalidate = yml["invalidate"] if yml.has_key?("invalidate")
self.cdn_distribution_id = yml['cdn_distribution_id'] if yml.has_key?("cdn_distribution_id")
self.cache_asset_regexps = yml['cache_asset_regexps'] if yml.has_key?("cache_asset_regexps")
self.include_manifest = yml['include_manifest'] if yml.has_key?("include_manifest")

self.azure_storage_account_name = yml['azure_storage_account_name'] if yml.has_key?("azure_storage_account_name")
self.azure_storage_access_key = yml['azure_storage_access_key'] if yml.has_key?("azure_storage_access_key")
Expand Down
1 change: 1 addition & 0 deletions lib/asset_sync/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Engine < Rails::Engine

config.gzip_compression = (ENV['ASSET_SYNC_GZIP_COMPRESSION'] == 'true') if ENV.has_key?('ASSET_SYNC_GZIP_COMPRESSION')
config.manifest = (ENV['ASSET_SYNC_MANIFEST'] == 'true') if ENV.has_key?('ASSET_SYNC_MANIFEST')
config.include_manifest = (ENV['ASSET_SYNC_INCLUDE_MANIFEST'] == 'true') if ENV.has_key?('ASSET_SYNC_INCLUDE_MANIFEST')
end

config.prefix = ENV['ASSET_SYNC_PREFIX'] if ENV.has_key?('ASSET_SYNC_PREFIX')
Expand Down
14 changes: 13 additions & 1 deletion lib/asset_sync/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,25 @@ def ignored_files
expand_file_names(self.config.ignored_files)
end

def get_manifest_path
return [] unless self.config.include_manifest

if ActionView::Base.respond_to?(:assets_manifest)
manifest = Sprockets::Manifest.new(ActionView::Base.assets_manifest.environment, ActionView::Base.assets_manifest.dir)
manifest_path = manifest.filename
else
manifest_path = self.config.manifest_path
end
[manifest_path.sub(/^#{path}\//, "")] # full path to relative path
end

def local_files
@local_files ||=
(get_local_files + config.additional_local_file_paths).uniq
end

def always_upload_files
expand_file_names(self.config.always_upload)
expand_file_names(self.config.always_upload) + get_manifest_path
end

def files_with_custom_headers
Expand Down
3 changes: 3 additions & 0 deletions lib/generators/asset_sync/templates/asset_sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
# upload instead of searching the assets directory.
# config.manifest = true
#
# Upload the manifest file also.
# config.include_manifest = false
#
# Fail silently. Useful for environments such as Heroku
# config.fail_silently = true
#
Expand Down