lolita 3.0.7 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. data/GUIDELINE +4 -0
  2. data/README.rdoc +50 -0
  3. data/VERSION +1 -1
  4. data/app/controllers/lolita/rest_controller.rb +27 -11
  5. data/app/helpers/components/lolita/configuration/list_component.rb +11 -0
  6. data/app/helpers/lolita_helper.rb +1 -1
  7. data/app/views/components/lolita/configuration/field/_display.html.erb +9 -0
  8. data/app/views/components/lolita/configuration/field/_label.html.erb +1 -0
  9. data/app/views/components/lolita/{field → configuration/field}/_object.html.erb +0 -0
  10. data/app/views/components/lolita/configuration/field/array/_display.html.erb +5 -0
  11. data/app/views/components/lolita/configuration/field/array/habtm/_display.html.erb +26 -0
  12. data/app/views/components/lolita/configuration/field/array/select/_display.html.erb +5 -0
  13. data/app/views/components/lolita/configuration/field/big_decimal/_display.html.erb +1 -0
  14. data/app/views/components/lolita/{field/_boolean.html.erb → configuration/field/boolean/_display.html.erb} +0 -0
  15. data/app/views/components/lolita/configuration/field/date/_display.html.erb +1 -0
  16. data/app/views/components/lolita/{field/_string.html.erb → configuration/field/float/_display.html.erb} +0 -0
  17. data/app/views/components/lolita/configuration/field/integer/_display.html.erb +1 -0
  18. data/app/views/components/lolita/configuration/field/string/_display.html.erb +5 -0
  19. data/app/views/components/lolita/{field/_disabled.html.erb → configuration/field/string/disabled/_display.html.erb} +0 -0
  20. data/app/views/components/lolita/{field/_password.html.erb → configuration/field/string/password/_display.html.erb} +0 -0
  21. data/app/views/components/lolita/configuration/field/string/text/_display.html.erb +34 -0
  22. data/app/views/components/lolita/configuration/field/time/_display.html.erb +1 -0
  23. data/app/views/components/lolita/{field_set → configuration/field_set}/_display.html.erb +1 -1
  24. data/app/views/components/lolita/configuration/list/_body.html.erb +5 -0
  25. data/app/views/components/lolita/{list → configuration/list}/_body_cell.html.erb +0 -0
  26. data/app/views/components/lolita/{list → configuration/list}/_checkbox_cell.html.erb +0 -0
  27. data/app/views/components/lolita/{list → configuration/list}/_checkbox_header.html.erb +0 -0
  28. data/app/views/components/lolita/configuration/list/_display.html.erb +12 -0
  29. data/app/views/components/lolita/configuration/list/_filter.html.erb +8 -0
  30. data/app/views/components/lolita/configuration/list/_header.html.erb +9 -0
  31. data/app/views/components/lolita/{list → configuration/list}/_header_cell.html.erb +0 -0
  32. data/app/views/components/lolita/{list → configuration/list}/_new_resource.html.erb +0 -0
  33. data/app/views/components/lolita/configuration/list/_paginator.html.erb +3 -0
  34. data/app/views/components/lolita/configuration/list/_row.html.erb +7 -0
  35. data/app/views/components/lolita/{list → configuration/list}/_title.html.erb +0 -0
  36. data/app/views/components/lolita/{list → configuration/list}/_tool_cell.html.erb +0 -0
  37. data/app/views/components/lolita/{list → configuration/list}/_tool_header.html.erb +0 -0
  38. data/app/views/components/lolita/configuration/tab/_display.html.erb +17 -0
  39. data/app/views/components/lolita/configuration/tab/_fields.html.erb +7 -0
  40. data/app/views/components/lolita/configuration/tab/content/_display.html.erb +1 -0
  41. data/app/views/components/lolita/configuration/tab/default/_display.html.erb +9 -0
  42. data/app/views/components/lolita/{tabs → configuration/tabs}/_display.html.erb +4 -3
  43. data/app/views/{lolita/layouts → layouts/lolita}/application.html.erb +0 -0
  44. data/app/views/{lolita/layouts → layouts/lolita}/application.html.erb_spec.rb +0 -0
  45. data/author +1 -1
  46. data/lib/lolita.rb +31 -12
  47. data/lib/lolita/adapter/active_record.rb +16 -5
  48. data/lib/lolita/adapter/mongoid.rb +2 -2
  49. data/lib/lolita/base_configuration.rb +44 -2
  50. data/lib/lolita/builder.rb +31 -14
  51. data/lib/lolita/configuration/column.rb +92 -86
  52. data/lib/lolita/configuration/columns.rb +65 -65
  53. data/lib/lolita/configuration/factory.rb +8 -8
  54. data/lib/lolita/configuration/field.rb +156 -100
  55. data/lib/lolita/configuration/field/array.rb +74 -0
  56. data/lib/lolita/configuration/field/big_decimal.rb +12 -0
  57. data/lib/lolita/configuration/field/boolean.rb +7 -5
  58. data/lib/lolita/configuration/field/date.rb +13 -0
  59. data/lib/lolita/configuration/field/integer.rb +7 -5
  60. data/lib/lolita/configuration/field/string.rb +8 -6
  61. data/lib/lolita/configuration/field/time.rb +13 -0
  62. data/lib/lolita/configuration/fields.rb +36 -0
  63. data/lib/lolita/configuration/filter.rb +63 -0
  64. data/lib/lolita/configuration/list.rb +101 -91
  65. data/lib/lolita/configuration/page.rb +1 -0
  66. data/lib/lolita/configuration/tab.rb +137 -131
  67. data/lib/lolita/configuration/tab/content.rb +14 -12
  68. data/lib/lolita/configuration/tab/default.rb +15 -13
  69. data/lib/lolita/configuration/tabs.rb +2 -2
  70. data/lib/lolita/controllers/component_helpers.rb +26 -14
  71. data/lib/lolita/controllers/internal_helpers.rb +14 -0
  72. data/lib/lolita/controllers/url_helpers.rb +47 -10
  73. data/lib/lolita/dbi/base.rb +50 -50
  74. data/lib/lolita/errors.rb +2 -2
  75. data/lib/lolita/hooks.rb +298 -0
  76. data/lib/lolita/hooks/named_hook.rb +122 -0
  77. data/lib/lolita/lazy_loader.rb +46 -46
  78. data/lib/lolita/mapping.rb +3 -2
  79. data/lib/lolita/navigation.rb +48 -0
  80. data/lib/lolita/observed_array.rb +7 -0
  81. data/lib/lolita/rails/routes.rb +29 -3
  82. data/lolita.gemspec +65 -48
  83. data/public/javascripts/lolita/tab.js +5 -0
  84. data/public/javascripts/rails.js +137 -137
  85. data/public/stylesheets/lolita/style.css +3 -1
  86. data/spec/builder_spec.rb +42 -0
  87. data/spec/configuration/field_spec.rb +29 -18
  88. data/spec/configuration/filter_spec.rb +60 -0
  89. data/spec/configuration/tab_spec.rb +28 -20
  90. data/spec/configuration/tabs_spec.rb +8 -4
  91. data/spec/controllers/lolita_rest_spec.rb +15 -0
  92. data/spec/hooks_spec.rb +191 -0
  93. data/spec/lolita_spec.rb +6 -4
  94. data/spec/navigation/tree_spec.rb +59 -0
  95. data/spec/rails_app/app/mongoid/post.rb +2 -0
  96. data/spec/rails_app/app/views/components/lolita/{list → configuration/list}/_body_cell.html.erb +0 -0
  97. data/spec/rails_app/config/application.rb +1 -0
  98. data/spec/rails_app/lib/lolita/configuration/field/my_custom_collection.rb +14 -0
  99. data/spec/simple_spec_helper.rb +1 -0
  100. data/spec/spec_helper.rb +1 -2
  101. metadata +66 -49
  102. data/README.md +0 -5
  103. data/app/helpers/components/lolita/list_component.rb +0 -9
  104. data/app/views/components/lolita/field/_collection.html.erb +0 -5
  105. data/app/views/components/lolita/field/_date.html.erb +0 -1
  106. data/app/views/components/lolita/field/_datetime.html.erb +0 -1
  107. data/app/views/components/lolita/field/_display.html.erb +0 -6
  108. data/app/views/components/lolita/field/_integer.html.erb +0 -1
  109. data/app/views/components/lolita/field/_label.html.erb +0 -1
  110. data/app/views/components/lolita/field/_select.html.erb +0 -1
  111. data/app/views/components/lolita/field/_text.html.erb +0 -27
  112. data/app/views/components/lolita/list/_body.html.erb +0 -5
  113. data/app/views/components/lolita/list/_display.html.erb +0 -11
  114. data/app/views/components/lolita/list/_header.html.erb +0 -9
  115. data/app/views/components/lolita/list/_paginator.html.erb +0 -4
  116. data/app/views/components/lolita/list/_row.html.erb +0 -7
  117. data/app/views/components/lolita/tab/_content.html.erb +0 -1
  118. data/app/views/components/lolita/tab/_default.html.erb +0 -11
  119. data/app/views/components/lolita/tab/_display.html.erb +0 -7
  120. data/app/views/components/lolita/tab/_fields.html.erb +0 -7
  121. data/lib/lolita/configuration/field/collection.rb +0 -71
  122. data/lib/lolita/configuration/field/datetime.rb +0 -10
  123. data/lib/lolita/configuration/field/disabled.rb +0 -10
  124. data/lib/lolita/configuration/field/password.rb +0 -10
  125. data/lib/lolita/configuration/field/text.rb +0 -10
  126. data/lib/lolita/hooks/base.rb +0 -58
  127. data/lib/lolita/hooks/component.rb +0 -15
  128. data/lib/lolita/hooks/hooks.rb +0 -15
