lolita 3.1.0 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/{GUIDELINE → GUIDELINES} +0 -0
  2. data/History.rdoc +70 -0
  3. data/LICENSE.txt +3 -1
  4. data/README.rdoc +5 -1
  5. data/Rakefile +2 -2
  6. data/VERSION +1 -1
  7. data/app/controllers/lolita/rest_controller.rb +1 -1
  8. data/app/views/components/lolita/configuration/field/array/filter/_display.html.erb +1 -0
  9. data/app/views/components/lolita/configuration/field/boolean/filter/_display.html.erb +2 -0
  10. data/app/views/components/lolita/configuration/field/date_time/_display.html.erb +1 -0
  11. data/app/views/components/lolita/configuration/field/date_time/date/_display.html.erb +1 -0
  12. data/app/views/components/lolita/configuration/field/date_time/time/_display.html.erb +1 -0
  13. data/app/views/components/lolita/configuration/field/time/_display.html.erb +1 -1
  14. data/app/views/components/lolita/configuration/list/_filter.html.erb +2 -2
  15. data/config/locales/en.yml +4 -1
  16. data/lib/lolita.rb +18 -11
  17. data/lib/lolita/adapter/abstract_adapter.rb +1 -1
  18. data/lib/lolita/adapter/active_record.rb +28 -1
  19. data/lib/lolita/adapter/mongoid.rb +25 -2
  20. data/lib/lolita/configuration/field/array.rb +1 -0
  21. data/lib/lolita/configuration/field/date.rb +1 -1
  22. data/lib/lolita/configuration/field/date_time.rb +13 -0
  23. data/lib/lolita/configuration/filter.rb +24 -0
  24. data/lib/lolita/configuration/list.rb +4 -1
  25. data/lib/lolita/configuration/page.rb +18 -2
  26. data/lib/lolita/controllers/internal_helpers.rb +1 -0
  27. data/lib/lolita/hooks.rb +22 -22
  28. data/lib/lolita/hooks/named_hook.rb +7 -3
  29. data/lib/lolita/navigation/branch.rb +7 -0
  30. data/lib/lolita/navigation/tree.rb +7 -0
  31. data/lolita.gemspec +22 -12
  32. data/public/stylesheets/lolita/style.css +16 -0
  33. data/spec/adapter_helper.rb +1 -1
  34. data/spec/configuration/filter_spec.rb +63 -1
  35. data/spec/controllers/internal_helpers_spec.rb +7 -0
  36. data/spec/controllers/lolita_rest_spec.rb +1 -0
  37. data/spec/hooks_spec.rb +16 -15
  38. data/spec/navigation/tree_spec.rb +41 -18
  39. data/spec/orm/mongoid.rb +4 -7
  40. data/spec/rails_app/app/mongoid/address.rb +1 -1
  41. data/spec/rails_app/app/mongoid/category.rb +6 -0
  42. data/spec/rails_app/app/mongoid/comment.rb +2 -2
  43. data/spec/rails_app/app/mongoid/post.rb +10 -6
  44. data/spec/rails_app/app/mongoid/preference.rb +1 -1
  45. data/spec/rails_app/app/mongoid/profile.rb +3 -3
  46. data/spec/rails_app/app/mongoid/tag.rb +4 -0
  47. data/spec/support/factories/category.rb +3 -0
  48. data/spec/support/factories/post.rb +1 -0
  49. data/spec/support/factories/tag.rb +3 -0
  50. metadata +23 -14
  51. data/.project +0 -17
  52. data/lib/lolita/navigation.rb +0 -48
  53. data/log/development.log +0 -0
  54. data/test/cells/form_cell_test.rb +0 -15
  55. data/test/test_helper.rb +0 -2
