Class: Locomotive::Mounter::Reader::Api::ThemeAssetsReader

Inherits:
Base
  • Object
show all
Defined in:
lib/locomotive/mounter/reader/api/theme_assets_reader.rb

Instance Attribute Summary

Attributes inherited from Base

#items, #runner

Instance Method Summary collapse

Methods inherited from Base

#add_content_asset, #get, #mounting_point

Constructor Details

#initialize(runner) ⇒ ThemeAssetsReader

Returns a new instance of ThemeAssetsReader.



8
9
10
11
# File 'lib/locomotive/mounter/reader/api/theme_assets_reader.rb', line 8

def initialize(runner)
  super
  self.items = []
end

Instance Method Details

#readArray

Build the list of theme assets from the public folder with eager loading.

Returns:

  • (Array)

    The cached list of theme assets



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/locomotive/mounter/reader/api/theme_assets_reader.rb', line 17

def read
  super

  self.items = self.get(:theme_assets).map do |attributes|
    url = attributes.delete('url')
    url.gsub!(/^\/\//, "https://")

    attributes['uri'] = URI(url =~ /^https?:\/\// ? url : "#{self.base_uri_with_scheme}#{url}")

    Locomotive::Mounter::Models::ThemeAsset.new(attributes)
  end
end