@@ -64,8 +64,8 @@ module Lolita
64
64
  def paginate(opt={})
65
65
  #FIXME depend on will_paginate
66
66
  if order=opt.delete(:sort)
67
- order.map{|c| c.join(" ")}.join(", ")
68
- opt[:order_by]=order
67
+ order=order.map{|c| c.join(" ")}.join(", ")
68
+ opt[:order]=order
69
69
  end
70
70
  self.klass.paginate(opt)
71
71
  end
@@ -99,13 +99,24 @@ module Lolita
99
99
  def field_to_hash(column)
100
100
  {
101
101
  :name=>column.name,
102
- :type=>column.type.to_s,
102
+ :type=>type_cast(column.type.to_s),
103
103
  :title=>column.name.to_s.humanize,
104
104
  :options=>{
105
- :primary=>column.primary
105
+ :primary=>column.primary,
106
+ :native_type=>column.type.to_s
106
107
  }
107
108
  }
108
109
  end
110
+
111
+ # Converts SQL types to normal ruby types
112
+ def type_cast name
113
+ types = {
114
+ 'decimal' => 'big_decimal',
115
+ 'datetime' => 'time',
116
+ 'text' => 'string'
117
+ }
118
+ types[name.to_s] || name
119
+ end
109
120
  end
110
121
  end
