lolita 3.2.0.rc.17 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +22 -17
  3. data/Rakefile +3 -0
  4. data/app/assets/javascripts/lolita/list.js +2 -2
  5. data/app/assets/javascripts/lolita/main.js +2 -2
  6. data/app/assets/javascripts/lolita/tab.js +7 -7
  7. data/app/assets/stylesheets/lolita/PIE-custom.htc +87 -87
  8. data/app/assets/stylesheets/lolita/PIE.htc +81 -81
  9. data/app/assets/stylesheets/lolita/application.css +6 -6
  10. data/app/assets/stylesheets/lolita/default.css.erb +169 -169
  11. data/app/assets/stylesheets/lolita/jquery-ui-1.8.16.lolita.css.erb +567 -567
  12. data/app/assets/stylesheets/lolita/style.css.erb +4 -1
  13. data/app/helpers/components/lolita/configuration/list_component.rb +10 -10
  14. data/app/views/components/lolita/configuration/column/_first.html.haml +1 -1
  15. data/app/views/components/lolita/configuration/column/header/_first.html.haml +1 -1
  16. data/app/views/components/lolita/configuration/column/header/_sort.html.haml +6 -6
  17. data/app/views/components/lolita/configuration/columns/header/_display.html.haml +5 -5
  18. data/app/views/components/lolita/configuration/field/array/checkbox/_display.html.haml +7 -7
  19. data/app/views/components/lolita/configuration/filter/_display.html.haml +2 -2
  20. data/app/views/components/lolita/configuration/search/_display.html.haml +2 -2
  21. data/app/views/kaminari/lolita/_first_page.html.erb +11 -11
  22. data/app/views/kaminari/lolita/_gap.html.erb +8 -8
  23. data/app/views/kaminari/lolita/_last_page.html.erb +11 -11
  24. data/app/views/kaminari/lolita/_next_page.html.erb +11 -11
  25. data/app/views/kaminari/lolita/_page.html.erb +12 -12
  26. data/app/views/kaminari/lolita/_paginator.html.erb +23 -23
  27. data/app/views/kaminari/lolita/_prev_page.html.erb +11 -11
  28. data/app/views/lolita/info/index.html.erb +232 -232
  29. data/app/views/lolita/rest/index.html.haml +1 -1
  30. data/config/routes.rb +6 -6
  31. data/lib/generators/lolita/install_generator.rb +2 -4
  32. data/lib/generators/lolita/uninstall_generator.rb +3 -8
  33. data/lib/generators/templates/lolita.rb +13 -16
  34. data/lib/lolita.rb +4 -5
  35. data/lib/lolita/adapter/active_record.rb +4 -4
  36. data/lib/lolita/adapter/common_helper.rb +45 -71
  37. data/lib/lolita/adapter/field_helper.rb +18 -18
  38. data/lib/lolita/adapter/mongoid.rb +8 -8
  39. data/lib/lolita/configuration/field/big_decimal.rb +12 -12
  40. data/lib/lolita/configuration/field/boolean.rb +12 -12
  41. data/lib/lolita/configuration/field/date.rb +12 -12
  42. data/lib/lolita/configuration/field/hidden.rb +12 -12
  43. data/lib/lolita/configuration/field/integer.rb +11 -11
  44. data/lib/lolita/configuration/field/string.rb +16 -16
  45. data/lib/lolita/configuration/field/time.rb +13 -13
  46. data/lib/lolita/configuration/field_set.rb +25 -25
  47. data/lib/lolita/configuration/filter.rb +6 -0
  48. data/lib/lolita/configuration/list.rb +10 -10
  49. data/lib/lolita/configuration/nested_form.rb +104 -104
  50. data/lib/lolita/configuration/search.rb +104 -104
  51. data/lib/lolita/configuration/tab/content.rb +3 -3
  52. data/lib/lolita/controllers/component_helpers.rb +9 -9
  53. data/lib/lolita/controllers/rails_helpers.rb +5 -5
  54. data/lib/lolita/dbi/base.rb +56 -56
  55. data/lib/lolita/hooks.rb +16 -16
  56. data/lib/lolita/hooks/named_hook.rb +125 -125
  57. data/lib/lolita/lazy_loader.rb +54 -54
  58. data/lib/lolita/navigation/tree.rb +132 -132
  59. data/lib/lolita/rails/engine.rb +2 -2
  60. data/lib/lolita/rails/routes.rb +9 -9
  61. data/lib/lolita/ruby_ext/accessors.rb +26 -26
  62. data/lib/lolita/ruby_ext/lolita_model_name.rb +10 -2
  63. data/lib/lolita/search/simple.rb +75 -75
  64. data/lib/lolita/support/formatter.rb +62 -62
  65. data/lib/lolita/support/formatter/rails.rb +56 -56
  66. data/lib/lolita/test/matchers.rb +77 -77
  67. data/lib/lolita/version.rb +2 -2
  68. data/spec/adapter/common_helper_spec.rb +96 -0
  69. data/spec/adapter_helper.rb +3 -4
  70. data/spec/builder_spec.rb +120 -120
  71. data/spec/configuration/base_spec.rb +1 -1
  72. data/spec/configuration/column_spec.rb +1 -1
  73. data/spec/configuration/columns_spec.rb +1 -1
  74. data/spec/configuration/core_spec.rb +1 -1
  75. data/spec/configuration/field_set_spec.rb +1 -1
  76. data/spec/configuration/field_spec.rb +1 -1
  77. data/spec/configuration/filter_spec.rb +30 -1
  78. data/spec/configuration/list_spec.rb +44 -145
  79. data/spec/configuration/nested_list_spec.rb +1 -1
  80. data/spec/configuration/search_spec.rb +1 -1
  81. data/spec/configuration/tab_spec.rb +1 -1
  82. data/spec/configuration/tabs_spec.rb +1 -2
  83. data/spec/controllers/component_helpers_spec.rb +1 -1
  84. data/spec/controllers/configuration_spec.rb +1 -1
  85. data/spec/controllers/internal_helpers_spec.rb +1 -1
  86. data/spec/controllers/lolita_rest_nested_resources_spec.rb +1 -1
  87. data/spec/controllers/lolita_rest_spec.rb +2 -2
  88. data/spec/dbi/base_spec.rb +1 -4
  89. data/spec/extensions/authorization/cancan_adapter_spec.rb +4 -4
  90. data/spec/extensions/extensions_spec.rb +1 -1
  91. data/spec/generators/lolita/install_generator_spec.rb +55 -0
  92. data/spec/generators/lolita/uninstall_generator_spec.rb +49 -0
  93. data/spec/hooks_spec.rb +25 -25
  94. data/spec/mapping_spec.rb +1 -1
  95. data/spec/navigation/branch_spec.rb +1 -1
  96. data/spec/navigation/tree_spec.rb +1 -1
  97. data/spec/rails_app/app/controllers/application_controller.rb +3 -3
  98. data/spec/rails_app/app/helpers/application_helper.rb +3 -3
  99. data/spec/rails_app/app/mongoid/address.rb +7 -7
  100. data/spec/rails_app/app/mongoid/comment.rb +5 -5
  101. data/spec/rails_app/app/mongoid/preference.rb +5 -5
  102. data/spec/rails_app/app/mongoid/profile.rb +13 -13
  103. data/spec/rails_app/app/mongoid/tag.rb +3 -3
  104. data/spec/rails_app/app/views/components/lolita/configuration/list/_body_cell.html.erb +1 -1
  105. data/spec/rails_app/config/boot.rb +4 -9
  106. data/spec/rails_app/config/environment.rb +5 -5
  107. data/spec/rails_app/config/environments/production.rb +37 -37
  108. data/spec/rails_app/config/environments/test.rb +37 -37
  109. data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -7
  110. data/spec/rails_app/config/initializers/inflections.rb +2 -2
  111. data/spec/rails_app/config/initializers/secret_token.rb +1 -1
  112. data/spec/rails_app/config/routes.rb +1 -1
  113. data/spec/rails_app/lib/lolita/configuration/field/my_custom_collection.rb +13 -13
  114. data/spec/rails_app/log/development.log +12940 -43222
  115. data/spec/rails_app/public/javascripts/jquery-1.5.1.min.js +15 -15
  116. data/spec/rails_app/public/javascripts/lolita/main.js +6 -6
  117. data/spec/rails_app/public/javascripts/modernizr-1.7.min.js +1 -1
  118. data/spec/rails_app/public/javascripts/rails.js +137 -137
  119. data/spec/rails_app/public/javascripts/tinymce/langs/en.js +221 -221
  120. data/spec/rails_app/public/javascripts/tinymce/license.txt +504 -504
  121. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/about.htm +52 -52
  122. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/anchor.htm +26 -26
  123. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/charmap.htm +51 -51
  124. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/color_picker.htm +74 -74
  125. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/editor_template_src.js +1328 -1328
  126. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/image.htm +80 -80
  127. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/about.js +73 -73
  128. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/anchor.js +42 -42
  129. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/charmap.js +354 -354
  130. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/color_picker.js +329 -329
  131. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/image.js +247 -247
  132. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/link.js +153 -153
  133. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/source_editor.js +56 -56
  134. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/langs/en.js +68 -68
  135. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/langs/en_dlg.js +53 -53
  136. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/link.htm +57 -57
  137. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/shortcuts.htm +47 -47
  138. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/skins/cirkuit/content.css +66 -66
  139. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/skins/cirkuit/dialog.css +117 -117
  140. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/skins/cirkuit/ui.css +988 -988
  141. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/source_editor.htm +25 -25
  142. data/spec/rails_app/public/javascripts/tinymce/tiny_mce_popup.js +4 -4
  143. data/spec/rails_app/public/stylesheets/lolita/default.css +169 -169
  144. data/spec/rails_app/public/stylesheets/lolita/style.css +214 -214
  145. data/spec/routing/routes_spec.rb +1 -1
  146. data/spec/search/simple_spec.rb +1 -1
  147. data/spec/simple_spec_helper.rb +1 -1
  148. data/spec/spec_helper.rb +6 -4
  149. data/spec/support/formatter_spec.rb +1 -1
  150. data/spec/tmp/config/routes.rb +0 -0
  151. data/vendor/assets/javascripts/jquery-numeric.js +279 -279
  152. data/vendor/assets/javascripts/modernizr_1_7_min.js +1 -1
  153. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/content.css +66 -66
  154. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/dialog.css +117 -117
  155. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/ui.css +988 -988
  156. data/vendor/assets/stylesheets/jquery-ui-1.8.16.custom.css +567 -567
  157. metadata +380 -395
  158. data/spec/rails_app/coverage.data +0 -1
  159. data/spec/rails_app/log/test.log +0 -370
