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
@@ -1,11 +1,13 @@
1
1
  module Lolita
2
2
  module Configuration
3
- class StringField < Lolita::Configuration::Field
4
-
5
- def initialize *args, &block
6
- @type="string"
7
- super
3
+ module Field
4
+ class String < Lolita::Configuration::Field::Base
5
+ lolita_accessor :simple, :rows
6
+ def initialize *args, &block
7
+ @type="string"
8
+ super
9
+ end
8
10
  end
9
11
  end
10
12
  end
11
- end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Lolita
2
+ module Configuration
3
+ module Field
4
+ class Time < Lolita::Configuration::Field::Base
5
+ attr_accessor :format
6
+ def initialize *args
7
+ @type="time"
8
+ super
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,36 @@
1
+ module Lolita
2
+ module Configuration
3
+ # Lolita::Configuration::Tabs is container class that holds all
4
+ # tabs for each lolita instance.
5
+ # Also it has some useful methods.
6
+
7
+ class Fields
8
+ include Enumerable
9
+ include Lolita::ObservedArray
10
+
11
+ def initialize *args,&block
12
+ @fields=[]
13
+ self.instance_eval(&block) if block_given?
14
+ end
15
+
16
+ def clear
17
+ @fields=[]
18
+ end
19
+
20
+ def by_name(name)
21
+ @fields.detect{|field| (field.name==name.to_sym || field.name=="#{name}_id".to_sym) }
22
+ end
23
+
24
+ private
25
+
26
+ def collection_variable
27
+ @fields
28
+ end
29
+
30
+ def build_element(element,&block)
31
+ element
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,63 @@
1
+ module Lolita
2
+ module Configuration
3
+ class Filter
4
+ include Lolita::Builder
5
+ attr_reader :dbi
6
+
7
+ def initialize(dbi,*args,&block)
8
+ @dbi = dbi
9
+ @fields=Lolita::Configuration::Fields.new
10
+ set_attributes(*args)
11
+ self.instance_eval(&block) if block_given?
12
+ end
13
+
14
+ def field *args, &block
15
+ field=Lolita::Configuration::Field.add(self.dbi,*args,&block)
16
+ @fields<<field
17
+ field
18
+ end
19
+
20
+ # Set all fields in tab. Accept <code>fields</code> as Array.
21
+ # Each array element can be Lolita::Configuration::Field object or
22
+ # Hash, that will be passed to #field method.
23
+ def fields=(fields)
24
+ if fields.is_a?(Array)
25
+ fields.each{|field_attr|
26
+ if field_attr.is_a?(Lolita::Configuration::Field)
27
+ @fields<<field_attr
28
+ else
29
+ self.field(field_attr)
30
+ end
31
+ }
32
+ end
33
+ end
34
+
35
+ def fields(*args, &block)
36
+ unless args.empty?
37
+ args.each do |field_name|
38
+ f = field(field_name)
39
+ f.instance_eval(&block) if block_given?
40
+ end
41
+ end
42
+ if @fields.empty?
43
+ field :search
44
+ end
45
+ @fields
46
+ end
47
+
48
+ # Used to set attributes if block not given.
49
+ def set_attributes(*args)
50
+ if args && args[0]
51
+ if args[0].is_a?(Hash)
52
+ args[0].each{|m,value|
53
+ self.send("#{m}=".to_sym,value)
54
+ }
55
+ else
56
+ fields *args
57
+ end
58
+ end
59
+ end
60
+
61
+ end
62
+ end
63
+ end
@@ -1,92 +1,102 @@
1
- module Lolita
2
- module Configuration
3
- class List
4
- include Lolita::Builder
5
-
6
- attr_reader :dbi,:initialized_attributes
7
-
8
- def initialize(*args,&block)
9
- if args && args[0].is_a?(Lolita::DBI::Base)
10
- @dbi=args.shift
11
- end
12
- @columns=Lolita::Configuration::Columns.new(self)
13
- @set_attributes=[]
14
- set_attributes(*args)
15
- self.instance_eval(&block) if block_given?
16
- self.generate!()
17
- end
18
-
19
- # Look for methods in Page class. Load @page on demand and call method on it.
20
- def method_missing(method_name,*args,&block)
21
- if Lolita::Configuration::Page.public_instance_methods.include?(method_name.to_sym)
22
- @page||=Lolita::Configuration::Page.new(@dbi)
23
- @page.send(method_name.to_sym,*args,&block)
24
- else
25
- super
26
- end
27
- end
28
- # Set columns. Allowed classes are Lolita::Configuration::Columns or
29
- # Array.
30
- def columns=(value)
31
- set_attribute(:columns)
32
- if value.is_a?(Lolita::Configuration::Columns)
33
- @columns=value
34
- elsif value.is_a?(Array)
35
- value.each{|el| @columns<<el}
36
- else
37
- raise ArgumentError.new("Columns must bet Array or Lolita::Configuration::Columns.")
38
- end
39
- end
40
-
41
- # Get list columns (also block setter)
42
- def columns(*args)
43
- if args && !args.empty?
44
- self.columns=args
45
- end
46
- self.generate!
47
- @columns
48
- end
49
-
50
- # Generate uninitialized attributes
51
- def generate!()
52
- @columns.generate! unless is_set?(:columns)
53
- end
54
-
55
- private
56
-
57
- # Used to set attributes if block not given.
58
- def set_attributes(*args)
59
- if args && args[0]
60
- if args[0].is_a?(Hash)
61
- args[0].each{|m,value|
62
- self.send("#{m}=".to_sym,value)
63
- }
64
- else
65
- raise ArgumentError.new("Lolita::Configuration::List arguments must be Hash instead of #{args[0].class}")
66
- end
67
- end
68
- end
69
-
70
- # Mark attribute as set.
71
- def set_attribute(var)
72
- @set_attributes<<var unless is_set?(var)
73
- end
74
-
75
- # Determine if attribute is set and don't need to generate it.
76
- def is_set?(var)
77
- @set_attributes.include?(var)
78
- end
79
-
80
- # Block setter for columns
81
- def column(*args,&block)
82
- set_attribute(:columns)
83
- if block_given?
84
- @columns<<block
85
- else
86
- @columns<<args[0]
87
- end
88
- end
89
-
90
- end
91
- end
1
+ module Lolita
2
+ module Configuration
3
+ class List
4
+ include Lolita::Builder
5
+
6
+ attr_reader :dbi,:initialized_attributes
7
+
8
+ def initialize(*args,&block)
9
+ if args && args[0].is_a?(Lolita::DBI::Base)
10
+ @dbi=args.shift
11
+ end
12
+ @columns=Lolita::Configuration::Columns.new(self)
13
+ @set_attributes=[]
14
+ set_attributes(*args)
15
+ self.instance_eval(&block) if block_given?
16
+ self.generate!()
17
+ end
18
+
19
+ # Look for methods in Page class. Load @page on demand and call method on it.
20
+ def method_missing(method_name,*args,&block)
21
+ if Lolita::Configuration::Page.public_instance_methods.include?(method_name.to_sym)
22
+ @page||=Lolita::Configuration::Page.new(@dbi)
23
+ @page.send(method_name.to_sym,*args,&block)
24
+ else
25
+ super
26
+ end
27
+ end
28
+ # Set columns. Allowed classes are Lolita::Configuration::Columns or
29
+ # Array.
30
+ def columns=(value)
31
+ set_attribute(:columns)
32
+ if value.is_a?(Lolita::Configuration::Columns)
33
+ @columns=value
34
+ elsif value.is_a?(Array)
35
+ value.each{|el| @columns<<el}
36
+ else
37
+ raise ArgumentError.new("Columns must bet Array or Lolita::Configuration::Columns.")
38
+ end
39
+ end
40
+
41
+ # Get list columns (also block setter)
42
+ def columns(*args)
43
+ if args && !args.empty?
44
+ self.columns=args
45
+ end
46
+ self.generate!
47
+ @columns
48
+ end
49
+
50
+ # Generate uninitialized attributes
51
+ def generate!()
52
+ @columns.generate! unless is_set?(:columns)
53
+ end
54
+
55
+ # checks if filter defined
56
+ def filter?
57
+ @filter.is_a?(Lolita::Configuration::Filter)
58
+ end
59
+
60
+ # Adds filter
61
+ def filter(*args,&block)
62
+ @filter ||= Lolita::Configuration::Filter.new(self.dbi,*args,&block)
63
+ end
64
+
65
+ private
66
+
67
+ # Used to set attributes if block not given.
68
+ def set_attributes(*args)
69
+ if args && args[0]
70
+ if args[0].is_a?(Hash)
71
+ args[0].each{|m,value|
72
+ self.send("#{m}=".to_sym,value)
73
+ }
74
+ else
75
+ raise ArgumentError.new("Lolita::Configuration::List arguments must be Hash instead of #{args[0].class}")
76
+ end
77
+ end
78
+ end
79
+
80
+ # Mark attribute as set.
81
+ def set_attribute(var)
82
+ @set_attributes<<var unless is_set?(var)
83
+ end
84
+
85
+ # Determine if attribute is set and don't need to generate it.
86
+ def is_set?(var)
87
+ @set_attributes.include?(var)
88
+ end
89
+
90
+ # Block setter for columns
91
+ def column(*args,&block)
92
+ set_attribute(:columns)
93
+ if block_given?
94
+ @columns<<block
95
+ else
96
+ @columns<<args[0]
97
+ end
98
+ end
99
+
100
+ end
101
+ end
92
102
  end
