Sha256: afc56ccb3f6a740dccb97bbcaabe186140d8be0d2f1893c0480bb9ba9b7c72e4

Contents?: true

Size: 925 Bytes

Versions: 8

Compression:

Stored size: 925 Bytes

Contents

require File.expand_path("#{File.dirname(__FILE__)}/lib/insert_commands.rb")

class WebtranslateitGenerator < Rails::Generator::Base

  def add_options!(opt)
    opt.on('-k', '--api-key=key', String, 'Your Web Translate It API key') { |v| options[:api_key] = v }
  end

  def manifest # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
    if !api_key_configured? && !options[:api_key]
      puts 'You must pass --api-key or create config/translations.yml'
      exit
    end
    record do |m|
      if options[:api_key]
        project_details = YAML.load WebTranslateIt::Project.fetch_info(options[:api_key])
        m.template '.wti', '.wti',
                   assigns: {api_key: options[:api_key], project: project_details['project']}
        m.append_to 'Rakefile', "require 'web_translate_it' rescue LoadError"
      end
    end
  end

  def api_key_configured?
    File.exist?('config/translations.yml')
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
web_translate_it-2.7.6 generators/webtranslateit/webtranslateit_generator.rb
web_translate_it-2.7.5 generators/webtranslateit/webtranslateit_generator.rb
web_translate_it-2.7.4 generators/webtranslateit/webtranslateit_generator.rb
web_translate_it-2.7.3 generators/webtranslateit/webtranslateit_generator.rb
web_translate_it-2.7.2 generators/webtranslateit/webtranslateit_generator.rb
web_translate_it-2.7.1 generators/webtranslateit/webtranslateit_generator.rb
web_translate_it-2.7.0 generators/webtranslateit/webtranslateit_generator.rb
web_translate_it-2.6.4 generators/webtranslateit/webtranslateit_generator.rb