@@ -1 +1 @@
1
- = render_component *@component_builder
1
+ = render_component *@component_builder
data/config/routes.rb CHANGED
@@ -1,6 +1,6 @@
1
- Rails.application.routes.draw do
2
- match '/lolita' => "lolita/info#index"
3
- match '/lolita/info/properties' => "lolita/info#properties"
4
- match "/lolita/array_field/:name/:field_class/:class/:id" => "lolita/field_data#array_polymorphic", :as => "array_field_data_collector"
5
- match "/lolita/autocomplete_field/:field_class/:field_name" => "lolita/field_data#autocomplete_field", :as => "autocomplete_field"
6
- end
1
+ Rails.application.routes.draw do
2
+ match '/lolita' => "lolita/info#index"
3
+ match '/lolita/info/properties' => "lolita/info#properties"
4
+ match "/lolita/array_field/:name/:field_class/:class/:id" => "lolita/field_data#array_polymorphic", :as => "array_field_data_collector"
5
+ match "/lolita/autocomplete_field/:field_class/:field_name" => "lolita/field_data#autocomplete_field", :as => "autocomplete_field"
6
+ end
@@ -4,18 +4,16 @@ module Lolita
4
4
  source_root File.expand_path("../../templates", __FILE__)
5
5
  desc "Create lolita initializer."
