Sha256: 4c6448af49bee85d9a39b392ba1df523070f5a2fe7f9d0ddf720a5453cf5d3c0

Contents?: true

Size: 1.4 KB

Versions: 4

Compression:

Stored size: 1.4 KB

Contents

class RichI18nTranslationGenerator < Rails::Generator::Base
  def initialize(runtime_args, runtime_options = {})
    super
    @name = @args.first || "translation"
  end

  def manifest
    record do |m|
      m.directory                          "app/models"
      m.template               "model.rb", "app/models/#{model_file_name}.rb"
      m.template              "config.rb", "config/initializers/enrichments.rb", {:collision => :skip}
      m.migration_template "migration.rb", "db/migrate", :migration_file_name => migration_file_name
    end
  end
  
  def after_generate
    File.open(destination_path("config/initializers/enrichments.rb"), "a+") do |file|
      file << "\nRich::I18n::Engine.enable_i18n_cms"
    end
    
    system "rake db:migrate" if options[:migrate]
  end

  def model_file_name
    @name.underscore
  end

  def model_class_name
    @name.classify
  end
  
  def table_name
    model_file_name.gsub("/", "_").pluralize
  end

  def migration_file_name
    "create_#{table_name}"
  end

  def migration_class_name
    migration_file_name.camelize
  end

protected

  def add_options!(opt)
    opt.separator ""
    opt.separator "Options:"
    opt.on("-m", "--migrate", "Run 'rake db:migrate' after generating model and migration.") { options[:migrate] = true }
  end

  def banner
    <<-EOS
Creates Rich-i18n translation model and migration.

USAGE: #{$0} #{spec.name} [model_name]
EOS
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rich_i18n-1.2.3 rails_generators/rich_i18n_translation/rich_i18n_translation_generator.rb
rich_i18n-1.2.2 rails_generators/rich_i18n_translation/rich_i18n_translation_generator.rb
rich_i18n-1.2.1 rails_generators/rich_i18n_translation/rich_i18n_translation_generator.rb
rich_i18n-1.2.0 rails_generators/rich_i18n_translation/rich_i18n_translation_generator.rb