class TsAssets::Generators::ConstGenerator

Attributes

mapping[R]

@return [Hash]

Public Class Methods

new(mapping) click to toggle source

@param [Hash] mapping

# File lib/ts_assets/generators/const_generator.rb, line 11
def initialize(mapping)
  @mapping = mapping
end

Public Instance Methods

constify(meta_info) click to toggle source

@param [TsAssets::Models::AssetMetaInfo] meta_info @return [String]

# File lib/ts_assets/generators/const_generator.rb, line 23
      def constify(meta_info)
        <<~TS
          /** #{meta_info.asset_path} */
          const #{meta_info.normalised_path} = "/assets/#{meta_info.digest_path}";
        TS
      end
generate() click to toggle source

@return [TsAssets::Models::Content]

# File lib/ts_assets/generators/const_generator.rb, line 16
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