6
6
 
7
-
8
7
  def copy_initializer
9
8
  template "lolita.rb", "config/initializers/lolita.rb" unless File.exist?(Rails.root + "config/initializers/lolita.rb")
10
9
  end
11
10
 
12
11
  def install_modules
13
12
  Lolita.modules.each do |module_name|
14
-
15
- invoke "lolita:#{module_name.to_s.underscore.gsub("/","_").gsub(/^lolita_/,"")}:install" rescue nil
13
+ invoke "lolita:#{module_name.to_s.underscore.gsub("/","_").gsub(/^lolita_/,"")}:install" rescue nil
16
14
  end
17
15
  end
18
-
16
+
19
17
  end
20
18
  end
21
19
  end
@@ -7,19 +7,14 @@ module Lolita
7
7
 
8
8
  desc "Uninstall Lolita and remove all dependencies"
9
9
 
10
- def ask_to_continue
11
- #ask("Do you want to remove initializer, clear routes and remove Lolita from models? [y]es/[n]o")
12
- end
13
10
  # Remove lolita initializer file
14
11
  def remove_initializer
15
- if File.exist?(Rails.root + "config/initializers/lolita.rb")
16
- remove_file "config/initializers/lolita.rb"
17
- end
12
+ remove_file "config/initializers/lolita.rb"
18
13
  end
