Sha256: aeec809f62394612f3224c1605791034c0a8d0d1ba5e2be2da0380f40d53243d

Contents?: true

Size: 1.69 KB

Versions: 1

Compression:

Stored size: 1.69 KB

Contents

require "yaml"

module Sofav
  module Local
    def create_config_record(file_name, record)
      record_config = YAML.load_file(File.join(__dir__, '../generators/sofav/templates/activerecord.zh-CN.yml'))
      
      record_config["zh-CN"]["activerecord"]["models"] = {"#{file_name}" => nil}
      record_config["zh-CN"]["activerecord"]["attributes"] = {"#{file_name}" => {"#{record.first}" => nil}}
      record.shift

      record.each do |a|
        record_config["zh-CN"]["activerecord"]["attributes"]["#{file_name}"][a] = nil
      end

      create_file "config/locales/activerecord/#{file_name}.zh-CN.yml", <<-FILE
#{record_config.to_yaml}
      FILE
    end

    def create_config_attribute(file_name, types)
      attributes_config = YAML.load_file(File.join(__dir__, '../generators/sofav/templates/attribute_types.zh-CN.yml'))
      attributes_config["zh-CN"]["attribute_types"] = {"#{file_name}" => {"#{types.first.name}" => nil}}

      types.each do |t|
        attributes_config["zh-CN"]["attribute_types"]["#{file_name}"]["#{t.name}"] = {"type" => nil}
        attributes_config["zh-CN"]["attribute_types"]["#{file_name}"]["#{t.name}"]["required"] = true
        attributes_config["zh-CN"]["attribute_types"]["#{file_name}"]["#{t.name}"]["type"] = type_field(t.type)
      end

      create_file "config/locales/attribute_types/#{file_name}.zh-CN.yml", <<-FILE
#{attributes_config.to_yaml}
      FILE
    end

    private
    def type_field(type)
      case type
      when 'integer', 'float'
        "number_field"
      when 'datetime'
        "datetime_select"
      when 'boolean'
        "collection_check_box"
      when 'date'
        "date_select"
      else
        "text_field"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sofav-0.2.0 lib/sofav/local.rb