Sha256: 5f6a71327556e9814844d3fdcd82bd5309663038acb0591e62b071a573e98847

Contents?: true

Size: 777 Bytes

Versions: 5

Compression:

Stored size: 777 Bytes

Contents

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

5 entries across 5 versions & 1 rubygems

Version Path
ts_assets-1.0.0 lib/ts_assets/generators/const_generator.rb
ts_assets-0.1.3 lib/ts_assets/generators/const_generator.rb
ts_assets-0.1.2 lib/ts_assets/generators/const_generator.rb
ts_assets-0.1.1 lib/ts_assets/generators/const_generator.rb
ts_assets-0.1.0 lib/ts_assets/generators/const_generator.rb