@@ -71,6 +71,7 @@ module Lolita
71
71
  def get_page()
72
72
  @page=@dbi.paginate((@page_options||{}).merge(@last_options))
73
73
  end
74
+
74
75
  # Return last paginated page
75
76
  # ====Example
76
77
  # list.paginate(2)
@@ -17,156 +17,162 @@ module Lolita
17
17
  # lolita do
18
18
  # tab(:files)
19
19
  # end
20
- class Tab
21
- extend Lolita::Configuration::Factory
20
+ module Tab
21
+ class Base
22
+ include Lolita::Builder
22
23
 
23
- # For different types there are different builders(cells)
24
- @@default_tab_type=:default
25
- @@available_types=[:content]
26
-
27
- lolita_accessor :title,:name,:type
28
- attr_accessor :dbi,:current_fieldset,:current_dbi
29
- attr_reader :field_sets,:nested_form
24
+ # For different types there are different builders(cells)
25
+ @@default_tab_type=:default
26
+ @@available_types=[:content]
27
+
28
+ lolita_accessor :title,:name,:type
29
+ attr_accessor :dbi,:current_fieldset,:current_dbi
30
+ attr_reader :field_sets,:nested_form
30
31
 
31
- # To create new tab the following parametrs need to be provided.
32
- # * <tt>dbi</tt> Lolita::DBI::Base object, that represents database.
33
- # * <tt>*args</tt> See #set_attributes, for how these args are processed.
34
- # * <tt>&block</tt> Block can be passed, anything in block will be evaled for current instance.
35
- def initialize dbi,*args,&block
36
- @fields=[]
37
- @field_sets=[]
38
- self.dbi=dbi
39
- self.current_dbi=dbi
40
- self.set_attributes(*args)
41
- self.instance_eval(&block) if block_given?
42
- validate
43
- end
32
+ # To create new tab the following parametrs need to be provided.
33
+ # * <tt>dbi</tt> Lolita::DBI::Base object, that represents database.
34
+ # * <tt>*args</tt> See #set_attributes, for how these args are processed.
35
+ # * <tt>&block</tt> Block can be passed, anything in block will be evaled for current instance.
36
+ def initialize dbi,*args,&block
37
+ @fields=Lolita::Configuration::Fields.new
38
+ @field_sets=[]
39
+ self.dbi=dbi
40
+ self.current_dbi=dbi
41
+ self.set_attributes(*args)
42
+ self.instance_eval(&block) if block_given?
43
+ validate
44
+ end
44
45
 