19
14
 
20
15
  # Remove all not-commented lines that begins with lolita_for
21
16
  def clear_routes
22
- gsub_file File.join(Rails.root,"config","routes.rb"), /^\s*#{ROUTE_NAME}.*/ do |match|
17
+ gsub_file Rails.root.join("config","routes.rb"), /^\s*#{ROUTE_NAME}.*/ do |match|
23
18
  match.clear
24
19
  match
25
20
  end
@@ -28,7 +23,7 @@ module Lolita
28
23
  # Remove configuration include line and lolita block or single lolita method call.
29
24
  # Block will be removed correctly if it starts with _do_ and ends with _end_.
30
25
  def clear_models
31
- Dir[File.join(Rails.root,"app","models","*.rb")].each do |file_name|
26
+ Dir[Rails.root.join("app","models","*.rb")].each do |file_name|
32
27
  matched = false
33
28
  gsub_file file_name, /^\s*include\s+#{INCLUDE_MODULE}.*/ do |match|
34
29
  matched = true
@@ -1,17 +1,14 @@
1
-
2
1
  Lolita.setup do |config|
3
- # ==> User and authentication configuration
4
- # Add one or more of your user classes to Lolita
5
- # config.user_classes << MyUser
6
- # config.authentication = :authenticate_user!
7
-
8
- # Define authentication for Lolita controllers.
9
- # Call some of your own methods
10
- # config.authentication=:is_admin?
11
-
12
- <% if defined?(Devise) %>
13
- <% default_user_class = Devise.mappings.keys.first %>
14
- config.user_classes << <%= default_user_class.to_s.camelize %>
15
- config.authentication=:authenticate_<%= default_user_class %>!
16
- <% end %>
17
- end
2
+ #= More info about setup - https://github.com/ithouse/lolita/wiki/Lolita-setup
3
+ #= More info about authentication - https://github.com/ithouse/lolita/wiki/Authorization-and-authentication
4
+ <% if defined?(Devise) && Devise.respond_to?(:mappings) && default_user_class = Devise.mappings.keys.first %>
5
+ config.user_classes << <%= default_user_class.to_s.camelize %>
6
+ config.authentication=:authenticate_<%= default_user_class %>!
7
+ <% else %>
8
+ #= Sample config for Admin user managing Lolita
9
+ # config.user_classes << Admin
10
+ # config.authentication = :authenticate_admin!
11
+ <% end %>
12
+ ## add this if you manage your authorization with CanCan
13
+ # config.authorization = "CanCan"
14
+ end
data/lib/lolita.rb CHANGED
@@ -16,7 +16,7 @@ module Lolita
16
16
  yield configuration
17
17
  self.run(:after_setup)
18
18
  end
19
-
19
+
20
20
  def self.root
21
21
  @@root||=File.expand_path("#{__FILE__}/../..")
22
22
  end
@@ -24,7 +24,7 @@ module Lolita
24
24
  def self.app_root
25
25
  @@app_root||=File.join(File.expand_path("#{__FILE__}/../.."),"app")
26
26
  end
27
-
27
+
28
28
  def self.method_missing method_name, *args, &block
29
29
  self.class_eval <<-LOLITA_SETUP,__FILE__,__LINE__+1
30
30
  class << self
@@ -44,7 +44,7 @@ module Lolita
44
44
  self.send(:include, Lolita::Hooks)
45
45
  self.send(:add_hook, :before_setup, :after_setup, :after_routes_loaded,:before_routes_loaded)
46
46
 
47
-
47
+
48
48
  if rails?
49
49
  load_rails!
50
50
  end
