Module: Locomotive::Wagon::AssetsConcern
- Included in:
- PullBaseCommand
- Defined in:
- lib/locomotive/wagon/commands/pull_sub_commands/concerns/assets_concern.rb
Constant Summary collapse
- REGEX =
/((https?:\/\/\S+)?\/sites\/[0-9a-f]{24}\/(assets|pages|theme|content_entry[0-9a-f]{24})\/(([^;.\"]+)\/)*([a-zA-Z_\-0-9.%]+)(\?\w+)?)/
Instance Method Summary collapse
-
#replace_asset_urls(content) ⇒ Object
The content assets on the remote engine follows the format: /sites/<id>/assets/<type>/<file> This method replaces these urls by their local representation.
- #replace_asset_urls_in_hash(hash) ⇒ Object
Instance Method Details
#replace_asset_urls(content) ⇒ Object
The content assets on the remote engine follows the format: /sites/<id>/assets/<type>/<file> This method replaces these urls by their local representation. <type>/<file>
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/locomotive/wagon/commands/pull_sub_commands/concerns/assets_concern.rb', line 17 def replace_asset_urls(content) return '' if content.blank? _content = content.dup content.force_encoding('utf-8').scan(REGEX).map do |match| url, type, filename = match[0], match[2], match[5] folder = case type when 'assets', 'pages' then File.join('samples', "_#{env}", type) when 'theme' then $4 when /\Acontent_entry/ then File.join('samples', "_#{env}", 'content_entries') end Thread.new do if filepath = write_asset(url, File.join(path, 'public', folder, filename)) [url, File.join('', folder, File.basename(filepath)).to_s] else [url, ''] end end end.map(&:value).each do |(url, replacement)| _content.gsub!(url, replacement) end _content end |
#replace_asset_urls_in_hash(hash) ⇒ Object
44 45 46 47 48 |
# File 'lib/locomotive/wagon/commands/pull_sub_commands/concerns/assets_concern.rb', line 44 def replace_asset_urls_in_hash(hash) Locomotive::Wagon::YamlExt.transform(hash) do |value| replace_asset_urls(value) end end |