45
-
46
- # Field setter method, accpet <i>*args</i> and <i>&block</i> to be passed.
47
- # For details how to pass args and block see Lolita::Configuration::Field.
48
- # Return field itself.
49
- def field *args, &block
50
- field=Lolita::Configuration::Field.add(self.current_dbi,*args,&block)
51
- field.field_set=current_fieldset
52
- if self.current_dbi!=self.dbi
53
- field.nested_in=self.dbi
46
+
47
+ # Field setter method, accpet <i>*args</i> and <i>&block</i> to be passed.
48
+ # For details how to pass args and block see Lolita::Configuration::Field.
49
+ # Return field itself.
50
+ def field *args, &block
51
+ field=Lolita::Configuration::Field.add(self.current_dbi,*args,&block)
52
+ field.field_set=current_fieldset
53
+ if self.current_dbi!=self.dbi
54
+ field.nested_in=self.dbi
55
+ end
56
+ @fields<<field
57
+ field
54
58
  end
55
- @fields<<field
56
- field
57
- end
58
59
 
59
- # Return all fields in tab.
60
- def fields
61
- @fields
62
- end
60
+ # Return all fields in tab.
61
+ def fields
62
+ @fields
63
+ end
63
64
 
64
- # Set all fields in tab. Accept <code>fields</code> as Array.
65
- # Each array element can be Lolita::Configuration::Field object or
66
- # Hash, that will be passed to #field method.
67
- def fields=(fields)
68
- @fields=[]
69
- if fields.is_a?(Array)
70
- fields.each{|field_attr|
71
- if field_attr.is_a?(Lolita::Configuration::Field)
72
- @fields<<field_attr
73
- else
74
- self.field(field_attr)
75
- end
76
- }
65
+ # Set all fields in tab. Accept <code>fields</code> as Array.
66
+ # Each array element can be Lolita::Configuration::Field object or
67
+ # Hash, that will be passed to #field method.
68
+ def fields=(fields)
69
+ @fields=Lolita::Configuration::Fields.new
70
+ if fields.is_a?(Array)
71
+ fields.each{|field_attr|
72
+ if field_attr.is_a?(Lolita::Configuration::Field)
73
+ @fields<<field_attr
74
+ else
75
+ self.field(field_attr)
76
+ end
77
+ }
78
+ end
77
79
  end