111
- end
122
+ end
@@ -47,8 +47,8 @@ module Lolita
47
47
 
48
48
  def fields
49
49
  @fields||=self.klass.fields.collect{|name,field|
50
- field_to_hash(name,field)
51
- }
50
+ name[0] == '_' ? nil : field_to_hash(name,field)
51
+ }.compact
52
52
  @fields
53
53
  end
54
54
 
@@ -5,6 +5,7 @@ module Lolita
5
5
 
6
6
  attr_reader :scope, :modules, :routes, :controllers,:resources
7
7
  attr_accessor :mappings,:default_route,:user_classes,:authentication
8
+ attr_writer :default_locale
8
9
 
9
10
  def initialize(scope)
10
11
  @scope=scope
@@ -17,15 +18,56 @@ module Lolita
17
18
  @controllers={}
18
19
  end
19
20
 
21
+ def navigation
22
+ @navigation||=Lolita::Navigation::Base.new()
23
+ @navigation
24
+ end
25
+
26
+ def locales=(value)
27
+ unless value.is_a?(Array)
28
+ @locales=[value]
29
+ else
30
+ @locales=value
31
+ end
32
+ end
33
+
34
+ def locales
35
+ @locales || []
36
+ end
37
+
38
+ def locale()
39
+ @locale || default_locale
40
+ end
41
+
42
+ def locale=given_locale
43
+ @locale=if locales.include?(given_locale.to_s.to_sym)
44
+ given_locale.to_s.to_sym
45
+ else
46
+ Lolita.default_locale
47
+ end
48
+ end
49
+ # Return default locale. First looks for defined default locale for Lolita, when not found than
50
+ # take first of defined #locales for Lolita, if there no defined locales for Lolita, than
51
+ # look for I18n and take default locale from there or if there is no I18n than take :en
52
+ def default_locale
53
+ @default_locale || self.locales.first || (defined?(I18n) ? I18n.default_locale : :en)
54
+ end
20
55
  # Call (with #call) to route klass
21
56
  # And return all names of routes that are needed for resource.
