lolita 3.0.5 → 3.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/.rspec +2 -0
  2. data/GUIDELINE +20 -20
  3. data/VERSION +1 -1
  4. data/app/views/components/lolita/field/_boolean.html.erb +1 -0
  5. data/app/views/components/lolita/field/_select.html.erb +1 -1
  6. data/app/views/components/lolita/field/_text.html.erb +1 -1
  7. data/app/views/components/lolita/navigation/_display.html.erb +1 -1
  8. data/app/views/components/lolita/shared/_flash.html.erb +1 -1
  9. data/app/views/lolita/layouts/application.html.erb +3 -2
  10. data/lib/generators/lolita/{copy_assets_generator.rb → assets_generator.rb} +1 -1
  11. data/lib/generators/lolita/install_generator.rb +6 -3
  12. data/lib/lolita.rb +136 -135
  13. data/lib/lolita/adapter/active_record.rb +110 -110
  14. data/lib/lolita/adapter/mongoid.rb +104 -104
  15. data/lib/lolita/base_configuration.rb +49 -21
  16. data/lib/lolita/configuration/base.rb +76 -76
  17. data/lib/lolita/configuration/factory.rb +46 -0
  18. data/lib/lolita/configuration/field.rb +31 -45
  19. data/lib/lolita/configuration/field/boolean.rb +10 -0
  20. data/lib/lolita/configuration/{field_extensions → field}/collection.rb +25 -17
  21. data/lib/lolita/configuration/field/datetime.rb +10 -0
  22. data/lib/lolita/configuration/field/disabled.rb +10 -0
  23. data/lib/lolita/configuration/field/integer.rb +10 -0
  24. data/lib/lolita/configuration/field/password.rb +10 -0
  25. data/lib/lolita/configuration/field/string.rb +11 -0
  26. data/lib/lolita/configuration/field/text.rb +10 -0
  27. data/lib/lolita/configuration/tab.rb +5 -25
  28. data/lib/lolita/configuration/tab/default.rb +24 -0
  29. data/lib/lolita/configuration/tabs.rb +7 -3
  30. data/lib/lolita/controllers/component_helpers.rb +16 -1
  31. data/lib/lolita/errors.rb +2 -0
  32. data/lib/lolita/mapping.rb +17 -4
  33. data/lib/lolita/modules/rest.rb +1 -1
  34. data/lib/lolita/rails/routes.rb +21 -12
  35. data/lolita.gemspec +15 -5
  36. data/public/javascripts/lolita/main.js +7 -6
  37. data/public/javascripts/lolita/tab.js +36 -36
  38. data/spec/configuration/field_spec.rb +3 -3
  39. data/spec/configuration/tab_spec.rb +2 -2
  40. data/spec/configuration/tabs_spec.rb +7 -0
  41. data/spec/rails_app/public/javascripts/lolita/tab.js +36 -36
  42. data/spec/rails_app/public/javascripts/rails.js +137 -137
  43. metadata +16 -6
  44. data/lib/lolita/version.rb +0 -3