@@ -54,7 +54,7 @@ module Lolita
54
54
  def self.load_frameworks!
55
55
  frameworks.each do |framework|
56
56
  begin
57
- require framework
57
+ require framework
58
58
  puts "=> Loading Lolita #{version} with #{framework}"
59
59
  rescue Execption => e
60
60
  raise "Can't load #{framework}. Check you Gemfile."
@@ -138,5 +138,4 @@ module Lolita
138
138
  end
139
139
  end
140
140
 
141
-
142
141
  Lolita.load!
@@ -3,7 +3,7 @@ module Lolita
3
3
  class ActiveRecord
4
4
 
5
5
  include Lolita::Adapter::AbstractAdapter
6
-
6
+
7
7
  attr_reader :dbi, :klass
8
8
  def initialize(dbi)
9
9
  @dbi=dbi
@@ -28,7 +28,7 @@ module Lolita
28
28
  association_key
29
29
  else
30
30
  @association.foreign_key
31
- end
31
+ end
32
32
  end
33
33
 
34
34
  def association_key
@@ -57,7 +57,7 @@ module Lolita
57
57
 
58
58
  def macro
59
59
  convertator = {
60
- :has_many => :many, :has_one => :one, :belongs_to => :one,
60
+ :has_many => :many, :has_one => :one, :belongs_to => :one,
61
61
  :has_and_belongs_to_many => :many_to_many
62
62
  }
63
63
  convertator[@association.macro]
@@ -95,7 +95,7 @@ module Lolita
95
95
  [association.key.to_s].include?(@name.to_s)
96
96
  }
97
97
  @association = if possible_association
98
- possible_association.last
98
+ possible_association.last
99
99
  else
100
100
  false
101
101
  end
@@ -3,7 +3,7 @@ module Lolita
3
3
  module CommonHelper
4
4
 
5
5
  class Record
6
- def initialize(adapter,orm_record)
6
+ def initialize(adapter, orm_record)
7
7
  @adapter = adapter
8
8
  @record = orm_record
9
9
  end
@@ -37,23 +37,33 @@ module Lolita
37
37
  @options[:request]
38
38
  end
39
39
 
40
- def set_nested_criteria
40
+ def nested_criteria
41
41
  nested_hsh = params[:nested]
42
42
  if params[:nested] && !params[:nested][:association]
43
43
  nested_hsh = nested_hsh.reject{|k,v| [:parent,:path].include?(k.to_sym)}
44
- @nested_criteria = @adapter.klass.where(nested_hsh)
44
+ @adapter.klass.where(nested_hsh)
45
+ else
46
+ @adapter.klass.unscoped
47
+ end
48
+ end
49
+
50
+ def ability_criteria
51
+ if @adapter.klass.respond_to?(:accessible_by)
52
+ @adapter.klass.accessible_by(current_ability)
53
+ else
54
+ @adapter.klass.unscoped
45
55
  end
46
56
  end
47
57
 
48
- def set_relation
49
- @relation = if params[:nested] && params[:nested][:association]
50
- @adapter.find_by_id(hsh[:nested][:id]).send(hsh[:nested][:association])
58
+ def relation
59
+ if params[:nested] && params[:nested][:association]
60
+ @adapter.find(hsh[:nested][:id]).send(hsh[:nested][:association])
51
61
  else
52
62
  @adapter.klass.unscoped
53
63
  end
54
64
  end
55
65
 
56
- def set_custom_criteria
66
+ def custom_criteria
57
67
  if @options[:pagination_method]
58
68
  if @options[:pagination_method].respond_to?(:each)
59
69
  @options[:pagination_method].each do |method_name|
@@ -65,7 +75,13 @@ module Lolita
65
75
  else
66
76
  @custom_criteria = pagination_scope_for_klass(@options[:pagination_method],@page,@per,@options)
67
77
  end
68
- raise ArgumentError, "Didn't generate any scope from #{@options} page:{page} per:#{@per}" unless @custom_criteria
78
+ unless @custom_criteria
79
+ raise ArgumentError, "Didn't generate any scope from #{@options} page:{page} per:#{@per}"
80
+ else
81
+ @custom_criteria
82
+ end
83
+ else
84
+ @adapter.klass.unscoped
69
85
  end
70
86
  end
71
87
 
