Class: AbstractInterface::ViewBuilder

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#templateObject (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

  options = {}.to_openobject
  prepare_form! options, *args
  
  # wrap_theme 'forms/begin', true do
    concat render(:partial => themed_partial('forms/begin'), :object => options)
    concat capture(b, &block)
    concat render(:partial => themed_partial('forms/end'), :object => options)
  # end
end

#form_for(record_or_name_or_array, *args, &proc) ⇒ Object

Raises:

  • (ArgumentError)


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?

  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) || {}
  
  # wrap_theme 'forms/begin', true do
    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
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 options *args, &block
  opt = args.extract_options!
  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