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