@@ -1,103 +1,103 | |||||
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 | # Translate attribute names for validation errors display |
|
6 | # Translate attribute names for validation errors display | |
7 | def self.human_attribute_name(attr, *args) |
|
7 | def self.human_attribute_name(attr, *args) | |
8 | l("field_#{attr.to_s.gsub(/_id$/, '')}", :default => attr) |
|
8 | l("field_#{attr.to_s.gsub(/_id$/, '')}", :default => attr) | |
9 | end |
|
9 | end | |
10 | end |
|
10 | end | |
11 | end |
|
11 | end | |
12 |
|
12 | |||
13 | module ActionView |
|
13 | module ActionView | |
14 | module Helpers |
|
14 | module Helpers | |
15 | module DateHelper |
|
15 | module DateHelper | |
16 | # 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 | |
17 | 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 = {}) | |
18 | 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) | |
19 | 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) | |
20 | distance_in_days = (to_date - from_date).abs |
|
20 | distance_in_days = (to_date - from_date).abs | |
21 |
|
21 | |||
22 | 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| | |
23 | case distance_in_days |
|
23 | case distance_in_days | |
24 | 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 | |
25 | 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 | |
26 | 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 | |
27 | end |
|
27 | end | |
28 | end |
|
28 | end | |
29 | end |
|
29 | end | |
30 | end |
|
30 | end | |
31 | end |
|
31 | end | |
32 |
|
32 | |||
33 | class Resolver |
|
33 | class Resolver | |
34 | 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=[]) | |
35 | cached(key, [name, prefix, partial], details, locals) do |
|
35 | cached(key, [name, prefix, partial], details, locals) do | |
36 | if details[:formats] & [:xml, :json] |
|
36 | if details[:formats] & [:xml, :json] | |
37 | details = details.dup |
|
37 | details = details.dup | |
38 | details[:formats] = details[:formats].dup + [:api] |
|
38 | details[:formats] = details[:formats].dup + [:api] | |
39 | end |
|
39 | end | |
40 | find_templates(name, prefix, partial, details) |
|
40 | find_templates(name, prefix, partial, details) | |
41 | end |
|
41 | end | |
42 | end |
|
42 | end | |
43 | end |
|
43 | end | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | 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}" } | |
47 |
|
47 | |||
48 | require 'mail' |
|
48 | require 'mail' | |
49 |
|
49 | |||
50 | module DeliveryMethods |
|
50 | module DeliveryMethods | |
51 | class AsyncSMTP < ::Mail::SMTP |
|
51 | class AsyncSMTP < ::Mail::SMTP | |
52 | def deliver!(*args) |
|
52 | def deliver!(*args) | |
53 | Thread.start do |
|
53 | Thread.start do | |
54 | super *args |
|
54 | super *args | |
55 | end |
|
55 | end | |
56 | end |
|
56 | end | |
57 | end |
|
57 | end | |
58 |
|
58 | |||
59 | class AsyncSendmail < ::Mail::Sendmail |
|
59 | class AsyncSendmail < ::Mail::Sendmail | |
60 | def deliver!(*args) |
|
60 | def deliver!(*args) | |
61 | Thread.start do |
|
61 | Thread.start do | |
62 | super *args |
|
62 | super *args | |
63 | end |
|
63 | end | |
64 | end |
|
64 | end | |
65 | end |
|
65 | end | |
66 |
|
66 | |||
67 | class TmpFile |
|
67 | class TmpFile | |
68 | def initialize(*args); end |
|
68 | def initialize(*args); end | |
69 |
|
69 | |||
70 | def deliver!(mail) |
|
70 | def deliver!(mail) | |
71 | dest_dir = File.join(Rails.root, 'tmp', 'emails') |
|
71 | dest_dir = File.join(Rails.root, 'tmp', 'emails') | |
72 | Dir.mkdir(dest_dir) unless File.directory?(dest_dir) |
|
72 | Dir.mkdir(dest_dir) unless File.directory?(dest_dir) | |
73 | 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) } | |
74 | end |
|
74 | end | |
75 | end |
|
75 | end | |
76 | end |
|
76 | end | |
77 |
|
77 | |||
78 | ActionMailer::Base.add_delivery_method :async_smtp, DeliveryMethods::AsyncSMTP |
|
78 | ActionMailer::Base.add_delivery_method :async_smtp, DeliveryMethods::AsyncSMTP | |
79 | ActionMailer::Base.add_delivery_method :async_sendmail, DeliveryMethods::AsyncSendmail |
|
79 | ActionMailer::Base.add_delivery_method :async_sendmail, DeliveryMethods::AsyncSendmail | |
80 | ActionMailer::Base.add_delivery_method :tmp_file, DeliveryMethods::TmpFile |
|
80 | ActionMailer::Base.add_delivery_method :tmp_file, DeliveryMethods::TmpFile | |
81 |
|
81 | |||
82 | module ActionController |
|
82 | module ActionController | |
83 | module MimeResponds |
|
83 | module MimeResponds | |
84 | class Collector |
|
84 | class Collector | |
85 | def api(&block) |
|
85 | def api(&block) | |
86 | any(:xml, :json, &block) |
|
86 | any(:xml, :json, &block) | |
87 | end |
|
87 | end | |
88 | end |
|
88 | end | |
89 | end |
|
89 | end | |
90 | end |
|
90 | end | |
91 |
|
91 | |||
92 | module ActionController |
|
92 | module ActionController | |
93 | class Base |
|
93 | class Base | |
94 | # Displays an explicit message instead of a NoMethodError exception |
|
94 | # Displays an explicit message instead of a NoMethodError exception | |
95 | # when trying to start Redmine with an old session_store.rb |
|
95 | # when trying to start Redmine with an old session_store.rb | |
96 | # TODO: remove it in a later version |
|
96 | # TODO: remove it in a later version | |
97 | def self.session=(*args) |
|
97 | def self.session=(*args) | |
98 | $stderr.puts "Please remove config/session_store.rb and run `rake generate_secret_token`.\n" + |
|
98 | $stderr.puts "Please remove config/initializers/session_store.rb and run `rake generate_secret_token`.\n" + | |
99 | "Setting the session secret with ActionController.session= is no longer supported in Rails 3." |
|
99 | "Setting the session secret with ActionController.session= is no longer supported in Rails 3." | |
100 | exit 1 |
|
100 | exit 1 | |
101 | end |
|
101 | end | |
102 | end |
|
102 | end | |
103 | end |
|
103 | end |
General Comments 0
You need to be logged in to leave comments.
Login now