Sha256: 3cbe828f2b6a5e666c65d699c1923a0c617ed2456125b07b3129d9efd5c0f234

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

module EmberCLI
  class AssetResolver
    def initialize(app:, sprockets:)
      @app = app
      @sprockets = sprockets
    end

    def resolve_urls(html_content)
      mappings.reduce(html_content) do |resolved_content, (asset, new_path)|
        resolved_content.gsub(%{"assets/#{asset}"}, %{"#{new_path}"})
      end
    end

    private

    def mappings
      {
        "#{name}.js" => application.js,
        "#{name}.css" => application.css,
        "vendor.js" => vendor.js,
        "vendor.css" => vendor.css,
      }
    end

    def name
      @app.name
    end

    def application
      AssetPath.new(@sprockets, @app.application_assets)
    end

    def vendor
      AssetPath.new(@sprockets, @app.vendor_assets)
    end

    class AssetPath
      def initialize(sprockets, assets)
        @sprockets = sprockets
        @assets = assets
      end

      def js
        @sprockets.asset_path(@assets, type: :javascript)
      end

      def css
        @sprockets.asset_path(@assets, type: :stylesheet)
      end
    end

    private_constant :AssetPath
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ember-cli-rails-0.4.1 lib/ember-cli/asset_resolver.rb
ember-cli-rails-0.4.0 lib/ember-cli/asset_resolver.rb