Sha256: 98a8a033dff9616ac381a77427b44fd06184ef965d7ce6d4ae6f3896865deed7
Contents?: true
Size: 1.36 KB
Versions: 1
Compression:
Stored size: 1.36 KB
Contents
#encoding: utf-8 class I18nAttributes::ModelGenerator < Rails::Generators::NamedBase source_root File.expand_path('../templates', __FILE__) class_option :orm, :required => true argument :attributes, :type => :array, :default => [], :banner => "field:type field:type" include ::VkillGemsMethods::Rails::Generators::Base include ::I18nAttributes::GeneratorHelpers SUPPORTED_ORMS = %w(active_model active_record mongoid) def create_model_i18n_file say_error "#{orm} [not found]" unless SUPPORTED_ORMS.include? options.orm.to_s I18nAttributes::Configuration.locales.each do |locale| create_file "config/locales/model_#{ locale }/#{ file_name }.yml", generate_yaml_file_data( :locale => locale, :singular_name => singular_name, :human_name => human_name, :attributes => attributes_hash(), :model_i18n_scope => model_i18n_scope() ){|word| say_info "translated attribute/model_name #{word}"}.yaml_file_data end end private def attributes_hash Hash[ attributes.map {|attribute| [attribute.name, attribute.type] } ] end def model_i18n_scope case options.orm.to_s when "active_model" :activemodel when "active_record" :activerecord when "mongoid" :mongoid end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
i18n_attributes-0.1.6 | lib/generators/i18n_attributes/model/model_generator.rb |