57
+ # When with #add_module routes are defined like
58
+ # Lolita.add_module MyModule, :route=>:my_module
59
+ # then this will be passed to the method that creates routes, but
60
+ # when Proc is passed to <i>:route</i> then this Proc should return
61
+ # name of route or nil.
62
+ # These names then are used for methods like <em>lolita_[route_name]_route</em>
63
+ # that should be required somewhere in you module.
22
64
  def conditional_routes(klass=nil)
23
65
  @routes.map{|name,route|
24
66
  if route.first
25
67
  if route.last.respond_to?(:call)
26
68
  route.last.call(klass)
27
69
  else
28
- nil
70
+ route.last
29
71
  end
30
72
  end
31
73
  }.compact
@@ -36,7 +78,7 @@ module Lolita
36
78
  def common_routes(klasses)
37
79
  @routes.map{|name,route|
38
80
  unless route.first
39
- klasses.map{|klass| route.last.is_a?(Proc) ? route.last.call(klass) : nil}
81
+ klasses.map{|klass| route.last.respond_to?(:call) ? route.last.call(klass) : route.last}
40
82
  end
41
83
  }.flatten.compact.uniq
42
84
  end
@@ -8,18 +8,21 @@ module Lolita
8
8
  # String or Symbol for buider.
9
9
  #
10
10
  module Builder
11
+ lolita_accessor :builder
11
12
 
12
13
  # Build response. Render component for current class with given options.
13
- def build(options=nil)
14
+ def build(*args)
15
+ args||=[]
16
+ options=args.extract_options!
14
17
  builder_options=self.builder_options || {}
15
18
  options=(options || {}).merge(builder_options)
16
- builder_values=self.builder
17
- return builder_values[:name],builder_values[:state],options
19
+ builder_values=self.get_builder(*args)
20
+ return builder_values[:name].to_sym,builder_values[:state].to_sym,options
18
21
  end
19
22
 
20
23
  # Default options for class. This method should be overwritten.
21
24
  def builder_options
22
- {builder_name.to_sym=>self}
25
+ {builder_local_variable_name=>self}
23
26
  end
24
27
 
25
28
  # Set or get builder for class.
@@ -29,9 +32,11 @@ module Lolita
29
32
  # * <tt>String or Symbol (one arg)</tt> - is used as _name_.
30
33
  # Default _name_ is Lolita::Configuration class name (example <code>:list</code>) and
31
34
  # default state is <code>:display</code>
32
- def builder(*value)
35
+ def get_builder(*value)
33
36
  if value && !value.empty?
34
- set_builder(*value)
37
+ set_builder(value)
38
+ elsif @builder
39
+ set_builder(@builder)
35
40
  else
36
41
  unless @builder
37
42
  @builder=default_builder
@@ -42,28 +47,40 @@ module Lolita
42
47
 
43
48
  # Return default builder information.
44
49
  def default_builder
45
- {:name=>"lolita/#{builder_name}",:state=>default_build_state}
50
+ {:name=>"/#{builder_name}".to_sym,:state=>default_build_state}
46
51
  end
47
52
 
48
53
  private
49
54
 
50
- def set_builder *value
51
- if value[0].is_a?(Hash)
52
- @builder=value[0]
53
- elsif value.size>1
54
- @builder={:name=>value[0],:state=>value[1]}
55
+ def set_builder value
56
+ if value.is_a?(Hash)
57
+ @builder=value
58
+ elsif value.is_a?(Array)
59
+ @builder={:name=>fix_name(value[0]),:state=>value[1] || default_build_state}
55
60
  else
56
- @builder={:name=>value[0],:state=>default_build_state}
61
+ @builder={:name=>fix_name(value),:state=>default_build_state}
57
62
  end
58
63
  end
59
64
 
65
+ def fix_name value
66
+ name=if value.to_s[0] == '/'
67
+ value
68
+ else
69
+ "/#{builder_name}/#{value}"
70
+ end
71
+ name.gsub(/\/$/,"")
72
+ end
73
+
60
74
  def default_build_state
61
75
  :display
62
76
  end
63
77
 
64
78
  def builder_name
65
- self.class.to_s.split("::").last.downcase.to_sym
79
+ self.class.to_s.split("::").map(&:underscore).join("/").to_sym
66
80
  end
67
81
 
82
+ def builder_local_variable_name
83
+ self.class.to_s.split("::").last.underscore.to_sym
84
+ end
68
85
  end
69
86
  end