78
- end
79
80
 
80
- # Create fields for tab from database.
81
- # See Lolita::Adapter classes for use of DB field method.
82
- def default_fields
83
- self.current_dbi.fields.each{|db_field|
84
- self.field(db_field)
85
- }
86
- end
81
+ # Create fields for tab from database.
82
+ # See Lolita::Adapter classes for use of DB field method.
83
+ def default_fields
84
+ self.current_dbi.fields.each{|db_field|
85
+ self.field(db_field)
86
+ }
87
+ end
87
88
 
88
- # Add tab nested fields for <em>class_or_name</em> and <em>&block</em>
89
- # that will be evaluted in current tab instance.
90
- def nested_fields_for class_or_name,&block
91
- current_class=get_class(class_or_name)
92
- self.current_dbi=Lolita::DBI::Base.new(current_class)
93
- self.instance_eval(&block)
94
- self.current_dbi=self.dbi
95
- end
89
+ # Add tab nested fields for <em>class_or_name</em> and <em>&block</em>
90
+ # that will be evaluted in current tab instance.
91
+ def nested_fields_for class_or_name,&block
92
+ current_class=get_class(class_or_name)
93
+ self.current_dbi=Lolita::DBI::Base.new(current_class)
94
+ self.instance_eval(&block)
95
+ self.current_dbi=self.dbi
96
+ end
96
97
 
97
- # Return nested field for given <em>class_or_name</em>
98
- def nested_fields_of class_or_name
99
- current_class=get_class(class_or_name)
100
- self.fields.select{|field|
101
- field.nested_in?(@dbi) && field.dbi.klass==current_class
102
- }
103
- end
98
+ # Return nested field for given <em>class_or_name</em>
99
+ def nested_fields_of class_or_name
100
+ current_class=get_class(class_or_name)
101
+ self.fields.select{|field|
102
+ field.nested_in?(@dbi) && field.dbi.klass==current_class
103
+ }
104
+ end
104
105
 