@@ -1,105 +1,105 @@
1
- module Lolita
2
- module Adapter
3
- class Mongoid
4
- include Lolita::Adapter::AbstractAdapter
5
-
6
- attr_reader :dbi, :klass
7
- def initialize(dbi)
8
- @dbi=dbi
9
- @klass=dbi.klass
10
- end
11
-
12
- def associations
13
- klass.relations
14
- end
15
-
16
- def associations_class_names
17
- names=[]
18
- associations.each{|name,association|
19
- names<<association.class_name
20
- }
21
- names
22
- end
23
-
24
- def reflect_on_association(name)
25
- klass.reflect_on_association(name)
26
- end
27
-
28
- def association_macro(association)
29
- macro=association.macro
30
- case macro
31
- when :references_many
32
- :many
33
- when :referenced_in
34
- :one
35
- when :embeds_one
36
- :one
37
- when :embeds_many
38
- :many
39
- when :references_one
40
- :one
41
- end
42
- end
43
-
44
- def association_class_name(association)
45
- association.class_name
46
- end
47
-
48
- def fields
49
- @fields||=self.klass.fields.collect{|name,field|
50
- field_to_hash(name,field)
51
- }
52
- @fields
53
- end
54
-
55
- def find_by_id(id)
56
- self.klass.where(:_id=>id).first
57
- end
58
-
59
- def find *args
60
- self.klass.find(*args)
61
- end
62
-
63
- def paginate(options={})
64
- self.klass.paginate(options)
65
- end
66
-
67
- def db
68
- self.klass.db
69
- end
70
-
71
- def db_name
72
- self.klass.db.name
73
- end
74
-
75
- def collection
76
- self.klass.collection
77
- end
78
-
79
- def collection_name
80
- collection.name
81
- end
82
-
83
- def collections
84
- db.collections
85
- end
86
-
87
- def collection_names
88
- db.collection_names
89
- end
90
-
91
- private
92
-
93
- def field_to_hash(name,field)
94
- {
95
- :name=>name,
96
- :type=>field.type.to_s,
97
- :title=>name.to_s.humanize,
98
- :options=>field.options.merge({
99
- :primary=>name.to_s=="_id"
100
- })
101
- }
102
- end
103
- end
104
- end
1
+ module Lolita
2
+ module Adapter
3
+ class Mongoid
4
+ include Lolita::Adapter::AbstractAdapter
5
+
6
+ attr_reader :dbi, :klass
7
+ def initialize(dbi)
8
+ @dbi=dbi
9
+ @klass=dbi.klass
10
+ end
11
+
12
+ def associations
13
+ klass.relations
14
+ end
15
+
16
+ def associations_class_names
17
+ names=[]
18
+ associations.each{|name,association|
19
+ names<<association.class_name
20
+ }
21
+ names
22
+ end
23
+
24
+ def reflect_on_association(name)
25
+ klass.reflect_on_association(name)
26
+ end
27
+
28
+ def association_macro(association)
29
+ macro=association.macro
30
+ case macro
31
+ when :references_many
32
+ :many
33
+ when :referenced_in
34
+ :one
35
+ when :embeds_one
36
+ :one
37
+ when :embeds_many
38
+ :many
39
+ when :references_one
40
+ :one
41
+ end
42
+ end
43
+
44
+ def association_class_name(association)
45
+ association.class_name
46
+ end
47
+
48
+ def fields
49
+ @fields||=self.klass.fields.collect{|name,field|
50
+ field_to_hash(name,field)
51
+ }
52
+ @fields
53
+ end
54
+
55
+ def find_by_id(id)
56
+ self.klass.where(:_id=>id).first
57
+ end
58
+
59
+ def find *args
60
+ self.klass.find(*args)
61
+ end
62
+
63
+ def paginate(options={})
64
+ self.klass.paginate(options)
65
+ end
66
+
67
+ def db
68
+ self.klass.db
69
+ end
70
+
71
+ def db_name
72
+ self.klass.db.name
73
+ end
74
+
75
+ def collection
76
+ self.klass.collection
77
+ end
78
+
79
+ def collection_name
80
+ collection.name
81
+ end
82
+
83
+ def collections
84
+ db.collections
85
+ end
86
+
87
+ def collection_names
88
+ db.collection_names
89
+ end
90
+
91
+ private
92
+
93
+ def field_to_hash(name,field)
94
+ {
95
+ :name=>name,
96
+ :type=>field.type.to_s,
97
+ :title=>name.to_s.humanize,
98
+ :options=>field.options.merge({
99
+ :primary=>name.to_s=="_id"
100
+ })
101
+ }
102
+ end
103
+ end
104
+ end
105
105
  end
@@ -3,12 +3,13 @@ module Lolita
3
3
  # Like Lolita.modules and Lolita.routes and so on.
4
4
  class BaseConfiguration
5
5
 
6
- attr_reader :scope, :modules, :routes, :controllers
6
+ attr_reader :scope, :modules, :routes, :controllers,:resources
7
7
  attr_accessor :mappings,:default_route,:user_classes,:authentication
8
8
 
9
9
  def initialize(scope)
10
10
  @scope=scope
11
11
  @mappings={}
12
+ @resources={}
12
13
  @default_module=nil
13
14
  @user_classes=[]
14
15
  @modules=[]
@@ -16,16 +17,30 @@ module Lolita
16
17
  @controllers={}
17
18
  end
18
19
 
20
+ # Call (with #call) to route klass
21
+ # And return all names of routes that are needed for resource.
19
22
  def conditional_routes(klass=nil)
20
23
  @routes.map{|name,route|
21
- if route.is_a?(Proc)
22
- route.call(klass)
23
- else
24
- nil
24
+ if route.first
25
+ if route.last.respond_to?(:call)
26
+ route.last.call(klass)
27
+ else
28
+ nil
29
+ end
25
30
  end
26
31
  }.compact
27
32
  end
28
33
 
34
+ # Find all routes that is needed for defined classes
35
+ # And return only one for each different route.
36
+ def common_routes(klasses)
37
+ @routes.map{|name,route|
38
+ unless route.first
39
+ klasses.map{|klass| route.last.is_a?(Proc) ? route.last.call(klass) : nil}
40
+ end
41
+ }.flatten.compact.uniq
42
+ end
43
+
29
44
  # Include module in Lolita, don't know why i need this
30
45
  def use(module_name)
31
46
  Lolita.send(:include,module_name)
@@ -40,6 +55,7 @@ module Lolita
40
55
  # Add new module to Lolita
41
56
  # Accpted options
42
57
  # * <tt>controller</tt> - not in use
