Sha256: bdc7a666a7aa13d70e6fdf1fbc1fdf46147aeb4ad5d1b5b567179a351416d01a

Contents?: true

Size: 1.53 KB

Versions: 3

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

module ExtractI18n::Adapters
  class VuePugAdapter < SlimAdapter
    def run(original_content)
      super
      check_javascript_for_strings!
      @new_content.join("\n")
    end

    def check_javascript_for_strings!
      lines = @new_content
      # drop lines until <script
      start = lines.find_index { |line| line[/^<script/] }
      finish = lines.find_index { |line| line[/^<\/script/] }
      return if start.nil? || finish.nil?

      js_content = lines[(start + 1)...finish].join("\n")

      js_adapter = ExtractI18n::Adapters::JsAdapter.new(file_key: @file_key, on_ask: @on_ask, options: @options)
      js_replaced = js_adapter.run(js_content)

      @new_content = lines[0..start] + js_replaced.split("\n") + lines[(finish)..-1]
    end

    def process_line(old_line)
      @mode ||= :template
      if old_line[/^<template/]
        @mode = :template
      elsif old_line[/^<script/]
        @mode = :script
      elsif old_line[/^<style/]
        @mode = :style
      end
      if @mode != :template
        return old_line
      end
      word = ExtractI18n::Slimkeyfy::Word.for('.vue').new(old_line)
      ExtractI18n::Slimkeyfy::VueTransformer.new(word, @file_key).transform do |change|
        if change.nil? # nothing to do
          return old_line
        end
        if ExtractI18n.ignore?(change.i18n_string) || change.i18n_string.empty?
          return old_line
        end

        if @on_ask.call(change)
          change.i18n_t
        else
          old_line
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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