@@ -76,23 +92,24 @@ module Lolita
76
92
  end
77
93
 
78
94
  def create_page
79
- set_nested_criteria
80
- set_relation
81
- set_custom_criteria
82
-
83
- page_criteria = if @nested_criteria
84
- @relation.merge(@nested_criteria)
85
- else
86
- @relation
87
- end
88
- if @custom_criteria
89
- page_criteria = @custom_criteria.merge(page_criteria)
90
- end
95
+ page_criteria = relation.merge(nested_criteria).merge(ability_criteria).merge(custom_criteria)
91
96
  unless page_criteria.respond_to?(:current_page)
92
- page_criteria = page_criteria.page(@page).per(@per)
97
+ page_criteria = page_criteria.order(sorting).page(@page).per(@per)
93
98
  end
94
99
  page_criteria
95
100
  end
101
+
102
+ def current_ability
103
+ controller = request.headers["action_controller.instance"]
104
+ if controller && controller.respond_to?(:current_ability)
105
+ controller.current_ability
106
+ end
107
+ end
108
+
109
+ def sorting
110
+ params[:s] ? params[:s].gsub(',',' ').gsub('|',',') : nil
111
+ end
112
+
96
113
  end
97
114
 
98
115
  def record(orm_record)
@@ -131,76 +148,33 @@ module Lolita
131
148
  self.klass.unscoped.merge(by_id(id)).first
132
149
  end
133
150
 
134
- # def nested_scope_from_hash(hsh)
135
- # nested_hsh ||= (hsh[:nested] || {})
136
- # unless nested_hsh[:association]
137
- # nested_hsh = nested_hsh.reject{|k,v| [:parent,:path].include?(k.to_sym)}
138
- # criteria = klass.where(nested_hsh)
139
- # criteria
140
- # end
141
- # end
142
-
143
- # def scope_from_hash(hsh)
144
- # if hsh[:nested] && hsh[:nested][:association]
145
- # klass.find_by_id(hsh[:nested][:id]).send(hsh[:nested][:association])
146
- # end
147
- # end
148
-
149
- # This method is used to paginate, main reason is for list and for index action.
151
+ # This method is used to paginate, main reason is for list and for index action.
150
152
  # Method accepts three arguments
151
153
  # <tt>page</tt> - page that should be shown (integer)
152
154
  # <tt>per</tt> - how many records there should be in page
153
- # <tt>options</tt> - Hash with optional information.
155
+ # <tt>options</tt> - Hash with optional information.
154
156
  # By default, Lolita::Configuration::List passes request, with current request information.
155
157
  # Also it passes <i>:pagination_method</i> that is used to detect if there is special method(-s) in model
156
158
  # that should be used for creating page.
157
- def paginate(page,per,options ={})
158
-
159
- pagination_builder = PaginationBuilder.new(self,page,per,options)
159
+ def paginate(page, per, options = {})
160
+ pagination_builder = PaginationBuilder.new(self, page, per, options)
160
161
  pagination_builder.create_page
161
-
162
- # criteria = options[:request].respond_to?(:params) && nested_scope_from_hash(options[:request].params) || {}
163
- # scope = options[:request].respond_to?(:params) && scope_from_hash(options[:request].params) || klass.unscoped
164
-
165
- # if options[:pagination_method]
166
- # if options[:pagination_method].respond_to?(:each)
167
- # options[:pagination_method].each do |method_name|
168
- # options[:previous_scope] = scope
169
- # if new_criteria = pagination_criteria_for_klass(method_name,page,per,options)
170
- # criteria = criteria ? criteria.merge(new_criteria) : new_criteria
171
- # end
172
- # end
173
- # else
174
- # new_criteria = pagination_scope_for_klass(options[:pagination_method],page,per,options)
175
- # criteria = if new_criteria.respond_to?(:current_page) #already have per and page
176
- # new_criteria
177
- # else
178
- # criteria && criteria.merge(new_criteria) || new_criteria
179
- # end
180
- # end
181
- # raise ArgumentError, "Didn't generate any scope from #{options} page:{page} per:#{per}" unless criteria
182
- # criteria
183
- # else
184
- # scope.merge(criteria).page(page).per(per)
185
- # end
186
162
  end
187
163
 
188
-
189
-
190
164
  def switch_record_state(record, state = nil)
