11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/xmvc/generators/model.rb', line 11
def generate(name, *fields)
filename = Extlib::Inflection.underscore(name)
@var_name = filename
@class_name = Extlib::Inflection.camelize(name)
@fields = fields.map {|f|
field = f.split(':')
{:name => field.shift, :type => field.shift}
}
model_filename = "app/models/#{filename}.js"
spec_filename = "spec/models/#{filename}.spec.js"
unless File.exists?(model_filename)
Xmvc::Config.add(:models, filename)
end
template("Model.js", model_filename)
template("ModelSpec.js", spec_filename)
end
|