105
- # Create new field_set for current tab with given _name_ and <em>&block</em>
106
- # that will be evaluted in current tab instance.
107
- def field_set name,&block
108
- field_set=Lolita::Configuration::FieldSet.new(self,name)
109
- self.current_fieldset=field_set
110
- @field_sets<<field_set
111
- self.instance_eval(&block)
112
- self.current_fieldset=nil
113
- end
106
+ # Create new field_set for current tab with given _name_ and <em>&block</em>
107
+ # that will be evaluted in current tab instance.
108
+ def field_set name,&block
109
+ field_set=Lolita::Configuration::FieldSet.new(self,name)
110
+ self.current_fieldset=field_set
111
+ @field_sets<<field_set
112
+ self.instance_eval(&block)
113
+ self.current_fieldset=nil
114
+ end
114
115
 
115
- def fields_with_field_set
116
- used_fieldsets=[]
117
- self.fields.each{|field|
118
- if !field.field_set || (!used_fieldsets.include?(field.field_set))
119
- if field.field_set
120
- yield field.field_set.fields,field.field_set
121
- used_fieldsets<<field.field_set
122
- else
123
- yield field,nil
116
+ def fields_with_field_set
117
+ used_fieldsets=[]
118
+ self.fields.each{|field|
119
+ if !field.field_set || (!used_fieldsets.include?(field.field_set))
120
+ if field.field_set
121
+ yield field.field_set.fields,field.field_set
122
+ used_fieldsets<<field.field_set
123
+ else
124
+ yield field,nil
125
+ end
124
126
  end
127
+ }
128
+ end
129
+ # tab.field do
130
+ # tab.fields_with_fieldset do |field,fieldset|
131
+ # =field
132
+ # end
133
+
134
+
135
+ # Set attributes from given <em>*args</em>.
136
+ # First element of args is used as <i>type</i> other interpreted as options.
137
+ # Every Hash key is used as setter method, and value as method value.
138
+ # ====Example
139
+ # set_attributes(:content,:field=>{:name=>"My Field"})
140
+ # set_attributes(:field=>{:name=>"My Field"})
141
+ def set_attributes *args
142
+ if args
143
+ options=args.extract_options!
144
+ self.type=args.first if args.first.is_a?(Symbol)
145
+ options.each{|method,options|
146
+ self.send(:"#{method}=",options)
147
+ }
125
148
  end
126
- }
127
- end
128
- # tab.field do
129
- # tab.fields_with_fieldset do |field,fieldset|
130
- # =field
131
- # end
149
+
150
+ end
132
151
 
152
+ private
133
153
 
134
- # Set attributes from given <em>*args</em>.
135
- # First element of args is used as <i>type</i> other interpreted as options.
136
- # Every Hash key is used as setter method, and value as method value.
137
- # ====Example
138
- # set_attributes(:content,:field=>{:name=>"My Field"})
139
- # set_attributes(:field=>{:name=>"My Field"})
140
- def set_attributes *args
141
- if args
142
- options=args.extract_options!
143
- self.type=args.first if args.first.is_a?(Symbol)
144
- options.each{|method,options|
145
- self.send(:"#{method}=",options)
146
- }
154
+ def set_default_attributes
155
+ @type=@@default_tab_type unless @type
156
+ @name="tab_#{self.__id__}" unless @name
157
+ @title=@type.to_s.humanize unless @title
147
158
  end
148
159
 
149
- end
150
-
151
- private
160
+ def get_class(str_or_sym_or_class)
161
+ str_or_sym_or_class.is_a?(Class) ? str_or_sym_or_class : str_or_sym_or_class.to_s.camelize.constantize
162
+ end
163
+
164
+ def validate
165
+ set_default_attributes
166
+ end
152
167
 
153
- def set_default_attributes
154
- @type=@@default_tab_type unless @type
155
- @name="tab_#{self.__id__}" unless @name
156
- @title=@type.to_s.humanize unless @title
157
- end
158
-
159
- def get_class(str_or_sym_or_class)
160
- str_or_sym_or_class.is_a?(Class) ? str_or_sym_or_class : str_or_sym_or_class.to_s.camelize.constantize
161
- end
162
-
163
- def validate
164
- set_default_attributes
165
- end
166
-
167
- class << self
168
- def default_types
169
- @@available_types
168
+ def builder_local_variable_name
169
+ :tab
170
+ end
171
+
172
+ class << self
173
+ def default_types
174
+ @@available_types
175
+ end
170
176
  end
171
177
  end
172
178
  end