Class: Rad::Face::ViewBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/face/view_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template) ⇒ ViewBuilder

Returns a new instance of ViewBuilder.



17
18
19
# File 'lib/face/view_builder.rb', line 17

def initialize template
  @template = template
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object (protected)



93
94
95
# File 'lib/face/view_builder.rb', line 93

def method_missing m, *args, &block
  render_block "/#{m}", *args, &block
end

Instance Attribute Details

#templateObject (readonly)

def self.generate_view_helper_methods methods

methods.each do |folder, templates|
  templates.each do |template|
    code = %{\

def #{template} *args, &block

render_block "#{folder}", "#{template}", *args, &block

end}

      eval code, binding, __FILE__, __LINE__
    end
  end      
end


16
17
18
# File 'lib/face/view_builder.rb', line 16

def template
  @template
end

Instance Method Details

#form_for(*args, &block) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/face/view_builder.rb', line 70

def form_for *args, &block
  model_helper, options = template.build_form_model_helper_and_form_options *args
      
  form_tag options do |themed_form_helper|
    model_helper.form_helper = themed_form_helper
  
    block.call model_helper if block
  end
end

#form_tag(*args, &block) ⇒ Object

Forms



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/face/view_builder.rb', line 53

def form_tag *args, &block
  f = Rad::Face::ThemedFormHelper.new(template)    

  content = block ? capture{block.call(f)} : ""             
  object = Rad::Face::HtmlOpenObject.initialize_from(form_attributes: args, content: content)
  html = render(
    themed_partial('/forms/form'), 
    object: object
  )

  if block
    template.concat html
  else
    html
  end
end

#options(*args, &block) ⇒ Object

Builders



41
42
43
44
45
46
47
# File 'lib/face/view_builder.rb', line 41

def options *args, &block
  opt = args.extract_options!
  args.size.must_be.in 0..1
  opt[:content] = args.first if args.size == 1

  Rad::Face::HamlBuilder.get_input self.template, opt, &block
end

#prepare_form!(options, *args) ⇒ Object



86
87
88
89
90
# File 'lib/face/view_builder.rb', line 86

def prepare_form! options, *args
  buff = template.form_tag *args
  options[:begin] = buff
  options[:end] = '</form>'
end

#render_block(template, *args, &block) ⇒ Object



80
81
82
83
84
# File 'lib/face/view_builder.rb', line 80

def render_block template, *args, &block
  opt = options *args, &block
  html = render themed_partial(template), object: opt
  block ? self.concat(html) : html
end