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