##// END OF EJS Templates
Don't use alias_chain_method....
Jean-Philippe Lang -
r15278:9d9e26317a61
parent child
Show More
@@ -1,189 +1,189
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, options = {})
7 def self.human_attribute_name(attr, options = {})
8 prepared_attr = attr.to_s.sub(/_id$/, '').sub(/^.+\./, '')
8 prepared_attr = attr.to_s.sub(/_id$/, '').sub(/^.+\./, '')
9 class_prefix = name.underscore.gsub('/', '_')
9 class_prefix = name.underscore.gsub('/', '_')
10
10
11 redmine_default = [
11 redmine_default = [
12 :"field_#{class_prefix}_#{prepared_attr}",
12 :"field_#{class_prefix}_#{prepared_attr}",
13 :"field_#{prepared_attr}"
13 :"field_#{prepared_attr}"
14 ]
14 ]
15
15
16 options[:default] = redmine_default + Array(options[:default])
16 options[:default] = redmine_default + Array(options[:default])
17
17
18 super
18 super
19 end
19 end
20 end
20 end
21
21
22 # Undefines private Kernel#open method to allow using `open` scopes in models.
22 # Undefines private Kernel#open method to allow using `open` scopes in models.
23 # See Defect #11545 (http://www.redmine.org/issues/11545) for details.
23 # See Defect #11545 (http://www.redmine.org/issues/11545) for details.
24 class Base
24 class Base
25 class << self
25 class << self
26 undef open
26 undef open
27 end
27 end
28 end
28 end
29 class Relation ; undef open ; end
29 class Relation ; undef open ; end
30 end
30 end
31
31
32 module ActionView
32 module ActionView
33 module Helpers
33 module Helpers
34 module DateHelper
34 module DateHelper
35 # distance_of_time_in_words breaks when difference is greater than 30 years
35 # distance_of_time_in_words breaks when difference is greater than 30 years
36 def distance_of_date_in_words(from_date, to_date = 0, options = {})
36 def distance_of_date_in_words(from_date, to_date = 0, options = {})
37 from_date = from_date.to_date if from_date.respond_to?(:to_date)
37 from_date = from_date.to_date if from_date.respond_to?(:to_date)
38 to_date = to_date.to_date if to_date.respond_to?(:to_date)
38 to_date = to_date.to_date if to_date.respond_to?(:to_date)
39 distance_in_days = (to_date - from_date).abs
39 distance_in_days = (to_date - from_date).abs
40
40
41 I18n.with_options :locale => options[:locale], :scope => :'datetime.distance_in_words' do |locale|
41 I18n.with_options :locale => options[:locale], :scope => :'datetime.distance_in_words' do |locale|
42 case distance_in_days
42 case distance_in_days
43 when 0..60 then locale.t :x_days, :count => distance_in_days.round
43 when 0..60 then locale.t :x_days, :count => distance_in_days.round
44 when 61..720 then locale.t :about_x_months, :count => (distance_in_days / 30).round
44 when 61..720 then locale.t :about_x_months, :count => (distance_in_days / 30).round
45 else locale.t :over_x_years, :count => (distance_in_days / 365).floor
45 else locale.t :over_x_years, :count => (distance_in_days / 365).floor
46 end
46 end
47 end
47 end
48 end
48 end
49 end
49 end
50 end
50 end
51
51
52 class Resolver
52 class Resolver
53 def find_all(name, prefix=nil, partial=false, details={}, key=nil, locals=[])
53 def find_all(name, prefix=nil, partial=false, details={}, key=nil, locals=[])
54 cached(key, [name, prefix, partial], details, locals) do
54 cached(key, [name, prefix, partial], details, locals) do
55 if (details[:formats] & [:xml, :json]).any?
55 if (details[:formats] & [:xml, :json]).any?
56 details = details.dup
56 details = details.dup
57 details[:formats] = details[:formats].dup + [:api]
57 details[:formats] = details[:formats].dup + [:api]
58 end
58 end
59 find_templates(name, prefix, partial, details)
59 find_templates(name, prefix, partial, details)
60 end
60 end
61 end
61 end
62 end
62 end
63 end
63 end
64
64
65 ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| html_tag || ''.html_safe }
65 ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| html_tag || ''.html_safe }
66
66
67 # HTML5: <option value=""></option> is invalid, use <option value="">&nbsp;</option> instead
67 # HTML5: <option value=""></option> is invalid, use <option value="">&nbsp;</option> instead
68 module ActionView
68 module ActionView
69 module Helpers
69 module Helpers
70 module Tags
70 module Tags
71 class Base
71 class Base
72 private
72 private
73 def add_options_with_non_empty_blank_option(option_tags, options, value = nil)
73 alias :add_options_without_non_empty_blank_option :add_options
74 def add_options(option_tags, options, value = nil)
74 if options[:include_blank] == true
75 if options[:include_blank] == true
75 options = options.dup
76 options = options.dup
76 options[:include_blank] = '&nbsp;'.html_safe
77 options[:include_blank] = '&nbsp;'.html_safe
77 end
78 end
78 add_options_without_non_empty_blank_option(option_tags, options, value)
79 add_options_without_non_empty_blank_option(option_tags, options, value)
79 end
80 end
80 alias_method_chain :add_options, :non_empty_blank_option
81 end
81 end
82 end
82 end
83
83
84 module FormTagHelper
84 module FormTagHelper
85 def select_tag_with_non_empty_blank_option(name, option_tags = nil, options = {})
85 alias :select_tag_without_non_empty_blank_option :select_tag
86 def select_tag(name, option_tags = nil, options = {})
86 if options.delete(:include_blank)
87 if options.delete(:include_blank)
87 options[:prompt] = '&nbsp;'.html_safe
88 options[:prompt] = '&nbsp;'.html_safe
88 end
89 end
89 select_tag_without_non_empty_blank_option(name, option_tags, options)
90 select_tag_without_non_empty_blank_option(name, option_tags, options)
90 end
91 end
91 alias_method_chain :select_tag, :non_empty_blank_option
92 end
92 end
93
93
94 module FormOptionsHelper
94 module FormOptionsHelper
95 def options_for_select_with_non_empty_blank_option(container, selected = nil)
95 alias :options_for_select_without_non_empty_blank_option :options_for_select
96 def options_for_select(container, selected = nil)
96 if container.is_a?(Array)
97 if container.is_a?(Array)
97 container = container.map {|element| element.blank? ? ["&nbsp;".html_safe, ""] : element}
98 container = container.map {|element| element.blank? ? ["&nbsp;".html_safe, ""] : element}
98 end
99 end
99 options_for_select_without_non_empty_blank_option(container, selected)
100 options_for_select_without_non_empty_blank_option(container, selected)
100 end
101 end
101 alias_method_chain :options_for_select, :non_empty_blank_option
102 end
102 end
103 end
103 end
104 end
104 end
105
105
106 require 'mail'
106 require 'mail'
107
107
108 module DeliveryMethods
108 module DeliveryMethods
109 class AsyncSMTP < ::Mail::SMTP
109 class AsyncSMTP < ::Mail::SMTP
110 def deliver!(*args)
110 def deliver!(*args)
111 Thread.start do
111 Thread.start do
112 super *args
112 super *args
113 end
113 end
114 end
114 end
115 end
115 end
116
116
117 class AsyncSendmail < ::Mail::Sendmail
117 class AsyncSendmail < ::Mail::Sendmail
118 def deliver!(*args)
118 def deliver!(*args)
119 Thread.start do
119 Thread.start do
120 super *args
120 super *args
121 end
121 end
122 end
122 end
123 end
123 end
124
124
125 class TmpFile
125 class TmpFile
126 def initialize(*args); end
126 def initialize(*args); end
127
127
128 def deliver!(mail)
128 def deliver!(mail)
129 dest_dir = File.join(Rails.root, 'tmp', 'emails')
129 dest_dir = File.join(Rails.root, 'tmp', 'emails')
130 Dir.mkdir(dest_dir) unless File.directory?(dest_dir)
130 Dir.mkdir(dest_dir) unless File.directory?(dest_dir)
131 File.open(File.join(dest_dir, mail.message_id.gsub(/[<>]/, '') + '.eml'), 'wb') {|f| f.write(mail.encoded) }
131 File.open(File.join(dest_dir, mail.message_id.gsub(/[<>]/, '') + '.eml'), 'wb') {|f| f.write(mail.encoded) }
132 end
132 end
133 end
133 end
134 end
134 end
135
135
136 ActionMailer::Base.add_delivery_method :async_smtp, DeliveryMethods::AsyncSMTP
136 ActionMailer::Base.add_delivery_method :async_smtp, DeliveryMethods::AsyncSMTP
137 ActionMailer::Base.add_delivery_method :async_sendmail, DeliveryMethods::AsyncSendmail
137 ActionMailer::Base.add_delivery_method :async_sendmail, DeliveryMethods::AsyncSendmail
138 ActionMailer::Base.add_delivery_method :tmp_file, DeliveryMethods::TmpFile
138 ActionMailer::Base.add_delivery_method :tmp_file, DeliveryMethods::TmpFile
139
139
140 # Changes how sent emails are logged
140 # Changes how sent emails are logged
141 # Rails doesn't log cc and bcc which is misleading when using bcc only (#12090)
141 # Rails doesn't log cc and bcc which is misleading when using bcc only (#12090)
142 module ActionMailer
142 module ActionMailer
143 class LogSubscriber < ActiveSupport::LogSubscriber
143 class LogSubscriber < ActiveSupport::LogSubscriber
144 def deliver(event)
144 def deliver(event)
145 recipients = [:to, :cc, :bcc].inject("") do |s, header|
145 recipients = [:to, :cc, :bcc].inject("") do |s, header|
146 r = Array.wrap(event.payload[header])
146 r = Array.wrap(event.payload[header])
147 if r.any?
147 if r.any?
148 s << "\n #{header}: #{r.join(', ')}"
148 s << "\n #{header}: #{r.join(', ')}"
149 end
149 end
150 s
150 s
151 end
151 end
152 info("\nSent email \"#{event.payload[:subject]}\" (%1.fms)#{recipients}" % event.duration)
152 info("\nSent email \"#{event.payload[:subject]}\" (%1.fms)#{recipients}" % event.duration)
153 debug(event.payload[:mail])
153 debug(event.payload[:mail])
154 end
154 end
155 end
155 end
156 end
156 end
157
157
158 # #deliver is deprecated in Rails 4.2
158 # #deliver is deprecated in Rails 4.2
159 # Prevents massive deprecation warnings
159 # Prevents massive deprecation warnings
160 module ActionMailer
160 module ActionMailer
161 class MessageDelivery < Delegator
161 class MessageDelivery < Delegator
162 def deliver
162 def deliver
163 deliver_now
163 deliver_now
164 end
164 end
165 end
165 end
166 end
166 end
167
167
168 module ActionController
168 module ActionController
169 module MimeResponds
169 module MimeResponds
170 class Collector
170 class Collector
171 def api(&block)
171 def api(&block)
172 any(:xml, :json, &block)
172 any(:xml, :json, &block)
173 end
173 end
174 end
174 end
175 end
175 end
176 end
176 end
177
177
178 module ActionController
178 module ActionController
179 class Base
179 class Base
180 # Displays an explicit message instead of a NoMethodError exception
180 # Displays an explicit message instead of a NoMethodError exception
181 # when trying to start Redmine with an old session_store.rb
181 # when trying to start Redmine with an old session_store.rb
182 # TODO: remove it in a later version
182 # TODO: remove it in a later version
183 def self.session=(*args)
183 def self.session=(*args)
184 $stderr.puts "Please remove config/initializers/session_store.rb and run `rake generate_secret_token`.\n" +
184 $stderr.puts "Please remove config/initializers/session_store.rb and run `rake generate_secret_token`.\n" +
185 "Setting the session secret with ActionController.session= is no longer supported."
185 "Setting the session secret with ActionController.session= is no longer supported."
186 exit 1
186 exit 1
187 end
187 end
188 end
188 end
189 end
189 end
General Comments 0
You need to be logged in to leave comments. Login now