File without changes
@@ -0,0 +1,70 @@
1
+ === Version 3.1.0 / 2011-04-12
2
+ * Enhancements
3
+ * Hooks added (Arturs Meisters)
4
+ * Builders updated to complete received names (Arturs Meisters)
5
+ * Fields renamed to related Ruby or ActiveSupport classes (Gatis Tomsons)
6
+ * Componente default naming changed to match related model/class structure (Gatis Tomsons)
7
+ * No need for <em>include Lolita::Configuration</em> and #lolita call for lolita_for
8
+ related class (Arturs Meisters)
9
+ * Automatic field type detection from ORM (Arturs Meisters)
10
+ * List filter introduced (Gatis Tomsons)
11
+ * Response for JSON (Gatis Tomsons)
12
+ * Configuration has locales, and Lolita using those to seperate project translation (Arturs Meisters)
13
+ * DateTime field formation for display only (Valdis Pornieks)
14
+
15
+ * Bug fixes
16
+ * Validation errors fixed (Janis Kesteris)
17
+ * MongoID adapter fixed to work with new mongoid (Valdis Pornieks)
18
+ * AR :order option fixed for find methods (Aivils Stoss)
19
+ * AR migration error fixed (Arturs Meisters)
20
+ * Redirect after destroy to index (Valdis Pornieks)
21
+ * Route and nested route bugs fixed (Arturs Meisters)
22
+ * Multiple textareas with tinyMCE (Valdis Pornieks)
23
+ * Resource path methods fixed (Arturs Meisters)
24
+ * #url_for fixed for lolita (Arturs Meisters, Gatis Tomsons)
25
+ * Layout fixed (Rolands Bondars)
26
+
27
+ === Version 3.0.7 / 2011-03-29
28
+ * Enhancements
29
+ * Collection field updated (Arturs Meisters)
30
+ * #options_for_select added for collection field (Gatis Tomsons)
31
+
32
+ === Version 3.0.6 / 2011-03-29
33
+ * Enhancements
34
+ * TinyMCE updated with new buttons (Janis Kesteris)
35
+ * #add_module changed to support nested routes (Arturs Meisters)
36
+ * Routes support nested resources (Arturs Meisters)
37
+ * Fields splited in classes based on type (Arturs Meisters)
38
+ * #render_component accept :format option (Arturs Meisters)
39
+
40
+ * Bug fixes
41
+ * Collection field collection priority fixed (Arturs Meisters)
42
+ * JQuery Ajax request updated, to support Rails CSRF fix. (Arturs Meisters)
43
+
44
+ === Version 3.0.5 / 2011-03-23
45
+ * Enhacements
46
+ * #by_type for tabs added (Arturs Meisters)
47
+ * Test module invented and #be_routable matcher added (Arturs Meisters)
48
+ * Cucumber added for testing (Rolands Bondars)
49
+
50
+ * Bug fixes
51
+ * Small look fixes (Rolands Bondars)
52
+ * #content_for removed from tab components (Rolands Bondars)
53
+
54
+ === Version 3.0.4 / 2011-03-17
55
+ * Enhancements
56
+ * Save button added (Rolands Bondars)
57
+ * Removed unnecessery stuff from TinyMCE (Rolands Bonadars)
58
+ * :content used as default type for tabs. (Arturs Meisters)
59
+
60
+ === Version 3.0.3 / 2011-03-16
61
+ * Enhancements (Arturs Meisters)
62
+ * First version form 3.x series of Lolita
63
+ * Basic configuration classes
64
+ * Basic views
65
+ * Basic controller and views mechanism
66
+ * New look (Rolands Bondars)
67
+
68
+ === Versions before 3.0.3
69
+ Lolita 3.0 is completely different from previous versions and don't have any compability or architecture same as
70
+ old versions.
@@ -1,4 +1,6 @@
1
- Copyright (c) 2011 Arturs Meisters
1
+ The MIT License
2
+
3
+ Copyright (c) 2011 ITHouse and Arturs Meisters
2
4
 
3
5
  Permission is hereby granted, free of charge, to any person obtaining