58
+ # * <tt>nested</tt> - is route stands itsefl or is used in combination with resource
43
59
  # * <tt>route</tt> - Symbol of route name or lambad, that return route name based on resource.
44
60
  # Route name is used to call method lolita_[route_name] in Mapper class, and that should draw route.
45
61
  # * <tt>:name</tt> - name of module, underscored symbol. Used to draw default route, by default always
@@ -51,25 +67,37 @@ module Lolita
51
67
  # lolita_for :posts #=> create url whatever is defined in lolita_post method, and goes to :controller=>"lolita/posts"
52
68
  # Lolita.add_module Lolita::FileUpload, :route=>lambda{|resource| resource.lolita.tabs.by_type(:file) ? :file_upload : nil}
53
69
  # lolita_for :users #=> creat default rest urls and also call method lolita_file_upload if user lolita define :file tab.
70
+ # To add route for public interface that goes to added module, than use
71
+ # Lolita.add_module Post, :name=>:posts
72
+ # And then when in routes.rb will be defined lolita_for(:posts) it will call method <i>lolita_posts_route</i>
73
+ # and that method should define resource.
74
+ # ====Example
75
+ # # require this in your gem or lib
76
+ # module ActionDispatch::Routing
77
+ # class Mapper
78
+ # protected
79
+ # def lolita_posts_route mapping, controllers
80
+ # resources mapping.plural,:only=>[:index,:new,:create],
81
+ # :controller=>controllers[:posts],:module=>mapping.module
82
+ # end
83
+ # end
84
+ # end
85
+ # You open Mapper class and add your method that call #resources or #match or other method that define route
86
+ # For common route for all lolita resources your method should look like this
87
+ # ====Example
88
+ # def lolita_files_route
89
+ # mapping=Lolita.add_mapping(:files,:class_name=>"Lolita::Multimedia::File",:module=>"file_upload")
90
+ # scope :module=>mapping.module do
91
+ # resources mapping.name
92
+ # end
93
+ # end
54
94
  def add_module module_container, options={}
55
- options.assert_valid_keys(:controller,:route,:model,:path,:name)
95
+ options.assert_valid_keys(:controller,:route,:model,:path,:name,:nested)
56
96
  name=options[:name]||module_container.to_s.to_sym
57
97
  self.modules<<module_container
58
- config={
59
- :route=>self.routes,
60
- :controller=>self.controllers
61
- }
62
- config.each{|key,value|
63
- next unless options[key]
64
- new_value=options[key]
65
- if value.is_a?(Hash)
66
- value[name]=new_value
67
- elsif value.is_a?(Proc)
68
- value[name]=new_value
69
- elsif value.respond_to?(:include?) && !value.include?(new_value)
70
- value << new_value
71
- end
72
- }
98
+
99
+ self.routes[name]=[options.has_key?(:nested) ? options[:nested] : true,options[:route]]
100
+ self.controllers[name]=options[:controller] if options.has_key?(:controller)
73
101
 
74
102
  if options[:path]
75
103
  require File.join(options[:path],name.to_s)