191
165
  set_state_for(record)
192
166
  if state
193
- record.send(:"#{state}_state!")
167
+ record.send(:"#{state}_state!")
194
168
  elsif !record.have_state?
195
169
  if record.new_record?
196
170
  record.create_state!
197
- else
171
+ else
198
172
  record.update_state!
199
173
  end
200
174
  end
201
175
  record
202
176
  end
203
-
177
+
204
178
  def set_state_for(record)
205
179
  unless record.respond_to?(:read_state!)
206
180
  class << record
@@ -1,19 +1,19 @@
1
- module Lolita
2
- module Adapter
3
- module FieldHelper
4
- def technical?
5
- if self.name.to_s.match(/^created_at|updated_at|type$/)
6
- true
7
- elsif self.primary?
8
- true
9
- elsif adapter.klass.respond_to?(:uploaders)
10
- adapter.klass.uploaders.keys.include?(name.to_sym)
11
- end
12
- end
13
-
14
- def content?
15
- !technical?
16
- end
17
- end
18
- end
1
+ module Lolita
2
+ module Adapter
3
+ module FieldHelper
4
+ def technical?
5
+ if self.name.to_s.match(/^created_at|updated_at|type$/)
6
+ true
7
+ elsif self.primary?
8
+ true
9
+ elsif adapter.klass.respond_to?(:uploaders)
10
+ adapter.klass.uploaders.keys.include?(name.to_sym)
11
+ end
12
+ end
13
+
14
+ def content?
15
+ !technical?
16
+ end
17
+ end
18
+ end
19
19
  end
@@ -3,7 +3,7 @@ module Lolita
3
3
  class Mongoid
4
4
 
5
5
  include Lolita::Adapter::AbstractAdapter
6
-
6
+
7
7
  attr_reader :dbi, :klass
8
8
  def initialize(dbi)
9
9
  @dbi=dbi
@@ -41,7 +41,7 @@ module Lolita
41
41
 
42
42
  def macro
43
43
  convertator = {
44
- :references_many => :many, :references_one => :one, :referenced_in => :one,
44
+ :references_many => :many, :references_one => :one, :referenced_in => :one,
45
45
  :references_and_referenced_in_many => :many_to_many, :embeds_one => :one, :embeds_many => :many
46
46
  }
47
47
  convertator[@association.macro]
@@ -79,7 +79,7 @@ module Lolita
79
79
  [association.key.to_s].include?(@name.to_s)
80
80
  }
81
81
  @association = if possible_association
82
- possible_association.last
82
+ possible_association.last
83
83
  else
84
84
  false
85
85
  end
@@ -99,8 +99,8 @@ module Lolita
99
99
 
100
100
  def type_cast(type)
101
101
  if type.to_s=="Object" || type.to_s.split("::").last == "Object"
102
- "string"
103
- elsif type.to_s.match(/::/)
102
+ "string"
103
+ elsif type.to_s.match(/::/)
104
104
  type.to_s.split("::").last
105
105
  else
106
106
  type.to_s.underscore
@@ -144,7 +144,7 @@ module Lolita
144
144
 
145
145
  def search(query, options = {})
146
146
  unless query.blank?
147
- content_fields = @dbi.fields.map{|field|
147
+ content_fields = @dbi.fields.map{|field|
148
148
  if field.type!="string" || field.name.match(/^_/)
149
149
  nil
150
150
  else
@@ -155,7 +155,7 @@ module Lolita
155
155
  content_fields = content_fields & options[:fields]
156
156
  end
157
157
  content_fields = content_fields.slice(0..3)
158
-
158
+
159
159
  where_hash = {}
160
160
  content_fields.each do |field|
161
161
  where_hash[field] = /#{Regexp.escape(query.to_s)}/
@@ -168,7 +168,7 @@ module Lolita
168
168
 
169
169
  #FIXME
170
170
  def map_reduce_search(content_fields,query)
171
- keys = "[" + @dbi.fields.map{|f|
171
+ keys = "[" + @dbi.fields.map{|f|
172
172
  f.primary? || f.name.to_s.match(/^_/) ? nil : "'#{f.name}'"
173
173
  }.compact.join(",").to_s + "]"
174
174
  content_keys = "[" + content_fields.map{|f| "'#{f.name}'"}.join(",").to_s + "]"