lolita 3.1.4 → 3.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/{GUIDELINES → GUIDELINES.rdoc} +0 -0
- data/Gemfile +1 -1
- data/History.rdoc +18 -2
- data/VERSION +1 -1
- data/app/views/components/lolita/configuration/list/_paginator.html.erb +1 -5
- data/app/views/components/lolita/navigation/_tree.html.erb +23 -13
- data/lib/lolita.rb +13 -4
- data/lib/lolita/adapter/active_record.rb +4 -5
- data/lib/lolita/adapter/mongoid.rb +5 -5
- data/lib/lolita/base_configuration.rb +4 -2
- data/lib/lolita/configuration/column.rb +1 -1
- data/lib/lolita/configuration/field/array.rb +1 -1
- data/lib/lolita/controllers/internal_helpers.rb +24 -5
- data/lib/lolita/controllers/user_helpers.rb +4 -1
- data/lib/lolita/navigation/branch.rb +11 -0
- data/lib/lolita/navigation/tree.rb +4 -0
- data/lib/lolita/rails.rb +1 -0
- data/lib/lolita/rails/routes.rb +5 -0
- data/lib/lolita/support/formatter.rb +63 -0
- data/lib/lolita/support/formatter/rails.rb +8 -8
- data/lolita.gemspec +9 -13
- data/spec/controllers/internal_helpers_spec.rb +13 -0
- data/spec/dbi/base_spec.rb +10 -0
- data/spec/rails_app/app/mongoid/post.rb +1 -1
- data/spec/rails_app/config/application.rb +1 -1
- data/spec/support/{formatter/base_spec.rb → formatter_spec.rb} +3 -3
- metadata +9 -13
- data/IDEA +0 -1
- data/app/views/layouts/lolita/application.html.erb_spec.rb +0 -0
- data/lib/lolita/support/formatter/base.rb +0 -64
- data/spec/rails_app/config/initializers/load_my_cells.rb +0 -7
File without changes
|
data/Gemfile
CHANGED
@@ -2,7 +2,7 @@ source "http://rubygems.org"
|
|
2
2
|
|
3
3
|
# Thing how to seperate gems for Rails Engine from those that are only for lolita
|
4
4
|
gem "rails", "~>3.0"
|
5
|
-
gem "
|
5
|
+
gem "kaminari", "~>0.11.0"
|
6
6
|
gem "abstract"
|
7
7
|
gem "builder", "~> 2.1.2" #cucumber asks for builder 3 but rails supports 2.1
|
8
8
|
|
data/History.rdoc
CHANGED
@@ -1,10 +1,26 @@
|
|
1
|
+
=== Version 3.1.5 / 2011-04
|
2
|
+
* Changes
|
3
|
+
* Moved from WillPaginate to Kaminari (Gatis Tomsons, Arturs Meisters)
|
4
|
+
|
5
|
+
* Enhancements
|
6
|
+
* Lolita #before_setup and #after_setup hooks added (Arturs Meisters)
|
7
|
+
* Lolita #before_routes_load and #after_routes_load hooks added (Arturs Meisters)
|
8
|
+
* added Kaminari[https://github.com/amatsuda/kaminari] support to paginator (Gatis Tomsons)
|
9
|
+
|
10
|
+
* Bug fixes
|
11
|
+
* array field values lazy assigment removed (Arturs Meisters)
|
12
|
+
* tree fixed that can use mapping without InternalHelper (Arturs Meisters)
|
13
|
+
* tree now can detect if parent is active, when any of children is active (Arturs Meisters)
|
14
|
+
* order in list view works when model has default_scope (Gatis Tomsons)
|
15
|
+
* rest_controller now understands Rails date/date_time generated attributes (Gatis Tomsons)
|
16
|
+
|
1
17
|
=== Version 3.1.4 / 2011-04-19
|
2
18
|
* Enhancements
|
3
|
-
* #render_component improved, to support any class with build method as first argument (Arturs
|
19
|
+
* #render_component improved, to support any class with build method as first argument (Arturs Meisters)
|
4
20
|
* list components refactore; columns and column components created (Arturs Meisters)
|
5
21
|
* documentation for Filters (Gatis Tomsons)
|
6
22
|
* sorting configuration for columns (Arturs Meisters)
|
7
|
-
* lolita:assets generator invoke :assets for all added modules
|
23
|
+
* lolita:assets generator invoke :assets for all added modules (Arturs Meisters)
|
8
24
|
|
9
25
|
* Bug fixes
|
10
26
|
* paginator updated, to use WillPaginate only when it is accessable (Arturs Meisters)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.1.
|
1
|
+
3.1.5
|
@@ -1,22 +1,32 @@
|
|
1
|
-
|
1
|
+
<% if tree.root?
|
2
|
+
tree.each do |branch|
|
3
|
+
if branch.object.is_a?(Lolita::Mapping)
|
4
|
+
branch.options[:url]||=lolita_resources_path(branch.object)
|
5
|
+
else
|
6
|
+
branch.options[:url]=if branch.options[:url].respond_to?(:call)
|
7
|
+
branch.options[:url].call(self,branch)
|
8
|
+
else
|
9
|
+
branch.options[:url]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end %>
|
14
|
+
<ul <%=!tree.root? ? "class='subtree'" : ""%> >
|
2
15
|
<% last_branch=tree.branches.last %>
|
3
16
|
<%tree.branches.each do |branch|
|
4
17
|
if branch.object.is_a?(Lolita::Mapping)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
branch.options[:url]
|
13
|
-
end
|
14
|
-
active=branch.options[:url]==request.path
|
18
|
+
active=if self.respond_to?(:resource_class)
|
19
|
+
branch.object.to==resource_class
|
20
|
+
else
|
21
|
+
branch.options[:url]==request.path
|
22
|
+
end
|
23
|
+
else
|
24
|
+
active=branch.self_with_children.detect{|b| b.options[:url]==request.path}
|
15
25
|
end
|
16
26
|
|
17
27
|
%>
|
18
|
-
<li class="<%=active ? "active" : ""%> <%=branch.children.branches.any? ? "with-subtree" : ""%>
|
19
|
-
<%= link_to branch.title, branch.options[:url] %>
|
28
|
+
<li class="<%=active ? "active" : ""%> <%=branch.children.branches.any? ? "with-subtree" : ""%> <%=!tree.root? && branch==last_branch ? "last-in-subtree" : ""%>">
|
29
|
+
<%= link_to branch.title, branch.options[:url] || "#" %>
|
20
30
|
<% if branch.children.branches.any? %>
|
21
31
|
<%= render_component(:"lolita/navigation",:tree,:tree=>branch.children) %>
|
22
32
|
<% end %>
|
data/lib/lolita.rb
CHANGED
@@ -22,12 +22,16 @@ require 'active_support/concern'
|
|
22
22
|
require 'active_support/callbacks'
|
23
23
|
require 'active_support/dependencies'
|
24
24
|
require 'lolita/errors'
|
25
|
+
require "lolita/hooks"
|
25
26
|
# Require all ruby extensions
|
26
27
|
Dir["#{File.dirname(__FILE__)}/lolita/ruby_ext/**/*.*"].each do |path|
|
27
28
|
require path
|
28
29
|
end
|
29
30
|
|
30
31
|
module Lolita
|
32
|
+
include Lolita::Hooks
|
33
|
+
add_hook :before_setup, :after_setup, :after_routes_loaded,:before_routes_loaded
|
34
|
+
|
31
35
|
autoload(:LazyLoader,'lolita/lazy_loader')
|
32
36
|
autoload(:VERSION,'lolita/version')
|
33
37
|
autoload(:ObservedArray,'lolita/observed_array')
|
@@ -44,7 +48,6 @@ module Lolita
|
|
44
48
|
autoload :Base, 'lolita/dbi/base'
|
45
49
|
end
|
46
50
|
|
47
|
-
autoload :Hooks, "lolita/hooks"
|
48
51
|
module Hooks
|
49
52
|
autoload :NamedHook, "lolita/hooks/named_hook"
|
50
53
|
end
|
@@ -125,8 +128,8 @@ module Lolita
|
|
125
128
|
end
|
126
129
|
|
127
130
|
module Support
|
128
|
-
|
129
|
-
|
131
|
+
autoload :Formatter, 'lolita/support/formatter'
|
132
|
+
class Formatter
|
130
133
|
autoload :Rails, 'lolita/support/formatter/rails'
|
131
134
|
end
|
132
135
|
end
|
@@ -140,7 +143,9 @@ module Lolita
|
|
140
143
|
end
|
141
144
|
|
142
145
|
def self.setup
|
146
|
+
self.run(:before_setup)
|
143
147
|
yield scope
|
148
|
+
self.run(:after_setup)
|
144
149
|
end
|
145
150
|
|
146
151
|
def self.scope_name
|
@@ -159,12 +164,16 @@ module Lolita
|
|
159
164
|
scope.send(method_name,*args,&block)
|
160
165
|
end
|
161
166
|
|
167
|
+
def self.rails3?
|
168
|
+
defined?(::Rails) && ::Rails::VERSION::MAJOR == 3
|
169
|
+
end
|
170
|
+
|
162
171
|
module Generators
|
163
172
|
autoload :FileHelper, File.join(Lolita.root,"lib","generators","helpers","file_helper")
|
164
173
|
end
|
165
174
|
|
166
175
|
end
|
167
176
|
|
168
|
-
if
|
177
|
+
if Lolita.rails3?
|
169
178
|
require 'lolita/rails/all'
|
170
179
|
end
|
@@ -54,20 +54,19 @@ module Lolita
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def find_by_id(id)
|
57
|
-
self.klass.where(:id=>id).first
|
57
|
+
self.klass.unscoped.where(:id=>id).first
|
58
58
|
end
|
59
59
|
|
60
60
|
def find(*args)
|
61
|
-
self.klass.find(*args)
|
61
|
+
self.klass.unscoped.find(*args)
|
62
62
|
end
|
63
63
|
|
64
64
|
def paginate(opt={})
|
65
|
-
#FIXME depend on will_paginate
|
66
65
|
if order=opt.delete(:sort)
|
67
66
|
order=order.map{|c| c.join(" ")}.join(", ")
|
68
67
|
opt[:order]=order
|
69
68
|
end
|
70
|
-
self.klass.
|
69
|
+
self.klass.unscoped.page(opt[:page]).per(opt[:per_page]).order(opt[:order])
|
71
70
|
end
|
72
71
|
|
73
72
|
def filter(opt={})
|
@@ -89,7 +88,7 @@ module Lolita
|
|
89
88
|
end
|
90
89
|
end
|
91
90
|
unless conditions.empty?
|
92
|
-
rs = self.klass.where(conditions)
|
91
|
+
rs = self.klass.unscoped.where(conditions)
|
93
92
|
joins.each { |join| rs = rs.joins(join) }
|
94
93
|
return rs
|
95
94
|
end
|
@@ -55,15 +55,15 @@ module Lolita
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def find_by_id(id)
|
58
|
-
self.klass.where(:_id=>id).first
|
58
|
+
self.klass.unscoped.where(:_id=>id).first
|
59
59
|
end
|
60
60
|
|
61
61
|
def find *args
|
62
|
-
self.klass.find(*args)
|
62
|
+
self.klass.unscoped.find(*args)
|
63
63
|
end
|
64
64
|
|
65
|
-
def paginate(
|
66
|
-
self.klass.
|
65
|
+
def paginate(opt={})
|
66
|
+
self.klass.unscoped.order_by(opt[:sort]).page(opt[:page]).per(opt[:per_page])
|
67
67
|
end
|
68
68
|
|
69
69
|
def filter(opt={})
|
@@ -82,7 +82,7 @@ module Lolita
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
end
|
85
|
-
return self.klass.where(conditions)
|
85
|
+
return self.klass.unscoped.where(conditions)
|
86
86
|
end
|
87
87
|
self
|
88
88
|
end
|
@@ -50,7 +50,7 @@ module Lolita
|
|
50
50
|
# take first of defined #locales for Lolita, if there no defined locales for Lolita, than
|
51
51
|
# look for I18n and take default locale from there or if there is no I18n than take :en
|
52
52
|
def default_locale
|
53
|
-
@default_locale || self.locales.first || (defined?(I18n) ? I18n.default_locale : :en)
|
53
|
+
@default_locale || self.locales.first || (defined?(::I18n) ? ::I18n.default_locale : :en)
|
54
54
|
end
|
55
55
|
# Call (with #call) to route klass
|
56
56
|
# And return all names of routes that are needed for resource.
|
@@ -139,7 +139,9 @@ module Lolita
|
|
139
139
|
name=options[:name]||module_container.to_s.to_sym
|
140
140
|
self.modules<<module_container
|
141
141
|
|
142
|
-
|
142
|
+
if options.has_key?(:route)
|
143
|
+
self.routes[name]=[options.has_key?(:nested) ? options[:nested] : true,options[:route]]
|
144
|
+
end
|
143
145
|
self.controllers[name]=options[:controller] if options.has_key?(:controller)
|
144
146
|
|
145
147
|
if options[:path]
|
@@ -34,7 +34,7 @@ module Lolita
|
|
34
34
|
# Define format, for details see Lolita::Support::Formatter::Base and Lolita::Support::Formater::Rails
|
35
35
|
def formatter(value=nil,&block)
|
36
36
|
if block_given?
|
37
|
-
@formatter=Lolita::Support::Formatter
|
37
|
+
@formatter=Lolita::Support::Formatter.new(value,&block)
|
38
38
|
elsif value || !@formatter
|
39
39
|
@formatter=Lolita::Support::Formatter::Rails.new(value)
|
40
40
|
end
|
@@ -29,7 +29,7 @@ module Lolita
|
|
29
29
|
# <code>find_options</code> for advanced search. When <code>find_options</code>
|
30
30
|
# is used, than <code>conditions</code> is ignored.
|
31
31
|
def association_values() #TODO test
|
32
|
-
@association_values
|
32
|
+
@association_values=if options_for_select
|
33
33
|
options_for_select
|
34
34
|
elsif @association
|
35
35
|
klass=@dbi.association_class_name(@association).camelize.constantize
|
@@ -43,11 +43,10 @@ module Lolita
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def resource_attributes
|
46
|
-
params[resource_name] || {}
|
46
|
+
fix_attributes(params[resource_name] || {})
|
47
47
|
end
|
48
48
|
|
49
49
|
def resource_with_attributes(current_resource,attributes={})
|
50
|
-
#TODO: detect rails date_select and datetime_select special attributes
|
51
50
|
attributes||=resource_attributes
|
52
51
|
attributes.each{|key,value|
|
53
52
|
current_resource.send(:"#{key}=",value)
|
@@ -78,12 +77,32 @@ module Lolita
|
|
78
77
|
|
79
78
|
private
|
80
79
|
|
80
|
+
def fix_attributes attributes
|
81
|
+
fix_rails_date_attributes attributes
|
82
|
+
end
|
83
|
+
|
84
|
+
def fix_rails_date_attributes attributes
|
85
|
+
#{"created_at(1i)"=>"2011", "created_at(2i)"=>"4", "created_at(3i)"=>"19", "created_at(4i)"=>"16", "created_at(5i)"=>"14"}
|
86
|
+
date_attributes = {}
|
87
|
+
attributes.each_pair do |k,v|
|
88
|
+
if k.to_s =~ /(.+)\((\d)i\)$/
|
89
|
+
date_attributes[$1] = {} unless date_attributes[$1]
|
90
|
+
date_attributes[$1][$2.to_i] = v.to_i
|
91
|
+
attributes.delete(k)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
date_attributes.each_pair do |k,v|
|
95
|
+
attributes[k] = v.size == 3 ? Date.new(v[1],v[2],v[3]) : Time.new(v[1],v[2],v[3],v[4],v[5])
|
96
|
+
end
|
97
|
+
attributes
|
98
|
+
end
|
99
|
+
|
81
100
|
def switch_locale
|
82
|
-
old_locale
|
101
|
+
old_locale=::I18n.locale
|
83
102
|
Lolita.locale=params[:locale]
|
84
|
-
I18n.locale=Lolita.locale
|
103
|
+
::I18n.locale=Lolita.locale
|
85
104
|
yield
|
86
|
-
I18n.locale=old_locale
|
105
|
+
::I18n.locale=old_locale
|
87
106
|
end
|
88
107
|
end
|
89
108
|
end
|
@@ -7,7 +7,10 @@ module Lolita
|
|
7
7
|
# or return True when no authentication is defined.
|
8
8
|
module UserHelpers
|
9
9
|
extend ActiveSupport::Concern
|
10
|
-
|
10
|
+
included do
|
11
|
+
helper LolitaHelper
|
12
|
+
end
|
13
|
+
|
11
14
|
private
|
12
15
|
# FIXME what to do when block or method return false, and do not redirect
|
13
16
|
# need some redirect, but how to detect it?
|
@@ -27,6 +27,17 @@ module Lolita
|
|
27
27
|
@children
|
28
28
|
end
|
29
29
|
|
30
|
+
def self_with_children
|
31
|
+
if block_given?
|
32
|
+
yield self
|
33
|
+
@children.each do |branch|
|
34
|
+
yield branch
|
35
|
+
end
|
36
|
+
else
|
37
|
+
[self]+@children.map{|b| b}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
30
41
|
def index
|
31
42
|
self.tree.get_branch_index(self)
|
32
43
|
end
|
data/lib/lolita/rails.rb
CHANGED
data/lib/lolita/rails/routes.rb
CHANGED
@@ -2,12 +2,17 @@ module ActionDispatch::Routing
|
|
2
2
|
|
3
3
|
class RouteSet
|
4
4
|
|
5
|
+
# Each time when #draw method is called this is called as well.
|
6
|
+
# It creates :left_side_navigation tree and call callbacks
|
7
|
+
# Lolita#before_routes_loaded and Lolita#after_routes_loaded
|
5
8
|
def draw_with_lolita *args,&block
|
6
9
|
unless Lolita::Navigation::Tree[:"left_side_navigation"]
|
7
10
|
tree=Lolita::Navigation::Tree.new(:"left_side_navigation")
|
8
11
|
Lolita::Navigation::Tree.remember(tree)
|
9
12
|
end
|
13
|
+
Lolita.run(:before_routes_loaded)
|
10
14
|
draw_without_lolita *args,&block
|
15
|
+
Lolita.run(:after_routes_loaded)
|
11
16
|
end
|
12
17
|
|
13
18
|
alias_method_chain :draw, :lolita
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Lolita
|
2
|
+
module Support
|
3
|
+
# Containes different kind of formaters.
|
4
|
+
# Change output format of different input types.
|
5
|
+
# To define, pass block, or String.
|
6
|
+
# ====Exmaple
|
7
|
+
# Lolita::Support::Formatter.new do |value|
|
8
|
+
# value.to_i**2
|
9
|
+
# end
|
10
|
+
# # or as String
|
11
|
+
# Lolita::Support::Formatter.new("%Y-%m")
|
12
|
+
# To format any value with defined formater call #with
|
13
|
+
# ====Example
|
14
|
+
# # Previous examples may be called like this
|
15
|
+
# formatter.with(1)
|
16
|
+
# formatter.with(Date.today)
|
17
|
+
class Formatter
|
18
|
+
|
19
|
+
def initialize(format=nil,&block)
|
20
|
+
@format=format
|
21
|
+
@block=block if block_given?
|
22
|
+
end
|
23
|
+
|
24
|
+
def format
|
25
|
+
@format
|
26
|
+
end
|
27
|
+
|
28
|
+
def block
|
29
|
+
@block
|
30
|
+
end
|
31
|
+
|
32
|
+
def with(value,*optional_values)
|
33
|
+
if @block
|
34
|
+
@block.call(value,*optional_values)
|
35
|
+
elsif @format
|
36
|
+
use_format_for(value,*optional_values)
|
37
|
+
else
|
38
|
+
use_default_format(value,*optional_values)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def use_default_format(value,*optional_values)
|
45
|
+
value
|
46
|
+
end
|
47
|
+
|
48
|
+
def use_format_for(value, *optional_values)
|
49
|
+
if value.respond_to?(:format)
|
50
|
+
call_block(value,*optional_values)
|
51
|
+
else
|
52
|
+
value.to_s.unpack(@format)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def call_block(value,*optional_values)
|
57
|
+
value.send(:format,value,*optional_values)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module Lolita
|
2
2
|
module Support
|
3
|
-
|
3
|
+
class Formatter
|
4
4
|
|
5
5
|
# Formater for work with rails, it localize Date and Time.
|
6
6
|
# Also
|
7
|
-
class Rails < Lolita::Support::Formatter
|
7
|
+
class Rails < Lolita::Support::Formatter
|
8
8
|
|
9
9
|
|
10
10
|
private
|
@@ -18,8 +18,8 @@ module Lolita
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def localize_time_with_format(value,*optional_values)
|
21
|
-
if defined?(I18n)
|
22
|
-
I18n.localize(value, :format => @format)
|
21
|
+
if defined?(::I18n)
|
22
|
+
::I18n.localize(value, :format => @format)
|
23
23
|
else
|
24
24
|
use_default_format(value,*optional_values)
|
25
25
|
end
|
@@ -32,14 +32,14 @@ module Lolita
|
|
32
32
|
elsif value.is_a?(Numeric)
|
33
33
|
value
|
34
34
|
elsif value.is_a?(Date)
|
35
|
-
if defined?(I18n)
|
36
|
-
I18n.localize(value, :format => :long)
|
35
|
+
if defined?(::I18n)
|
36
|
+
::I18n.localize(value, :format => :long)
|
37
37
|
else
|
38
38
|
value.strftime("%Y/%m%/%d")
|
39
39
|
end
|
40
40
|
elsif value.is_a?(Time)
|
41
|
-
if defined?(I18n)
|
42
|
-
I18n.localize(value, :format => :long)
|
41
|
+
if defined?(::I18n)
|
42
|
+
::I18n.localize(value, :format => :long)
|
43
43
|
else
|
44
44
|
value.strftime("%Y/%m/%d %H:%M:%S")
|
45
45
|
end
|
data/lolita.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{lolita}
|
8
|
-
s.version = "3.1.
|
8
|
+
s.version = "3.1.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["ITHouse (Latvia) and Arturs Meisters"]
|
12
|
-
s.date = %q{2011-04-
|
12
|
+
s.date = %q{2011-04-20}
|
13
13
|
s.description = %q{Great Rails CMS, that turns your business logic into good-looking, fully functional workspace. }
|
14
14
|
s.email = %q{support@ithouse.lv}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -19,10 +19,9 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
21
|
".rspec",
|
22
|
-
"GUIDELINES",
|
22
|
+
"GUIDELINES.rdoc",
|
23
23
|
"Gemfile",
|
24
24
|
"History.rdoc",
|
25
|
-
"IDEA",
|
26
25
|
"LICENSE.txt",
|
27
26
|
"README.rdoc",
|
28
27
|
"Rakefile",
|
@@ -79,7 +78,6 @@ Gem::Specification.new do |s|
|
|
79
78
|
"app/views/components/lolita/shared/_header.html.erb",
|
80
79
|
"app/views/components/lolita/shared/_right_sidebar.html.erb",
|
81
80
|
"app/views/layouts/lolita/application.html.erb",
|
82
|
-
"app/views/layouts/lolita/application.html.erb_spec.rb",
|
83
81
|
"app/views/lolita/rest/form.html.erb",
|
84
82
|
"app/views/lolita/rest/index.html.erb",
|
85
83
|
"author",
|
@@ -142,7 +140,7 @@ Gem::Specification.new do |s|
|
|
142
140
|
"lib/lolita/rails/all.rb",
|
143
141
|
"lib/lolita/rails/routes.rb",
|
144
142
|
"lib/lolita/ruby_ext/accessors.rb",
|
145
|
-
"lib/lolita/support/formatter
|
143
|
+
"lib/lolita/support/formatter.rb",
|
146
144
|
"lib/lolita/support/formatter/rails.rb",
|
147
145
|
"lib/lolita/test/matchers.rb",
|
148
146
|
"lolita.gemspec",
|
@@ -245,7 +243,6 @@ Gem::Specification.new do |s|
|
|
245
243
|
"spec/rails_app/config/environments/test.rb",
|
246
244
|
"spec/rails_app/config/initializers/backtrace_silencers.rb",
|
247
245
|
"spec/rails_app/config/initializers/inflections.rb",
|
248
|
-
"spec/rails_app/config/initializers/load_my_cells.rb",
|
249
246
|
"spec/rails_app/config/initializers/secret_token.rb",
|
250
247
|
"spec/rails_app/config/routes.rb",
|
251
248
|
"spec/rails_app/db/schema.rb",
|
@@ -314,7 +311,7 @@ Gem::Specification.new do |s|
|
|
314
311
|
"spec/support/factories/category.rb",
|
315
312
|
"spec/support/factories/post.rb",
|
316
313
|
"spec/support/factories/tag.rb",
|
317
|
-
"spec/support/
|
314
|
+
"spec/support/formatter_spec.rb"
|
318
315
|
]
|
319
316
|
s.homepage = %q{http://github.com/ithouse/lolita}
|
320
317
|
s.licenses = ["MIT"]
|
@@ -362,7 +359,6 @@ Gem::Specification.new do |s|
|
|
362
359
|
"spec/rails_app/config/environments/test.rb",
|
363
360
|
"spec/rails_app/config/initializers/backtrace_silencers.rb",
|
364
361
|
"spec/rails_app/config/initializers/inflections.rb",
|
365
|
-
"spec/rails_app/config/initializers/load_my_cells.rb",
|
366
362
|
"spec/rails_app/config/initializers/secret_token.rb",
|
367
363
|
"spec/rails_app/config/routes.rb",
|
368
364
|
"spec/rails_app/db/schema.rb",
|
@@ -373,7 +369,7 @@ Gem::Specification.new do |s|
|
|
373
369
|
"spec/support/factories/category.rb",
|
374
370
|
"spec/support/factories/post.rb",
|
375
371
|
"spec/support/factories/tag.rb",
|
376
|
-
"spec/support/
|
372
|
+
"spec/support/formatter_spec.rb"
|
377
373
|
]
|
378
374
|
|
379
375
|
if s.respond_to? :specification_version then
|
@@ -381,7 +377,7 @@ Gem::Specification.new do |s|
|
|
381
377
|
|
382
378
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
383
379
|
s.add_runtime_dependency(%q<rails>, ["~> 3.0"])
|
384
|
-
s.add_runtime_dependency(%q<
|
380
|
+
s.add_runtime_dependency(%q<kaminari>, ["~> 0.11.0"])
|
385
381
|
s.add_runtime_dependency(%q<abstract>, [">= 0"])
|
386
382
|
s.add_runtime_dependency(%q<builder>, ["~> 2.1.2"])
|
387
383
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
@@ -396,7 +392,7 @@ Gem::Specification.new do |s|
|
|
396
392
|
s.add_development_dependency(%q<akephalos>, [">= 0"])
|
397
393
|
else
|
398
394
|
s.add_dependency(%q<rails>, ["~> 3.0"])
|
399
|
-
s.add_dependency(%q<
|
395
|
+
s.add_dependency(%q<kaminari>, ["~> 0.11.0"])
|
400
396
|
s.add_dependency(%q<abstract>, [">= 0"])
|
401
397
|
s.add_dependency(%q<builder>, ["~> 2.1.2"])
|
402
398
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
@@ -412,7 +408,7 @@ Gem::Specification.new do |s|
|
|
412
408
|
end
|
413
409
|
else
|
414
410
|
s.add_dependency(%q<rails>, ["~> 3.0"])
|
415
|
-
s.add_dependency(%q<
|
411
|
+
s.add_dependency(%q<kaminari>, ["~> 0.11.0"])
|
416
412
|
s.add_dependency(%q<abstract>, [">= 0"])
|
417
413
|
s.add_dependency(%q<builder>, ["~> 2.1.2"])
|
418
414
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
@@ -59,5 +59,18 @@ describe MyController do
|
|
59
59
|
attributes={:published_at => {}}
|
60
60
|
@controller.send(:resource_with_attributes,resource,attributes)
|
61
61
|
end
|
62
|
+
|
63
|
+
it "should fix rails date attributes" do
|
64
|
+
params = {"date_till(1i)"=>"2011", "date_till(2i)"=>"4", "date_till(3i)"=>"19", "description"=>"", "created_at(1i)"=>"2011", "created_at(2i)"=>"4", "created_at(3i)"=>"19", "created_at(4i)"=>"16", "created_at(5i)"=>"14"}
|
65
|
+
attributes = @controller.send(:fix_attributes,params)
|
66
|
+
attributes['date_till'].should == Date.new(2011,4,19)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should fix rails date_time attributes" do
|
70
|
+
params = {"created_at(1i)"=>"2011", "created_at(2i)"=>"4", "created_at(3i)"=>"19", "created_at(4i)"=>"16", "created_at(5i)"=>"14"}
|
71
|
+
attributes = @controller.send(:fix_attributes,params)
|
72
|
+
attributes['created_at'].should == Time.new(2011,4,19,16,14)
|
73
|
+
end
|
74
|
+
|
62
75
|
end
|
63
76
|
|
data/spec/dbi/base_spec.rb
CHANGED
@@ -30,5 +30,15 @@ describe Lolita::DBI::Base do
|
|
30
30
|
it "should display all adapter available" do
|
31
31
|
Lolita::DBI::Base.adapters.size.should > 0
|
32
32
|
end
|
33
|
+
|
34
|
+
it "should order with paginate" do
|
35
|
+
Post.destroy_all
|
36
|
+
Factory.create(:post, :title => "Apple")
|
37
|
+
Factory.create(:post, :title => "Banana")
|
38
|
+
Factory.create(:post, :title => "Cucumber")
|
39
|
+
dbi=Lolita::DBI::Base.new(Post)
|
40
|
+
dbi.paginate(:per_page => 3, :page => 1, :sort => [[:title,:desc]]).map(&:title).should == %w(Cucumber Banana Apple)
|
41
|
+
dbi.paginate(:per_page => 3, :page => 1, :sort => [[:title,:asc]]).map(&:title).should == %w(Apple Banana Cucumber)
|
42
|
+
end
|
33
43
|
end
|
34
44
|
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../simple_spec_helper')
|
2
2
|
|
3
|
-
describe Lolita::Support::Formatter
|
4
|
-
let(:klass){Lolita::Support::Formatter
|
3
|
+
describe Lolita::Support::Formatter do
|
4
|
+
let(:klass){Lolita::Support::Formatter}
|
5
5
|
|
6
6
|
context "create new" do
|
7
7
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: lolita
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 3.1.
|
5
|
+
version: 3.1.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- ITHouse (Latvia) and Arturs Meisters
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-04-
|
13
|
+
date: 2011-04-20 00:00:00 +03:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -25,13 +25,13 @@ dependencies:
|
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: *id001
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: kaminari
|
29
29
|
requirement: &id002 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
31
31
|
requirements:
|
32
32
|
- - ~>
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
version: 0.11.0
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: *id002
|
@@ -179,10 +179,9 @@ extra_rdoc_files:
|
|
179
179
|
files:
|
180
180
|
- .document
|
181
181
|
- .rspec
|
182
|
-
- GUIDELINES
|
182
|
+
- GUIDELINES.rdoc
|
183
183
|
- Gemfile
|
184
184
|
- History.rdoc
|
185
|
-
- IDEA
|
186
185
|
- LICENSE.txt
|
187
186
|
- README.rdoc
|
188
187
|
- Rakefile
|
@@ -239,7 +238,6 @@ files:
|
|
239
238
|
- app/views/components/lolita/shared/_header.html.erb
|
240
239
|
- app/views/components/lolita/shared/_right_sidebar.html.erb
|
241
240
|
- app/views/layouts/lolita/application.html.erb
|
242
|
-
- app/views/layouts/lolita/application.html.erb_spec.rb
|
243
241
|
- app/views/lolita/rest/form.html.erb
|
244
242
|
- app/views/lolita/rest/index.html.erb
|
245
243
|
- author
|
@@ -302,7 +300,7 @@ files:
|
|
302
300
|
- lib/lolita/rails/all.rb
|
303
301
|
- lib/lolita/rails/routes.rb
|
304
302
|
- lib/lolita/ruby_ext/accessors.rb
|
305
|
-
- lib/lolita/support/formatter
|
303
|
+
- lib/lolita/support/formatter.rb
|
306
304
|
- lib/lolita/support/formatter/rails.rb
|
307
305
|
- lib/lolita/test/matchers.rb
|
308
306
|
- lolita.gemspec
|
@@ -405,7 +403,6 @@ files:
|
|
405
403
|
- spec/rails_app/config/environments/test.rb
|
406
404
|
- spec/rails_app/config/initializers/backtrace_silencers.rb
|
407
405
|
- spec/rails_app/config/initializers/inflections.rb
|
408
|
-
- spec/rails_app/config/initializers/load_my_cells.rb
|
409
406
|
- spec/rails_app/config/initializers/secret_token.rb
|
410
407
|
- spec/rails_app/config/routes.rb
|
411
408
|
- spec/rails_app/db/schema.rb
|
@@ -474,7 +471,7 @@ files:
|
|
474
471
|
- spec/support/factories/category.rb
|
475
472
|
- spec/support/factories/post.rb
|
476
473
|
- spec/support/factories/tag.rb
|
477
|
-
- spec/support/
|
474
|
+
- spec/support/formatter_spec.rb
|
478
475
|
has_rdoc: true
|
479
476
|
homepage: http://github.com/ithouse/lolita
|
480
477
|
licenses:
|
@@ -489,7 +486,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
489
486
|
requirements:
|
490
487
|
- - ">="
|
491
488
|
- !ruby/object:Gem::Version
|
492
|
-
hash:
|
489
|
+
hash: 884824061
|
493
490
|
segments:
|
494
491
|
- 0
|
495
492
|
version: "0"
|
@@ -547,7 +544,6 @@ test_files:
|
|
547
544
|
- spec/rails_app/config/environments/test.rb
|
548
545
|
- spec/rails_app/config/initializers/backtrace_silencers.rb
|
549
546
|
- spec/rails_app/config/initializers/inflections.rb
|
550
|
-
- spec/rails_app/config/initializers/load_my_cells.rb
|
551
547
|
- spec/rails_app/config/initializers/secret_token.rb
|
552
548
|
- spec/rails_app/config/routes.rb
|
553
549
|
- spec/rails_app/db/schema.rb
|
@@ -558,4 +554,4 @@ test_files:
|
|
558
554
|
- spec/support/factories/category.rb
|
559
555
|
- spec/support/factories/post.rb
|
560
556
|
- spec/support/factories/tag.rb
|
561
|
-
- spec/support/
|
557
|
+
- spec/support/formatter_spec.rb
|
File without changes
|
@@ -1,64 +0,0 @@
|
|
1
|
-
module Lolita
|
2
|
-
module Support
|
3
|
-
# Containes different kind of formaters.
|
4
|
-
module Formatter
|
5
|
-
# Change output format of different input types.
|
6
|
-
# To define, pass block, or String.
|
7
|
-
# ====Exmaple
|
8
|
-
# Lolita::Support::Formatter.new do |value|
|
9
|
-
# value.to_i**2
|
10
|
-
# end
|
11
|
-
# # or as String
|
12
|
-
# Lolita::Support::Formatter.new("%Y-%m")
|
13
|
-
# To format any value with defined formater call #with
|
14
|
-
# ====Example
|
15
|
-
# # Previous examples may be called like this
|
16
|
-
# formatter.with(1)
|
17
|
-
# formatter.with(Date.today)
|
18
|
-
class Base
|
19
|
-
def initialize(format=nil,&block)
|
20
|
-
@format=format
|
21
|
-
@block=block if block_given?
|
22
|
-
end
|
23
|
-
|
24
|
-
def format
|
25
|
-
@format
|
26
|
-
end
|
27
|
-
|
28
|
-
def block
|
29
|
-
@block
|
30
|
-
end
|
31
|
-
|
32
|
-
def with(value,*optional_values)
|
33
|
-
if @block
|
34
|
-
@block.call(value,*optional_values)
|
35
|
-
elsif @format
|
36
|
-
use_format_for(value,*optional_values)
|
37
|
-
else
|
38
|
-
use_default_format(value,*optional_values)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def use_default_format(value,*optional_values)
|
45
|
-
value
|
46
|
-
end
|
47
|
-
|
48
|
-
def use_format_for(value, *optional_values)
|
49
|
-
if value.respond_to?(:format)
|
50
|
-
call_block(value,*optional_values)
|
51
|
-
else
|
52
|
-
value.to_s.unpack(@format)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def call_block(value,*optional_values)
|
57
|
-
value.send(:format,value,*optional_values)
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|