module InterfaceBuilder class ViewBuilder def self.generate_helper_methods methods methods.each do |folder, templates| templates.each do |template| code = < :template end # # Builders # def options options = {}, &block options.should! :be_a, Hash block.should! :be_a, Proc if block b = HamlBuilder.new self.template block.call b options.merge b.get_value else options end end # # Forms # def form *args, &block b = FormBuilders::ThemedFormTagBuilder.new self.template options = {}.to_openobject prepare_form! options, *args concat render(:partial => themed_partial('forms/begin'), :object => options) concat capture(b, &block) concat render(:partial => themed_partial('forms/end'), :object => options) end def form_for(record_or_name_or_array, *args, &proc) raise ArgumentError, "Missing block" unless block_given? options = args.extract_options! case record_or_name_or_array when String, Symbol object_name = record_or_name_or_array object = instance_variable_get "@#{record_or_name_or_array}" when Array object = record_or_name_or_array.last object_name = ActionController::RecordIdentifier.singular_class_name(object) self.template.apply_form_for_options!(record_or_name_or_array, options) args.unshift object else object = record_or_name_or_array object_name = ActionController::RecordIdentifier.singular_class_name(object) self.template.apply_form_for_options!([object], options) args.unshift object end # Rendering Form renderer_options = {}.to_openobject prepare_form! renderer_options, options.delete(:url) || {}, options.delete(:html) || {} concat render(:partial => themed_partial('forms/begin'), :object => renderer_options) options[:builder] = FormBuilders::ThemedFormBuilder self.template.fields_for(object_name, *(args << options), &proc) concat render(:partial => themed_partial('forms/end'), :object => renderer_options) end private def render_haml_builder folder, template, *args, &block opt = args.extract_options! args.size.should! :be_in, 0..1 opt[:content] = args.first if args.size == 1 if block if block.arity <= 0 opt[:content] ||= self.template.capture &block else b = HamlBuilder.new self.template block.call b opt = opt.merge b.get_value end end opt = opt.to_openobject html = render :partial => themed_partial("#{folder}/#{template}"), :object => opt block ? self.concat(html) : html end def prepare_form! options, *args buff = template.form_tag *args options[:begin] = buff options[:end] = '' end end end