e9_rails 0.0.11 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/e9_rails/active_record/attribute_searchable.rb +1 -0
- data/lib/e9_rails/active_record/scopes/times.rb +45 -0
- data/lib/e9_rails/controllers/orderable.rb +11 -4
- data/lib/e9_rails/helpers/resource_links.rb +14 -6
- data/lib/e9_rails/locale/en.yml +9 -0
- data/lib/e9_rails/version.rb +1 -1
- data/lib/e9_rails.rb +11 -0
- metadata +4 -2
@@ -0,0 +1,45 @@
|
|
1
|
+
module E9Rails::ActiveRecord
|
2
|
+
module Scopes
|
3
|
+
module Times
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
scope :from_time, lambda {|*args| args.flatten!; for_time_range(args.shift, nil, args.extract_options!) }
|
8
|
+
scope :until_time, lambda {|*args| args.flatten!; for_time_range(nil, args.shift, args.extract_options!) }
|
9
|
+
|
10
|
+
scope :for_time_range, lambda {|*args|
|
11
|
+
opts = args.extract_options!
|
12
|
+
|
13
|
+
args.flatten!
|
14
|
+
|
15
|
+
# try to determine a datetime from each arg, skipping #to_time on passed strings because
|
16
|
+
# it doesn't handle everything DateTime.parse can, e.g. 'yyyy/mm'
|
17
|
+
args.map! do |t|
|
18
|
+
t.presence and
|
19
|
+
|
20
|
+
# handle string years 2010, etc.
|
21
|
+
t.is_a?(String) && /^\d{4}$/.match(t) && Date.civil(t.to_i) ||
|
22
|
+
|
23
|
+
# handle Time etc. (String#to_time doesn't handle yyyy/mm properly)
|
24
|
+
!t.is_a?(String) && t.respond_to?(:to_time) && t.to_time ||
|
25
|
+
|
26
|
+
# try to parse it
|
27
|
+
DateTime.parse(t) rescue nil
|
28
|
+
end
|
29
|
+
|
30
|
+
time_column = opts[:column] || :created_at
|
31
|
+
|
32
|
+
if !args.any?
|
33
|
+
where('1=0')
|
34
|
+
elsif args.all?
|
35
|
+
where(time_column => args[0]..args[1])
|
36
|
+
elsif args[0]
|
37
|
+
where(arel_table[time_column].gteq(args[0]))
|
38
|
+
else
|
39
|
+
where(arel_table[time_column].lteq(args[1]))
|
40
|
+
end
|
41
|
+
}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -12,6 +12,8 @@ module E9Rails::Controllers
|
|
12
12
|
helper_method :default_ordered_dir
|
13
13
|
|
14
14
|
has_scope :order, :if => :ordered_if, :default => lambda {|c| c.send(:default_ordered_on) } do |controller, scope, columns|
|
15
|
+
resource_class = controller.send(:resource_class)
|
16
|
+
|
15
17
|
begin
|
16
18
|
# determine the dir from params or controller default
|
17
19
|
dir = case controller.params[:sort]
|
@@ -26,7 +28,7 @@ module E9Rails::Controllers
|
|
26
28
|
|
27
29
|
columns = columns.map {|v|
|
28
30
|
# if column split on '.', try to constantize the parsed class
|
29
|
-
if v.length > 1
|
31
|
+
if v.length > 1 && v.last =~ /\w+/
|
30
32
|
klass = v.first.classify.constantize rescue nil
|
31
33
|
|
32
34
|
# and if it succeeds
|
@@ -38,9 +40,14 @@ module E9Rails::Controllers
|
|
38
40
|
scope = scope.includes(v.first.underscore.to_sym)
|
39
41
|
"#{klass.table_name}.#{v.last} #{dir}"
|
40
42
|
end
|
41
|
-
|
42
|
-
|
43
|
-
|
43
|
+
elsif v.last =~ /\w+/
|
44
|
+
sql = ''
|
45
|
+
|
46
|
+
if resource_class.column_names.member?(v.last)
|
47
|
+
sql << "#{resource_class.table_name}."
|
48
|
+
end
|
49
|
+
|
50
|
+
sql << "#{v.last} #{dir}"
|
44
51
|
end
|
45
52
|
}.compact.join(', ')
|
46
53
|
|
@@ -18,16 +18,20 @@ module E9Rails::Helpers
|
|
18
18
|
|
19
19
|
path_options = options.slice!(:scope, :action, :method, :remote, :confirm, :class)
|
20
20
|
|
21
|
-
klass
|
21
|
+
klass = resource.is_a?(Class) ? resource : resource.class
|
22
22
|
|
23
|
-
action
|
24
|
-
|
23
|
+
action = (options.delete(:action) || :show).to_sym
|
24
|
+
|
25
|
+
if klass == resource && ![:index, :new].member?(action)
|
26
|
+
action = :index
|
27
|
+
end
|
25
28
|
|
26
29
|
scopes = [*(options[:scope] || @route_scope), parent].compact
|
27
30
|
path = case action
|
28
|
-
when :new;
|
29
|
-
when :edit;
|
30
|
-
|
31
|
+
when :new; new_polymorphic_path(scopes << klass, path_options)
|
32
|
+
when :edit; edit_polymorphic_path(scopes << resource, path_options)
|
33
|
+
when :index; polymorphic_path(scopes << klass, path_options)
|
34
|
+
else polymorphic_path(scopes << resource, path_options)
|
31
35
|
end
|
32
36
|
|
33
37
|
mn = klass.model_name
|
@@ -79,6 +83,10 @@ module E9Rails::Helpers
|
|
79
83
|
def link_to_destroy_resource(resource, options = {})
|
80
84
|
link_to_resource(resource, options.merge(:action => :destroy))
|
81
85
|
end
|
86
|
+
|
87
|
+
def link_to_collection(resource, options = {})
|
88
|
+
link_to_resource(resource, options.merge(:action => :index))
|
89
|
+
end
|
82
90
|
end
|
83
91
|
end
|
84
92
|
end
|
data/lib/e9_rails/version.rb
CHANGED
data/lib/e9_rails.rb
CHANGED
@@ -8,6 +8,10 @@ module E9Rails
|
|
8
8
|
autoload :InheritableOptions, 'e9_rails/active_record/inheritable_options'
|
9
9
|
autoload :Initialization, 'e9_rails/active_record/initialization'
|
10
10
|
autoload :STI, 'e9_rails/active_record/sti'
|
11
|
+
|
12
|
+
module Scopes
|
13
|
+
autoload :Times, 'e9_rails/active_record/scopes/times'
|
14
|
+
end
|
11
15
|
end
|
12
16
|
|
13
17
|
module Controllers
|
@@ -22,4 +26,11 @@ module E9Rails
|
|
22
26
|
autoload :Title, 'e9_rails/helpers/title'
|
23
27
|
autoload :Translation, 'e9_rails/helpers/translation'
|
24
28
|
end
|
29
|
+
|
30
|
+
class Railtie < Rails::Railtie
|
31
|
+
initializer 'e9_rails.append_i18n_translations' do
|
32
|
+
require 'active_support/i18n'
|
33
|
+
I18n.load_path << File.join(File.dirname(__FILE__), 'e9_rails/locale/en.yml')
|
34
|
+
end
|
35
|
+
end
|
25
36
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: e9_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.13
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Travis Cox
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-16 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- lib/e9_rails/active_record/attribute_searchable.rb
|
55
55
|
- lib/e9_rails/active_record/inheritable_options.rb
|
56
56
|
- lib/e9_rails/active_record/initialization.rb
|
57
|
+
- lib/e9_rails/active_record/scopes/times.rb
|
57
58
|
- lib/e9_rails/active_record/sti.rb
|
58
59
|
- lib/e9_rails/controllers/orderable.rb
|
59
60
|
- lib/e9_rails/controllers/sortable.rb
|
@@ -62,6 +63,7 @@ files:
|
|
62
63
|
- lib/e9_rails/helpers/resource_links.rb
|
63
64
|
- lib/e9_rails/helpers/title.rb
|
64
65
|
- lib/e9_rails/helpers/translation.rb
|
66
|
+
- lib/e9_rails/locale/en.yml
|
65
67
|
- lib/e9_rails/version.rb
|
66
68
|
has_rdoc: true
|
67
69
|
homepage: http://www.e9digital.com
|