Class: Percy::Capybara::Loaders::EmberCliRailsLoader

Inherits:
SprocketsLoader show all
Defined in:
lib/percy/capybara/loaders/ember_cli_rails_loader.rb

Constant Summary collapse

EMBER_ASSETS_DIR =
'assets'.freeze

Constants inherited from SprocketsLoader

SprocketsLoader::MAX_FILESIZE_BYTES, SprocketsLoader::SKIP_RESOURCE_EXTENSIONS

Constants inherited from BaseLoader

BaseLoader::MAX_FILESIZE_BYTES, BaseLoader::SKIP_RESOURCE_EXTENSIONS, BaseLoader::URL_REGEX

Instance Attribute Summary collapse

Attributes inherited from SprocketsLoader

#page, #sprockets_environment, #sprockets_options

Attributes inherited from BaseLoader

#page

Instance Method Summary collapse

Methods inherited from SprocketsLoader

#_asset_logical_paths, #_rails, #snapshot_resources

Methods inherited from BaseLoader

#_resources_from_dir, #_uri_join, #snapshot_resources

Constructor Details

#initialize(mounted_apps, options = {}) ⇒ EmberCliRailsLoader

Returns a new instance of EmberCliRailsLoader.



11
12
13
14
15
16
# File 'lib/percy/capybara/loaders/ember_cli_rails_loader.rb', line 11

def initialize(mounted_apps, options = {})
  super(options)

  raise 'mounted_apps is required' unless mounted_apps
  @mounted_apps = mounted_apps
end

Instance Attribute Details

#mounted_appsObject (readonly)

Returns the value of attribute mounted_apps.



7
8
9
# File 'lib/percy/capybara/loaders/ember_cli_rails_loader.rb', line 7

def mounted_apps
  @mounted_apps
end

Instance Method Details

#_dist_path_for_app(app_name) ⇒ Object



40
41
42
# File 'lib/percy/capybara/loaders/ember_cli_rails_loader.rb', line 40

def _dist_path_for_app(app_name)
  _ember_cli.apps[app_name].dist_path
end

#_ember_cliObject



44
45
46
# File 'lib/percy/capybara/loaders/ember_cli_rails_loader.rb', line 44

def _ember_cli
  EmberCli if defined?(EmberCli)
end

#build_resourcesObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/percy/capybara/loaders/ember_cli_rails_loader.rb', line 18

def build_resources
  resources = []

  @mounted_apps.map do |app_name, mount_path|
    # public assets path for this particular ember app. If the app is mounted on /admin
    # the output would be: /admin/assets
    base_assets_url = File.join(mount_path, EMBER_ASSETS_DIR)

    # full path on disk to the assets for this ember app
    # e.g. /Users/djones/Code/rails-ember-app/tmp/ember-cli/apps/frontend
    dist_path = _dist_path_for_app(app_name)

    # full path to the directory on disk where ember stores assets for this ember app
    # e.g. /Users/djones/Code/rails-ember-app/tmp/ember-cli/apps/frontend/assets
    ember_assets_path = File.join(dist_path, EMBER_ASSETS_DIR)

    resources += _resources_from_dir(ember_assets_path, base_url: base_assets_url)
  end

  resources += super # adds sprockets resources from Rails
end