Module: Lolita::Builder

Overview

Any Lolita::Configuration class that should return visual information about itself can include Builder::Base, that provide default methods for controllers to use.

  • #build method is used to render component for class instance.

  • #build_options is method that return specific options for builder, to pass to component, such as :color,:postition etc.

  • #builder is setter/getter method for Lolita::Configuration, that accept Hash or Array or single String or Symbol for buider.

Instance Method Summary collapse

Instance Method Details

#build(*args) ⇒ Object

Build response. Render component for current class with given options.



14
15
16
17
18
19
20
21
# File 'lib/lolita/builder.rb', line 14

def build(*args)
  args||=[]
  options=args.extract_options!
  builder_options=self.builder_options || {}
  options=(options || {}).merge(builder_options)
  builder_values=self.get_builder(*args)
  return builder_values[:name].to_sym,builder_values[:state].to_sym,options
end

#builder_optionsObject

Default options for class. This method should be overwritten.



24
25
26
# File 'lib/lolita/builder.rb', line 24

def builder_options
  {builder_local_variable_name=>self}
end

#default_builderObject

Return default builder information.



49
50
51
# File 'lib/lolita/builder.rb', line 49

def default_builder
  {:name=>"/#{builder_name}".to_sym,:state=>default_build_state}
end

#get_builder(*value) ⇒ Object

Set or get builder for class. Value can be

  • Hash where key :name is component name and :state is component state

  • Array or two args - first is used as name and second as state.

  • String or Symbol (one arg) - is used as name.

Default name is Lolita::Configuration class name (example :list) and default state is :display



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/lolita/builder.rb', line 35

def get_builder(*value)
  if value && !value.empty?
    set_builder(value)
  elsif @builder
    set_builder(@builder)
  else
    unless @builder
      @builder=default_builder
    end
    @builder
  end
end