Sha256: 8ace18c61904aaa252420e295e81699ccbaf3c54ca957e48c010aad7d69d3168

Contents?: true

Size: 871 Bytes

Versions: 3

Compression:

Stored size: 871 Bytes

Contents

# frozen_string_literal: true

module ExtractI18n::Adapters
  class Adapter
    def self.for(file_path)
      case file_path
      when /\.rb$/ then RubyAdapter
      when /\.erb$/ then ErbAdapter
      when /\.slim$/ then SlimAdapter
      when /\.ts$/, /\.js$/, /\.mjs/, /\.jsx$/ then JsAdapter
      when /\.vue$/
        if File.read(file_path)[/lang=.pug./]
          VuePugAdapter
        else
          VueAdapter
        end
      end
    end

    attr_reader :on_ask, :file_path, :file_key, :options

    def initialize(file_key:, on_ask:, options: {})
      @on_ask = on_ask
      @file_key = file_key
      @options = options
    end

    def run(content)
      raise NotImplementedError
    end

    def self.supports_relative_keys?
      false
    end

    private

    def original_content
      @original_content ||= File.read(file_path)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
extract_i18n-0.7.2 lib/extract_i18n/adapters/adapter.rb
extract_i18n-0.7.1 lib/extract_i18n/adapters/adapter.rb
extract_i18n-0.7.0 lib/extract_i18n/adapters/adapter.rb