Sha256: b79c9d948131ddfc23554c1b33670966825787f82b9298d64776ebf75acde97a

Contents?: true

Size: 808 Bytes

Versions: 2

Compression:

Stored size: 808 Bytes

Contents

# frozen_string_literal: true

module TsAssets
  module Generators
    class ConstGenerator < TsAssets::ApplicationGenerator

      # @return [Hash]
      attr_reader :mapping

      # @param [Hash] mapping
      def initialize(mapping)
        @mapping = mapping
      end

      # @return [TsAssets::Models::Content]
      def generate
        ts_paths = mapping.map { |full_path, asset_meta_info| constify(asset_meta_info) }
        TsAssets::Models::Content.new(header: nil, body: ts_paths.join("\n"))
      end

      # @param [TsAssets::Models::AssetMetaInfo] meta_info
      # @return [String]
      def constify(meta_info)
        <<~TS
          /** #{meta_info.asset_path} */
          const #{meta_info.normalised_path} = "/assets/#{meta_info.digest_path}";
        TS
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ts_assets-1.1.1 lib/ts_assets/generators/const_generator.rb
ts_assets-1.1.0 lib/ts_assets/generators/const_generator.rb