@@ -1,86 +1,92 @@
1
- module Lolita
2
- module Configuration
3
- class Column
4
-
5
- MAX_TEXT_SIZE=20
6
- DEFAULT_DATE_FORMAT="%Y-%m-%d"
7
- DEFAULT_TIME_FORMAT="%H:%M:%S"
8
- lolita_accessor :name,:title,:type,:options,:format
9
-
10
- def initialize(*args,&block)
11
- self.set_attributes(*args)
12
- self.instance_eval(&block) if block_given?
13
- validate
14
- set_default_values
15
- end
16
-
17
- #
18
- # column do
19
- # name "UID"
20
- # format do(values)
21
- # values.first+values.last
22
- # end
23
- # end
24
- # <%= column.with_format([@post.id,@post.user_id])%>
25
- def with_format(value) #TODO test
26
- if @format
27
- @format.call(value)
28
- else
29
- format_from_type(value)
30
- end
31
- end
32
-
33
- def format_from_type(value) #TODO test
34
- if value
35
- case self.type.to_s.downcase
36
- when "string"
37
- value
38
- when "integer"
39
- value
40
- when "text"
41
- new_value=value.to_s.gsub(/<\/?[^>]*>/, "").strip
42
- if new_value.size>MAX_TEXT_SIZE
43
- "#{new_value.slice(0..MAX_TEXT_SIZE)}..."
44
- else
45
- new_value
46
- end
47
- when "datetime"
48
- value.strftime("#{DEFAULT_DATE_FORMAT} #{DEFAULT_TIME_FORMAT}")
49
- when "date"
50
- value.strftime(DEFAULT_DATE_FORMAT)
51
- when "time"
52
- value.strftime(DEFAULT_TIME_FORMAT)
53
- else
54
- value.to_s
55
- end
56
- else
57
- ""
58
- end
59
- end
60
-
61
- def set_attributes(*args)
62
- if !args.empty?
63
- if args[0].is_a?(Hash)
64
- args[0].each{|m,value|
65
- self.send("#{m}=".to_sym,value)
66
- }
67
- elsif args[0].is_a?(Symbol) || args[0].is_a?(String)
68
- self.name=args[0].to_s
69
- else
70
- raise ArgumentError.new("Lolita::Configuration::Column arguments must be Hash or Symbol or String instead of #{args[0].class}")
71
- end
72
- end
73
- end
74
-
75
- private
76
-
77
- def set_default_values
78
- @title||=@name.to_s.humanize
79
- end
80
-
81
- def validate
82
- raise ArgumentError.new("Column must have name.") unless self.name
83
- end
84
- end
85
- end
86
- end
1
+ module Lolita
2
+ module Configuration
3
+ class Column
4
+
5
+ MAX_TEXT_SIZE=20
6
+ lolita_accessor :name,:title,:type,:options,:format
7
+
8
+ def initialize(*args,&block)
9
+ self.set_attributes(*args)
10
+ self.instance_eval(&block) if block_given?
11
+ validate
12
+ set_default_values
13
+ end
14
+
15
+ #
16
+ # column do
17
+ # name "UID"
18
+ # format do(values)
19
+ # values.first+values.last
20
+ # end
21
+ # end
22
+ # <%= column.with_format([@post.id,@post.user_id])%>
23
+ def with_format(value) #TODO test
24
+ if @format.respond_to?(:call)
25
+ @format.call(value)
26
+ elsif @format && (value.is_a?(Time) || value.is_a?(Date))
27
+ format_for_datetime(value)
28
+ else
29
+ format_from_type(value)
30
+ end
31
+ end
32
+
33
+ def format_from_type(value) #TODO test
34
+ if value
35
+ if value.is_a?(String)
36
+ value
37
+ elsif value.is_a?(Integer)
38
+ value
39
+ elsif value.is_a?(Date)
40
+ if defined?(I18n)
41
+ I18n.localize(value, :format => :long)
42
+ else
43
+ value.to_s
44
+ end
45
+ elsif value.is_a?(Time)
46
+ if defined?(I18n)
47
+ I18n.localize(value, :format => :long)
48
+ else
49
+ value.to_s
50
+ end
51
+ else
52
+ value.to_s
53
+ end
54
+ else
55
+ ""
56
+ end
57
+ end
58
+
59
+ def set_attributes(*args)
60
+ if !args.empty?
61
+ if args[0].is_a?(Hash)
62
+ args[0].each{|m,value|
63
+ self.send("#{m}=".to_sym,value)
64
+ }
65
+ elsif args[0].is_a?(Symbol) || args[0].is_a?(String)
66
+ self.name=args[0].to_s
67
+ else
68
+ raise ArgumentError.new("Lolita::Configuration::Column arguments must be Hash or Symbol or String instead of #{args[0].class}")
69
+ end
70
+ end
71
+ end
72
+
73
+ private
74
+
75
+ def set_default_values
76
+ @title||=@name.to_s.humanize
77
+ end
78
+
79
+ def format_for_datetime value
80
+ if defined?(I18n)
81
+ I18n.localize(value, :format => @format)
82
+ else
83
+ value.to_s
84
+ end
85
+ end
86
+
87
+ def validate
88
+ raise ArgumentError.new("Column must have name.") unless self.name
89
+ end
90
+ end
91
+ end
92
+ end
@@ -1,65 +1,65 @@
1
- module Lolita
2
- module Configuration
3
- class Columns
4
-
5
- include Enumerable
6
- include ObservedArray
7
-
8
- attr_accessor :list
9
- attr_reader :dbi
10
-
11
- def initialize(list,dbi=nil)
12
- @list=list
13
- @dbi=dbi || list.dbi
14
- @columns=[]
15
- end
16
-
17
- def each
18
- @columns.each_with_index{|column,index|
19
- if column.is_a?(Lolita::Configuration::Column)
20
- yield column
21
- else
22
- raise "Any column must be Lolita::Configuratin::Column object instead of #{column.class}."
23
- end
24
- }
25
- end
26
-
27
- def generate!
28
- @columns.clear
29
- @dbi.fields.each_with_index{|field,index|
30
- @columns[index]=Lolita::Configuration::Column.new(field)
31
- }
32
- end
33
-
34
- def add attributes={},&block
35
- if block_given?
36
- @columns<<build_element(&block)
37
- else
38
- @columns<<build_element(attributes)
39
- end
40
- self
41
- end
42
-
43
- private
44
-
45
- def collection_variable
46
- @columns
47
- end
48
-
49
- def build_element(column=nil,&block)
50
- if column.is_a?(Lolita::Configuration::Column)
51
- column
52
- elsif column.is_a?(Proc)
53
- Lolita::Configuration::Column.new(&column)
54
- elsif block_given?
55
- Lolita::Configuration::Column.new(&block)
56
- elsif [Symbol,String,Hash].include?(column.class)
57
- Lolita::Configuration::Column.new(column)
58
- else
59
- raise ArgumentError.new("Column can not be defined with #{column.class}.")
60
- end
61
- end
62
-
63
- end
64
- end
65
- end
1
+ module Lolita
2
+ module Configuration
3
+ class Columns
4
+
5
+ include Enumerable
6
+ include ObservedArray
7
+
8
+ attr_accessor :list
9
+ attr_reader :dbi
10
+
11
+ def initialize(list,dbi=nil)
12
+ @list=list
13
+ @dbi=dbi || list.dbi
14
+ @columns=[]
15
+ end
16
+
17
+ def each
18
+ @columns.each_with_index{|column,index|
19
+ if column.is_a?(Lolita::Configuration::Column)
20
+ yield column
21
+ else
22
+ raise "Any column must be Lolita::Configuratin::Column object instead of #{column.class}."
23
+ end
24
+ }
25
+ end
26
+
27
+ def generate!
28
+ @columns.clear
29
+ @dbi.fields.each_with_index{|field,index|
30
+ @columns[index]=Lolita::Configuration::Column.new(field)
31
+ }
32
+ end
33
+
34
+ def add attributes={},&block
35
+ if block_given?
36
+ @columns<<build_element(&block)
37
+ else
38
+ @columns<<build_element(attributes)
39
+ end
40
+ self
41
+ end
42
+
43
+ private
44
+
45
+ def collection_variable
46
+ @columns
47
+ end
48
+
49
+ def build_element(column=nil,&block)
50
+ if column.is_a?(Lolita::Configuration::Column)
51
+ column
52
+ elsif column.is_a?(Proc)
53
+ Lolita::Configuration::Column.new(&column)
54
+ elsif block_given?
55
+ Lolita::Configuration::Column.new(&block)
56
+ elsif [Symbol,String,Hash].include?(column.class)
57
+ Lolita::Configuration::Column.new(column)
58
+ else
59
+ raise ArgumentError.new("Column can not be defined with #{column.class}.")
60
+ end
61
+ end
62
+
63
+ end
64
+ end
65
+ end