6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/generators/brain_damage/lib/views/factory.rb', line 6
def self.create(type, field, options = {})
if options.is_a? Symbol
subtype = options
options = { type: options }
else
subtype = options[:type]
end
type = type.to_s
subtype = subtype.to_s
if File.exists? __dir__+"/#{type.pluralize}/#{subtype}.rb"
require_relative "#{type.pluralize}/#{subtype}"
eval("#{type.camelize.singularize}::#{subtype.camelize}").new field, options
else
require_relative "#{type.pluralize}/base"
options[:template_file] = "#{subtype.underscore}.html.haml"
eval("#{type.camelize.singularize}::Base").new field, options
end
end
|