Sha256: e35c1264c5e18632d4df4a69905545175911482fd149f5f8d0a3220e8472fb03
Contents?: true
Size: 1.15 KB
Versions: 2
Compression:
Stored size: 1.15 KB
Contents
module ExtJS module MVC module Generator class Model < Base def initialize(name, fields = []) super @fields = fields @gsubs['name'] = name.capitalize @gsubs['model_name'] = name @gsubs['inst_name'] = name.downcase @gsubs['fields'] = fields.collect {|f| field_template(f[0], f[1])}.join(",\n") @model_filename = "app/models/#{@gsubs['name']}.js" @spec_filename = "spec/models/#{@gsubs['name']}.spec.js" end def generate! ensure_no_overwrite! @model_filename, @spec_filename ensure_directories_present! "app", "app/models" ensure_directories_present! "spec", "spec/models" template "Model.js", @model_filename template "ModelSpec.js", @spec_filename end private def field_template(name, type) padding = longest_field_length - name.length " {name: '#{name}', #{" " * padding}type: '#{type}'}" end def longest_field_length @fields.collect {|f| f[0].length}.max end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
extjs-mvc-0.4.0.b | lib/extjs-mvc/generators/model.rb |
extjs-mvc-0.4.0.a | lib/extjs-mvc/generators/model.rb |