##// END OF EJS Templates
remove Rails2 named_scope wrapper from config/initializers/10-patches.rb...
Toshi MARUYAMA -
r9357:6f8d7d6e768a
parent child
Show More
@@ -1,94 +1,90
1 require 'active_record'
1 require 'active_record'
2
2
3 module ActiveRecord
3 module ActiveRecord
4 class Base
4 class Base
5 include Redmine::I18n
5 include Redmine::I18n
6 def self.named_scope(*args)
7 scope(*args)
8 end
9
10 # Translate attribute names for validation errors display
6 # Translate attribute names for validation errors display
11 def self.human_attribute_name(attr, *args)
7 def self.human_attribute_name(attr, *args)
12 l("field_#{attr.to_s.gsub(/_id$/, '')}", :default => attr)
8 l("field_#{attr.to_s.gsub(/_id$/, '')}", :default => attr)
13 end
9 end
14 end
10 end
15 end
11 end
16
12
17 module ActionView
13 module ActionView
18 module Helpers
14 module Helpers
19 module DateHelper
15 module DateHelper
20 # distance_of_time_in_words breaks when difference is greater than 30 years
16 # distance_of_time_in_words breaks when difference is greater than 30 years
21 def distance_of_date_in_words(from_date, to_date = 0, options = {})
17 def distance_of_date_in_words(from_date, to_date = 0, options = {})
22 from_date = from_date.to_date if from_date.respond_to?(:to_date)
18 from_date = from_date.to_date if from_date.respond_to?(:to_date)
23 to_date = to_date.to_date if to_date.respond_to?(:to_date)
19 to_date = to_date.to_date if to_date.respond_to?(:to_date)
24 distance_in_days = (to_date - from_date).abs
20 distance_in_days = (to_date - from_date).abs
25
21
26 I18n.with_options :locale => options[:locale], :scope => :'datetime.distance_in_words' do |locale|
22 I18n.with_options :locale => options[:locale], :scope => :'datetime.distance_in_words' do |locale|
27 case distance_in_days
23 case distance_in_days
28 when 0..60 then locale.t :x_days, :count => distance_in_days.round
24 when 0..60 then locale.t :x_days, :count => distance_in_days.round
29 when 61..720 then locale.t :about_x_months, :count => (distance_in_days / 30).round
25 when 61..720 then locale.t :about_x_months, :count => (distance_in_days / 30).round
30 else locale.t :over_x_years, :count => (distance_in_days / 365).floor
26 else locale.t :over_x_years, :count => (distance_in_days / 365).floor
31 end
27 end
32 end
28 end
33 end
29 end
34 end
30 end
35 end
31 end
36
32
37 class Resolver
33 class Resolver
38 def find_all(name, prefix=nil, partial=false, details={}, key=nil, locals=[])
34 def find_all(name, prefix=nil, partial=false, details={}, key=nil, locals=[])
39 cached(key, [name, prefix, partial], details, locals) do
35 cached(key, [name, prefix, partial], details, locals) do
40 if details[:formats] & [:xml, :json]
36 if details[:formats] & [:xml, :json]
41 details = details.dup
37 details = details.dup
42 details[:formats] = details[:formats].dup + [:api]
38 details[:formats] = details[:formats].dup + [:api]
43 end
39 end
44 find_templates(name, prefix, partial, details)
40 find_templates(name, prefix, partial, details)
45 end
41 end
46 end
42 end
47 end
43 end
48 end
44 end
49
45
50 ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| "#{html_tag}" }
46 ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| "#{html_tag}" }
51
47
52 require 'mail'
48 require 'mail'
53
49
54 module DeliveryMethods
50 module DeliveryMethods
55 class AsyncSMTP < ::Mail::SMTP
51 class AsyncSMTP < ::Mail::SMTP
56 def deliver!(*args)
52 def deliver!(*args)
57 Thread.start do
53 Thread.start do
58 super *args
54 super *args
59 end
55 end
60 end
56 end
61 end
57 end
62
58
63 class AsyncSendmail < ::Mail::Sendmail
59 class AsyncSendmail < ::Mail::Sendmail
64 def deliver!(*args)
60 def deliver!(*args)
65 Thread.start do
61 Thread.start do
66 super *args
62 super *args
67 end
63 end
68 end
64 end
69 end
65 end
70
66
71 class TmpFile
67 class TmpFile
72 def initialize(*args); end
68 def initialize(*args); end
73
69
74 def deliver!(mail)
70 def deliver!(mail)
75 dest_dir = File.join(Rails.root, 'tmp', 'emails')
71 dest_dir = File.join(Rails.root, 'tmp', 'emails')
76 Dir.mkdir(dest_dir) unless File.directory?(dest_dir)
72 Dir.mkdir(dest_dir) unless File.directory?(dest_dir)
77 File.open(File.join(dest_dir, mail.message_id.gsub(/[<>]/, '') + '.eml'), 'wb') {|f| f.write(mail.encoded) }
73 File.open(File.join(dest_dir, mail.message_id.gsub(/[<>]/, '') + '.eml'), 'wb') {|f| f.write(mail.encoded) }
78 end
74 end
79 end
75 end
80 end
76 end
81
77
82 ActionMailer::Base.add_delivery_method :async_smtp, DeliveryMethods::AsyncSMTP
78 ActionMailer::Base.add_delivery_method :async_smtp, DeliveryMethods::AsyncSMTP
83 ActionMailer::Base.add_delivery_method :async_sendmail, DeliveryMethods::AsyncSendmail
79 ActionMailer::Base.add_delivery_method :async_sendmail, DeliveryMethods::AsyncSendmail
84 ActionMailer::Base.add_delivery_method :tmp_file, DeliveryMethods::TmpFile
80 ActionMailer::Base.add_delivery_method :tmp_file, DeliveryMethods::TmpFile
85
81
86 module ActionController
82 module ActionController
87 module MimeResponds
83 module MimeResponds
88 class Collector
84 class Collector
89 def api(&block)
85 def api(&block)
90 any(:xml, :json, &block)
86 any(:xml, :json, &block)
91 end
87 end
92 end
88 end
93 end
89 end
94 end
90 end
General Comments 0
You need to be logged in to leave comments. Login now