@@ -1,76 +1,76 @@
1
- # Every class that include Lolita::Configuration this module assign
2
- # #lolita and #lolita= methods. First one is for normal Lolita configuration
3
- # definition, and the other one made to assing Lolita to class as a Lolita::Configuration::Base
4
- # object. You may want to do that to change configuration or for testing purpose.
5
- module Lolita
6
- module Configuration
7
- # Lolita could be defined inside of any class that is supported by Lolita::Adapter, for now that is
8
- # * ActiveRecord::Base
9
- # * Mongoid::Document
10
- # Main block can hold these methods:
11
- # <tt>list</tt> - List definition, see Lolitia::Configuration::List
12
- # <tt>tab</tt> - Tab definition, see Lolita::Configuration::Tab
13
- # <tt>tabs</tt> - Tabs definition, see Lolita::Configuration::Tabs
14
- class Base
15
-
16
- attr_reader :dbi,:klass
17
- @@generators=[:tabs,:list]
18
- class << self
19
- def add_generator(method)
20
- @@generators<<method.to_sym
21
- end
22
- end
23
- # When configuration is defined in class than you don't need to worry about
24
- # creating new object, because Lolita itself create it for that class.
25
- # New object is created like when you define it in class, but <i>parent_class</i>
26
- # must be given.
27
- # ====Example
28
- # class Person < ActiveRecord::Base
29
- # include Lolita::Configuration
30
- # lolita
31
- # end
32
- # Person.lolita.klass #=> Person
33
- # # Init Lolita by youself
34
- #
35
- # class Person < ActiveRecord::Base
36
- # include Lolita::Configuration
37
- # end
38
- # Person.lolita=Lolita::Configuration::Base.new(Person)
39
- # Person.lolita.klass #=> Person
40
- def initialize(orm_class,&block)
41
- @klass=orm_class
42
- @dbi=Lolita::DBI::Base.new(orm_class)
43
- block_given? ? self.instance_eval(&block) : self.generate!
44
- end
45
-
46
-
47
- # Create list variable for ::Base class and create lazy object of Lolita::LazyLoader.
48
- # See Lolita::Configuration::List for more information.
49
- def list &block
50
- Lolita::LazyLoader.lazy_load(self,:@list,Lolita::Configuration::List,@dbi,&block)
51
- end
52
-
53
- # Create collection of Lolita::Configuration::Tab, loading lazy.
54
- # See Lolita::Configuration::Tabs for details.
55
- def tabs &block
56
- Lolita::LazyLoader.lazy_load(self, :@tabs,Lolita::Configuration::Tabs,@dbi,&block)
57
- end
58
-
59
- # Shortcut for Lolita::Configuration::Tabs <<.
60
- # Tabs should not be defined in lolita block to create onew or more Lolita::Configuration::Tab
61
- # See Lolita::Configuration::Tab for details of defination.
62
- def tab *args, &block
63
- self.tabs<<Lolita::Configuration::Tab.add(@dbi,*args,&block)
64
- end
65
-
66
- # Call all supported instance metods to set needed variables and initialize object with them.
67
- def generate!
68
- @@generators.each{|generator|
69
- self.send(generator)
70
- }
71
- end
72
-
73
- end
74
- end
75
- end
76
-
1
+ # Every class that include Lolita::Configuration this module assign
2
+ # #lolita and #lolita= methods. First one is for normal Lolita configuration
3
+ # definition, and the other one made to assing Lolita to class as a Lolita::Configuration::Base
4
+ # object. You may want to do that to change configuration or for testing purpose.
5
+ module Lolita
6
+ module Configuration
7
+ # Lolita could be defined inside of any class that is supported by Lolita::Adapter, for now that is
8
+ # * ActiveRecord::Base
9
+ # * Mongoid::Document
10
+ # Main block can hold these methods:
11
+ # <tt>list</tt> - List definition, see Lolitia::Configuration::List
12
+ # <tt>tab</tt> - Tab definition, see Lolita::Configuration::Tab
13
+ # <tt>tabs</tt> - Tabs definition, see Lolita::Configuration::Tabs
14
+ class Base
15
+
16
+ attr_reader :dbi,:klass
17
+ @@generators=[:tabs,:list]
18
+ class << self
19
+ def add_generator(method)
20
+ @@generators<<method.to_sym
21
+ end
22
+ end
23
+ # When configuration is defined in class than you don't need to worry about
24
+ # creating new object, because Lolita itself create it for that class.
25
+ # New object is created like when you define it in class, but <i>parent_class</i>
26
+ # must be given.
27
+ # ====Example
28
+ # class Person < ActiveRecord::Base
29
+ # include Lolita::Configuration
30
+ # lolita
31
+ # end
32
+ # Person.lolita.klass #=> Person
33
+ # # Init Lolita by youself
34
+ #
35
+ # class Person < ActiveRecord::Base
36
+ # include Lolita::Configuration
37
+ # end
38
+ # Person.lolita=Lolita::Configuration::Base.new(Person)
39
+ # Person.lolita.klass #=> Person
40
+ def initialize(orm_class,&block)
41
+ @klass=orm_class
42
+ @dbi=Lolita::DBI::Base.new(orm_class)
43
+ block_given? ? self.instance_eval(&block) : self.generate!
44
+ end
45
+
46
+
47
+ # Create list variable for ::Base class and create lazy object of Lolita::LazyLoader.
48
+ # See Lolita::Configuration::List for more information.
49
+ def list &block
50
+ Lolita::LazyLoader.lazy_load(self,:@list,Lolita::Configuration::List,@dbi,&block)
51
+ end
52
+
53
+ # Create collection of Lolita::Configuration::Tab, loading lazy.
54
+ # See Lolita::Configuration::Tabs for details.
55
+ def tabs &block
56
+ Lolita::LazyLoader.lazy_load(self, :@tabs,Lolita::Configuration::Tabs,@dbi,&block)
57
+ end
58
+
59
+ # Shortcut for Lolita::Configuration::Tabs <<.
60
+ # Tabs should not be defined in lolita block to create onew or more Lolita::Configuration::Tab
61
+ # See Lolita::Configuration::Tab for details of defination.
62
+ def tab *args, &block
63
+ self.tabs<<Lolita::Configuration::Tab.add(@dbi,*args,&block)
64
+ end
65
+
66
+ # Call all supported instance metods to set needed variables and initialize object with them.
67
+ def generate!
68
+ @@generators.each{|generator|
69
+ self.send(generator)
70
+ }
71
+ end
72
+
73
+ end
74
+ end
75
+ end
76
+