Class: AbstractInterface::ViewBuilder
- Inherits:
-
Object
- Object
- AbstractInterface::ViewBuilder
- Defined in:
- lib/abstract_interface/view_builder.rb
Constant Summary collapse
- PROXY_METHODS =
Template methods
%w{ capture concat content_for content_tag render themed_partial themed_partial_exist? themed_resource }
Instance Attribute Summary collapse
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Class Method Summary collapse
Instance Method Summary collapse
-
#form(*args, &block) ⇒ Object
Forms.
- #form_for(record_or_name_or_array, *args, &proc) ⇒ Object
-
#initialize(template) ⇒ ViewBuilder
constructor
A new instance of ViewBuilder.
-
#options(*args, &block) ⇒ Object
Builders.
Constructor Details
#initialize(template) ⇒ ViewBuilder
Returns a new instance of ViewBuilder.
21 22 23 |
# File 'lib/abstract_interface/view_builder.rb', line 21 def initialize template @template = template end |
Instance Attribute Details
#template ⇒ Object (readonly)
Returns the value of attribute template.
20 21 22 |
# File 'lib/abstract_interface/view_builder.rb', line 20 def template @template end |
Class Method Details
.generate_helper_methods(methods) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/abstract_interface/view_builder.rb', line 4 def self.generate_helper_methods methods methods.each do |folder, templates| templates.each do |template| code = %{\ def #{template} *args, &block render_haml_builder "#{folder}", "#{template}", *args, &block end} eval code, binding, __FILE__, __LINE__ end end end |
Instance Method Details
#form(*args, &block) ⇒ Object
Forms
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/abstract_interface/view_builder.rb', line 67 def form *args, &block b = FormBuilders::ThemedFormTagBuilder.new self.template = {}.to_openobject prepare_form! , *args # wrap_theme 'forms/begin', true do concat render(:partial => themed_partial('forms/begin'), :object => ) concat capture(b, &block) concat render(:partial => themed_partial('forms/end'), :object => ) # end end |
#form_for(record_or_name_or_array, *args, &proc) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/abstract_interface/view_builder.rb', line 80 def form_for(record_or_name_or_array, *args, &proc) raise ArgumentError, "Missing block" unless block_given? = args. 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.(record_or_name_or_array, ) args.unshift object else object = record_or_name_or_array object_name = ActionController::RecordIdentifier.singular_class_name(object) self.template.([object], ) args.unshift object end # Rendering Form = {}.to_openobject prepare_form! , .delete(:url) || {}, .delete(:html) || {} # wrap_theme 'forms/begin', true do concat render(:partial => themed_partial('forms/begin'), :object => ) [:builder] = FormBuilders::ThemedFormBuilder self.template.fields_for(object_name, *(args << ), &proc) concat render(:partial => themed_partial('forms/end'), :object => ) # end end |
#options(*args, &block) ⇒ Object
Builders
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/abstract_interface/view_builder.rb', line 47 def *args, &block opt = args. args.size.should! :be_in, 0..1 opt[:content] = args.first if args.size == 1 HamlBuilder.get_input self.template, opt, &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 |