39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/dynamite.rb', line 39
def dynamite_inputs type_partials = {}
dir = File.expand_path('../default_partials', __FILE__)
default_partials = {
:textbox => "#{dir}/_textbox.html.erb",
:textarea => "#{dir}/_textarea.html.erb",
:email => "#{dir}/_email.html.erb",
:tickbox => "#{dir}/_tickbox.html.erb"
}
out = [];
JSON.parse(@object.schema)['inputs'].each do |input|
type = input['type'].to_sym
value = @object.vars()[input['label']]
is_error = !@object.errors.get(input['label'].to_sym).nil?
if !type_partials[type].nil?
out.push @template.render :partial => partials[type], :locals => {:form => self, :name => @object_name, :input => input, :value => value, :is_error => is_error}
elsif !default_partials[type].nil?
out.push @template.render :file => default_partials[type], :locals => {:form => self, :name => @object_name, :input => input, :value => value, :is_error => is_error}
else
out.push @template.render :partial => partials[:textbox], :locals => {:form => self, :name => @object_name, :input => input, :value => value, :is_error => is_error}
end
end
out.join.html_safe;
end
|