4
6
  a copy of this software and associated documentation files (the
@@ -1,6 +1,6 @@
1
1
  =Lolita
2
2
 
3
- Content management system that works with rails.
3
+ Great Rails CMS, that turns your business logic into good-looking, fully functional workspace.
4
4
  ==Demo
5
5
  See the demo page at Demo[http://lolita-demo.ithouse.lv]
6
6
 
@@ -48,3 +48,7 @@ to all controllers.
48
48
  If you decide to use some newer version, you most likely should copy new assets to your project.
49
49
  This can be done with
50
50
  rails g lolita:assets
51
+
52
+ ==License
53
+
54
+ Lolita is under MIT license. See LICENSE.txt[https://github.com/ithouse/lolita/blob/master/LICENSE.txt]
data/Rakefile CHANGED
@@ -16,9 +16,9 @@ Jeweler::Tasks.new do |gem|
16
16
  gem.homepage = "http://github.com/ithouse/lolita"
17
17
  gem.license = "MIT"
18
18
  gem.summary = %Q{Great Rails CMS.}
19
- gem.description = %Q{Great Rails CMS that allow you to start working with models right when you add this to your project.}
19
+ gem.description = %Q{Great Rails CMS, that turns your business logic into good-looking, fully functional workspace. }
20
20
  gem.email = "support@ithouse.lv"
21
- gem.authors = ["ITHouse","Arturs Meisters"]
21
+ gem.authors = ["ITHouse (Latvia) and Arturs Meisters"]
22
22
  # Include your dependencies below. Runtime dependencies are required when using your gem,
23
23
  # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
24
  # gem.add_runtime_dependency 'jabber4r', '> 0.1'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.0
1
+ 3.1.1
@@ -88,6 +88,6 @@ class Lolita::RestController < ApplicationController
88
88
  end
89
89
 
90
90
  def page
91
- resource_class.lolita.list.paginate(params[:page])
91
+ resource_class.lolita.list.paginate(params[:page], :params => params)
92
92
  end
93
93
  end
@@ -0,0 +1 @@
1
+ <%= select_tag filter.field_name(field), options_for_select(filter.options_for_select(field), params[filter.field_name(field)]),field.html_options || filter.html_option_for_select(field) %>
@@ -0,0 +1,2 @@
1
+ <label for="<%= filter.field_name(field) %>"><%= field.title %></label>
2
+ <%= check_box_tag filter.field_name(field), 1, params[filter.field_name(field)], field.html_options || {} %>
@@ -0,0 +1 @@
1
+ <%= datetime_select resource_name, field.name %>
@@ -0,0 +1 @@
1
+ <%= date_select resource_name, field.name %>
@@ -0,0 +1 @@
1
+ <%= time_select resource_name, field.name %>
@@ -1 +1 @@
1
- <%= datetime_select resource_name, field.name %>
1
+ <%= time_select resource_name, field.name %>
@@ -1,8 +1,8 @@
1
1
  <% if list.filter? -%>
2
2
  <form action="" action="get" class="filter">
3
3
  <% list.filter.fields.each do |field| %>
4
- <%= render_component *field.build %>
4
+ <%= render_component *field.build(:filter, :filter=>list.filter) %>
5
5
  <% end %>
6
- <button type="submit">Apply</button>
6
+ <button type="submit"><%= I18n.t "lolita.filter.apply_button" %></button>
7
7
  </form>
8
8
  <% end -%>
@@ -10,4 +10,7 @@ en:
10
10
  save_all: Save all
11
11
  list:
12
12
  add_new: Add new %{name}
13
- confirm: Are you sure you want to delete record?
13
+ confirm: Are you sure you want to delete record?
14
+ filter:
15
+ apply_button: Apply
16
+ include_blank_by_title: " -- Filter by %{title} -- "
@@ -1,9 +1,23 @@
1
- main_time=Time.now
2
1
 
3
2
  $:<<File.dirname(__FILE__) unless $:.include?(File.dirname(__FILE__))
3
+ LOLITA_VERSION=File.read(File.expand_path("../../VERSION",__FILE__)).gsub(/[^.\w]/,"")
4
+ puts "=> Lolita #{LOLITA_VERSION} starting#{defined?(Rails) ? " with Rails" : ""}"
5
+
6
+ # TODO should allow run lolita seperated
7
+ unless (["-d","--debug"] & ARGV).empty?
8
+ require "ruby-debug"
9
+ Debugger.settings[:autoeval]=true
10
+ else
11
+ unless self.respond_to?(:debugger)
12
+ def debugger
13
+ warn "Debugger called at #{caller.first} was ignored, run lolita with -d to attatch debugger."
14
+ end
15
+ end
16
+ end
4
17
 
5
- require 'abstract' #FIXME remove from gem
18
+ require 'abstract'
6
19
  require 'active_support/core_ext/numeric/time'
20
+ require 'active_support/core_ext/date_time/conversions'
7
21
  require 'active_support/concern'
8
22
  require 'active_support/callbacks'
9
23
  require 'active_support/dependencies'
@@ -105,10 +119,9 @@ module Lolita
105
119
  autoload :ViewUserHelpers, 'lolita/controllers/view_user_helpers'
106
120
  end
107
121
 
108
- autoload(:Navigation,"lolita/navigation")
109
122
  module Navigation
110
- autoload :Tree, "lolita/navigation"
111
- autoload :Branch, "lolita/navigation"
123
+ autoload :Tree, "lolita/navigation/tree"
124
+ autoload :Branch, "lolita/navigation/branch"
112
125
  end
113
126
 
114
127
  @@scopes={}
@@ -145,12 +158,6 @@ module Lolita
145
158
 
146
159
  end
147
160
 
148
- engine_time=Time.now
149
-
150
161
  if defined?(Rails)
151
162
  require 'lolita/rails/all'
152
163
  end
153
-
154
- puts "Lolita engine started in #{Time.at(Time.now-engine_time).strftime("%M:%S.%3N")}"
155
-
156
- puts "Lolita started in #{Time.at(Time.now-main_time).strftime("%M:%S.%3N")}"
@@ -4,7 +4,7 @@ module Lolita
4
4
 
5
5
  abstract_method '',:fields,:db, :db_name,:collection,:collection_name,:collections,:collection_names
6
6
  abstract_method '',:associations,:associations_class_names
7
- abstract_method 'opt={}',:paginate
7
+ abstract_method 'opt={}',:paginate, :filter
8
8
  abstract_method 'name',:reflect_on_association
9
9
  abstract_method 'association',:association_macro,:association_class_name
10
10
  abstract_method 'id',:find_by_id
@@ -70,6 +70,33 @@ module Lolita
70
70
  self.klass.paginate(opt)
71
71
  end
72
72
 
73
+ def filter(opt={})
74
+ conditions = {}
75
+ joins = []
76
+ unless opt.empty?
77
+ opt.each_pair do |k,v|
78
+ field = klass.columns.detect{|f| f.name == k.to_s}
79
+ if field
80
+ conditions[k] = v
81
+ elsif association = associations[k.to_sym]
82
+ case association_macro(association)
83
+ when :many
84
+ conditions[association.name] = {:id => v}
85
+ joins << association.name
86
+ when :one
87
+ conditions[association.primary_key_name] = v
88
+ end
89
+ end
90
+ end
91
+ unless conditions.empty?
92
+ rs = self.klass.where(conditions)
93
+ joins.each { |join| rs = rs.joins(join) }
94
+ return rs
95
+ end
96
+ end
97
+ self
98
+ end
99
+
73
100
  def db
74
101
  self.klass.connection
75
102
  end
@@ -112,7 +139,7 @@ module Lolita
112
139
  def type_cast name
113
140
  types = {
114
141
  'decimal' => 'big_decimal',
115
- 'datetime' => 'time',
142
+ 'datetime' => 'date_time',
116
143
  'text' => 'string'
117
144
  }
118
145
  types[name.to_s] || name
@@ -30,14 +30,16 @@ module Lolita
30
30
  case macro
31
31
  when :references_many
32
32
  :many
33
+ when :references_and_referenced_in_many
34
+ :many
33
35
  when :referenced_in
34
36
  :one
37
+ when :references_one
38
+ :one
35
39
  when :embeds_one
36
40
  :one
37
41
  when :embeds_many
38
42
  :many
39
- when :references_one
40
- :one
41
43
  end
42
44
  end
43
45
 
@@ -64,6 +66,27 @@ module Lolita
64
66
  self.klass.paginate(options)
65
67
  end
66
68
 
69
+ def filter(opt={})
70
+ conditions = {}
71
+ unless opt.empty?
72
+ opt.each_pair do |k,v|
73
+ field = klass.fields.detect{|name,f| name == k.to_s}
74
+ if field
75
+ conditions[k] = v
76
+ elsif association = associations[k.to_s]
77
+ case association_macro(association)
78
+ when :many
79
+ conditions[:"#{klass.reflect_on_association(k).key}".in] = [v]
80
+ when :one
81
+ conditions[klass.reflect_on_association(k).foreign_key] = v
82
+ end
83
+ end
84
+ end
85
+ return self.klass.where(conditions)
86
+ end
87
+ self
88
+ end
89
+
67
90
  def db
68
91
  self.klass.db
69
92
  end
@@ -1,6 +1,7 @@
1
1
  module Lolita
2
2
  module Configuration
3
3
  module Field
4
+
4
5
  class Array < Lolita::Configuration::Field::Base
5
6
  lolita_accessor :conditions,:text_method,:value_method,:find_options,:association_type,:include_blank
6
7
 
@@ -1,7 +1,7 @@
1
1
  module Lolita
2
2
  module Configuration
3
3
  module Field
4
- class Datetime < Lolita::Configuration::Field::Base
4
+ class Date < Lolita::Configuration::Field::Base
5
5
  attr_accessor :format
6
6
  def initialize *args
7
7
  @type="date"
@@ -0,0 +1,13 @@
1
+ module Lolita
2
+ module Configuration
3
+ module Field
4
+ class DateTime < Lolita::Configuration::Field::Base
5
+ attr_accessor :format
6
+ def initialize *args
7
+ @type="date_time"
8
+ super
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  module Lolita
2
3
  module Configuration
3
4
  class Filter
@@ -13,6 +14,7 @@ module Lolita
13
14
 
14
15
  def field *args, &block
15
16
  field=Lolita::Configuration::Field.add(self.dbi,*args,&block)
17
+ field
16
18
  @fields<<field
17
19
  field
18
20
  end
@@ -58,6 +60,28 @@ module Lolita
58
60
  end
59
61
  end
60
62
 
63
+ def field_name field
64
+ #'f_'+('a'..'z').to_a[self.fields.index(field)]
65
+ "f_#{field.name}"
66
+ end
67
+
68
+ def options_for_select field
69
+ if field.options_for_select
70
+ field.options_for_select
71
+ else
72
+ if field.association_values.respond_to?(:call)
73
+ field.association_values.call(self)
74
+ else
75
+ field.association_values
76
+ end
77
+ end
78
+ end
79
+
80
+ def html_option_for_select field
81
+ {
82
+ :include_blank => I18n.t('lolita.filter.include_blank_by_title', :title => field.title)
83
+ }
84
+ end
61
85
  end
62
86
  end
63
87
  end
@@ -57,7 +57,10 @@ module Lolita
57
57
  @filter.is_a?(Lolita::Configuration::Filter)
58
58
  end
59
59
 
60
- # Adds filter
60
+ # Filter by now works only for these field types:
61
+ # - belongs_to
62
+ # - boolean
63
+ #
61
64
  def filter(*args,&block)
62
65
  @filter ||= Lolita::Configuration::Filter.new(self.dbi,*args,&block)
63
66
  end
@@ -58,18 +58,19 @@ module Lolita
58
58
  def paginate *args
59
59
  options=args ? args.extract_options! : {}
60
60
  hold=options.delete(:hold)
61
+ @params=options.delete(:params)
61
62
  set_values_from_options(options)
62
63
  options[:page]||=((args && args.first) || 1)
63
64
  options[:per_page]||=@per_page || 10
64
65
  @last_options=options
65
- @last_options[:sort]=self.sort_columns.empty? ? nil : self.sort_columns
66
+ @last_options[:sort]=self.sort_columns unless self.sort_columns.empty?
66
67
  unless hold
67
68
  get_page()
68
69
  end
69
70
  end
70
71
 
71
72
  def get_page()
72
- @page=@dbi.paginate((@page_options||{}).merge(@last_options))
73
+ @page=@dbi.filter(filter_conditions).paginate((@page_options||{}).merge(@last_options))
73
74
  end
74
75
 
75
76
  # Return last paginated page
@@ -83,6 +84,21 @@ module Lolita
83
84
 
84
85
  private
85
86
 
87
+ # returns filter conditions as Hash for get_page()
88
+ def filter_conditions
89
+ if @params
90
+ conditions = {}
91
+ @params.each_pair do |k,v|
92
+ if k.to_s =~ /^f_([a-z0-9_\-]+)$/ && !v.to_s.strip.blank?
93
+ conditions[$1.to_sym] = v
94
+ end
95
+ end
96
+ conditions
97
+ else
98
+ {}
99
+ end
100
+ end
101
+
86
102
  def allowed_options
87
103
  [:sort_columns,:asc,:desc]
88
104
  end