lolita 3.0.7 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/GUIDELINE +4 -0
- data/README.rdoc +50 -0
- data/VERSION +1 -1
- data/app/controllers/lolita/rest_controller.rb +27 -11
- data/app/helpers/components/lolita/configuration/list_component.rb +11 -0
- data/app/helpers/lolita_helper.rb +1 -1
- data/app/views/components/lolita/configuration/field/_display.html.erb +9 -0
- data/app/views/components/lolita/configuration/field/_label.html.erb +1 -0
- data/app/views/components/lolita/{field → configuration/field}/_object.html.erb +0 -0
- data/app/views/components/lolita/configuration/field/array/_display.html.erb +5 -0
- data/app/views/components/lolita/configuration/field/array/habtm/_display.html.erb +26 -0
- data/app/views/components/lolita/configuration/field/array/select/_display.html.erb +5 -0
- data/app/views/components/lolita/configuration/field/big_decimal/_display.html.erb +1 -0
- data/app/views/components/lolita/{field/_boolean.html.erb → configuration/field/boolean/_display.html.erb} +0 -0
- data/app/views/components/lolita/configuration/field/date/_display.html.erb +1 -0
- data/app/views/components/lolita/{field/_string.html.erb → configuration/field/float/_display.html.erb} +0 -0
- data/app/views/components/lolita/configuration/field/integer/_display.html.erb +1 -0
- data/app/views/components/lolita/configuration/field/string/_display.html.erb +5 -0
- data/app/views/components/lolita/{field/_disabled.html.erb → configuration/field/string/disabled/_display.html.erb} +0 -0
- data/app/views/components/lolita/{field/_password.html.erb → configuration/field/string/password/_display.html.erb} +0 -0
- data/app/views/components/lolita/configuration/field/string/text/_display.html.erb +34 -0
- data/app/views/components/lolita/configuration/field/time/_display.html.erb +1 -0
- data/app/views/components/lolita/{field_set → configuration/field_set}/_display.html.erb +1 -1
- data/app/views/components/lolita/configuration/list/_body.html.erb +5 -0
- data/app/views/components/lolita/{list → configuration/list}/_body_cell.html.erb +0 -0
- data/app/views/components/lolita/{list → configuration/list}/_checkbox_cell.html.erb +0 -0
- data/app/views/components/lolita/{list → configuration/list}/_checkbox_header.html.erb +0 -0
- data/app/views/components/lolita/configuration/list/_display.html.erb +12 -0
- data/app/views/components/lolita/configuration/list/_filter.html.erb +8 -0
- data/app/views/components/lolita/configuration/list/_header.html.erb +9 -0
- data/app/views/components/lolita/{list → configuration/list}/_header_cell.html.erb +0 -0
- data/app/views/components/lolita/{list → configuration/list}/_new_resource.html.erb +0 -0
- data/app/views/components/lolita/configuration/list/_paginator.html.erb +3 -0
- data/app/views/components/lolita/configuration/list/_row.html.erb +7 -0
- data/app/views/components/lolita/{list → configuration/list}/_title.html.erb +0 -0
- data/app/views/components/lolita/{list → configuration/list}/_tool_cell.html.erb +0 -0
- data/app/views/components/lolita/{list → configuration/list}/_tool_header.html.erb +0 -0
- data/app/views/components/lolita/configuration/tab/_display.html.erb +17 -0
- data/app/views/components/lolita/configuration/tab/_fields.html.erb +7 -0
- data/app/views/components/lolita/configuration/tab/content/_display.html.erb +1 -0
- data/app/views/components/lolita/configuration/tab/default/_display.html.erb +9 -0
- data/app/views/components/lolita/{tabs → configuration/tabs}/_display.html.erb +4 -3
- data/app/views/{lolita/layouts → layouts/lolita}/application.html.erb +0 -0
- data/app/views/{lolita/layouts → layouts/lolita}/application.html.erb_spec.rb +0 -0
- data/author +1 -1
- data/lib/lolita.rb +31 -12
- data/lib/lolita/adapter/active_record.rb +16 -5
- data/lib/lolita/adapter/mongoid.rb +2 -2
- data/lib/lolita/base_configuration.rb +44 -2
- data/lib/lolita/builder.rb +31 -14
- data/lib/lolita/configuration/column.rb +92 -86
- data/lib/lolita/configuration/columns.rb +65 -65
- data/lib/lolita/configuration/factory.rb +8 -8
- data/lib/lolita/configuration/field.rb +156 -100
- data/lib/lolita/configuration/field/array.rb +74 -0
- data/lib/lolita/configuration/field/big_decimal.rb +12 -0
- data/lib/lolita/configuration/field/boolean.rb +7 -5
- data/lib/lolita/configuration/field/date.rb +13 -0
- data/lib/lolita/configuration/field/integer.rb +7 -5
- data/lib/lolita/configuration/field/string.rb +8 -6
- data/lib/lolita/configuration/field/time.rb +13 -0
- data/lib/lolita/configuration/fields.rb +36 -0
- data/lib/lolita/configuration/filter.rb +63 -0
- data/lib/lolita/configuration/list.rb +101 -91
- data/lib/lolita/configuration/page.rb +1 -0
- data/lib/lolita/configuration/tab.rb +137 -131
- data/lib/lolita/configuration/tab/content.rb +14 -12
- data/lib/lolita/configuration/tab/default.rb +15 -13
- data/lib/lolita/configuration/tabs.rb +2 -2
- data/lib/lolita/controllers/component_helpers.rb +26 -14
- data/lib/lolita/controllers/internal_helpers.rb +14 -0
- data/lib/lolita/controllers/url_helpers.rb +47 -10
- data/lib/lolita/dbi/base.rb +50 -50
- data/lib/lolita/errors.rb +2 -2
- data/lib/lolita/hooks.rb +298 -0
- data/lib/lolita/hooks/named_hook.rb +122 -0
- data/lib/lolita/lazy_loader.rb +46 -46
- data/lib/lolita/mapping.rb +3 -2
- data/lib/lolita/navigation.rb +48 -0
- data/lib/lolita/observed_array.rb +7 -0
- data/lib/lolita/rails/routes.rb +29 -3
- data/lolita.gemspec +65 -48
- data/public/javascripts/lolita/tab.js +5 -0
- data/public/javascripts/rails.js +137 -137
- data/public/stylesheets/lolita/style.css +3 -1
- data/spec/builder_spec.rb +42 -0
- data/spec/configuration/field_spec.rb +29 -18
- data/spec/configuration/filter_spec.rb +60 -0
- data/spec/configuration/tab_spec.rb +28 -20
- data/spec/configuration/tabs_spec.rb +8 -4
- data/spec/controllers/lolita_rest_spec.rb +15 -0
- data/spec/hooks_spec.rb +191 -0
- data/spec/lolita_spec.rb +6 -4
- data/spec/navigation/tree_spec.rb +59 -0
- data/spec/rails_app/app/mongoid/post.rb +2 -0
- data/spec/rails_app/app/views/components/lolita/{list → configuration/list}/_body_cell.html.erb +0 -0
- data/spec/rails_app/config/application.rb +1 -0
- data/spec/rails_app/lib/lolita/configuration/field/my_custom_collection.rb +14 -0
- data/spec/simple_spec_helper.rb +1 -0
- data/spec/spec_helper.rb +1 -2
- metadata +66 -49
- data/README.md +0 -5
- data/app/helpers/components/lolita/list_component.rb +0 -9
- data/app/views/components/lolita/field/_collection.html.erb +0 -5
- data/app/views/components/lolita/field/_date.html.erb +0 -1
- data/app/views/components/lolita/field/_datetime.html.erb +0 -1
- data/app/views/components/lolita/field/_display.html.erb +0 -6
- data/app/views/components/lolita/field/_integer.html.erb +0 -1
- data/app/views/components/lolita/field/_label.html.erb +0 -1
- data/app/views/components/lolita/field/_select.html.erb +0 -1
- data/app/views/components/lolita/field/_text.html.erb +0 -27
- data/app/views/components/lolita/list/_body.html.erb +0 -5
- data/app/views/components/lolita/list/_display.html.erb +0 -11
- data/app/views/components/lolita/list/_header.html.erb +0 -9
- data/app/views/components/lolita/list/_paginator.html.erb +0 -4
- data/app/views/components/lolita/list/_row.html.erb +0 -7
- data/app/views/components/lolita/tab/_content.html.erb +0 -1
- data/app/views/components/lolita/tab/_default.html.erb +0 -11
- data/app/views/components/lolita/tab/_display.html.erb +0 -7
- data/app/views/components/lolita/tab/_fields.html.erb +0 -7
- data/lib/lolita/configuration/field/collection.rb +0 -71
- data/lib/lolita/configuration/field/datetime.rb +0 -10
- data/lib/lolita/configuration/field/disabled.rb +0 -10
- data/lib/lolita/configuration/field/password.rb +0 -10
- data/lib/lolita/configuration/field/text.rb +0 -10
- data/lib/lolita/hooks/base.rb +0 -58
- data/lib/lolita/hooks/component.rb +0 -15
- 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[:
|
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
|
@@ -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
|
-
|
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.
|
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
|
data/lib/lolita/builder.rb
CHANGED
@@ -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(
|
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.
|
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
|
-
{
|
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
|
35
|
+
def get_builder(*value)
|
33
36
|
if value && !value.empty?
|
34
|
-
set_builder(
|
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=>"
|
50
|
+
{:name=>"/#{builder_name}".to_sym,:state=>default_build_state}
|
46
51
|
end
|
47
52
|
|
48
53
|
private
|
49
54
|
|
50
|
-
def set_builder
|
51
|
-
if value
|
52
|
-
@builder=value
|
53
|
-
elsif value.
|
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
|
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("::").
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
else
|
29
|
-
format_from_type(value)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def format_from_type(value) #TODO test
|
34
|
-
if value
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
value.
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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
|