@@ -1,260 +1,241 | |||
|
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 | attr = attr.to_s.sub(/_id$/, '') |
|
9 | 9 | |
|
10 | 10 | l("field_#{name.underscore.gsub('/', '_')}_#{attr}", :default => ["field_#{attr}".to_sym, attr]) |
|
11 | 11 | end |
|
12 | 12 | end |
|
13 | 13 | |
|
14 | 14 | # Undefines private Kernel#open method to allow using `open` scopes in models. |
|
15 | 15 | # See Defect #11545 (http://www.redmine.org/issues/11545) for details. |
|
16 | 16 | class Base |
|
17 | 17 | class << self |
|
18 | 18 | undef open |
|
19 | 19 | end |
|
20 | 20 | end |
|
21 | 21 | class Relation ; undef open ; end |
|
22 | 22 | end |
|
23 | 23 | |
|
24 | 24 | module ActionView |
|
25 | 25 | module Helpers |
|
26 | 26 | module DateHelper |
|
27 | 27 | # distance_of_time_in_words breaks when difference is greater than 30 years |
|
28 | 28 | def distance_of_date_in_words(from_date, to_date = 0, options = {}) |
|
29 | 29 | from_date = from_date.to_date if from_date.respond_to?(:to_date) |
|
30 | 30 | to_date = to_date.to_date if to_date.respond_to?(:to_date) |
|
31 | 31 | distance_in_days = (to_date - from_date).abs |
|
32 | 32 | |
|
33 | 33 | I18n.with_options :locale => options[:locale], :scope => :'datetime.distance_in_words' do |locale| |
|
34 | 34 | case distance_in_days |
|
35 | 35 | when 0..60 then locale.t :x_days, :count => distance_in_days.round |
|
36 | 36 | when 61..720 then locale.t :about_x_months, :count => (distance_in_days / 30).round |
|
37 | 37 | else locale.t :over_x_years, :count => (distance_in_days / 365).floor |
|
38 | 38 | end |
|
39 | 39 | end |
|
40 | 40 | end |
|
41 | 41 | end |
|
42 | 42 | end |
|
43 | 43 | |
|
44 | 44 | class Resolver |
|
45 | 45 | def find_all(name, prefix=nil, partial=false, details={}, key=nil, locals=[]) |
|
46 | 46 | cached(key, [name, prefix, partial], details, locals) do |
|
47 | 47 | if details[:formats] & [:xml, :json] |
|
48 | 48 | details = details.dup |
|
49 | 49 | details[:formats] = details[:formats].dup + [:api] |
|
50 | 50 | end |
|
51 | 51 | find_templates(name, prefix, partial, details) |
|
52 | 52 | end |
|
53 | 53 | end |
|
54 | 54 | end |
|
55 | 55 | end |
|
56 | 56 | |
|
57 | 57 | # Do not HTML escape text templates |
|
58 | 58 | module ActionView |
|
59 | 59 | class Template |
|
60 | 60 | module Handlers |
|
61 | 61 | class ERB |
|
62 | 62 | def call(template) |
|
63 | 63 | if template.source.encoding_aware? |
|
64 | 64 | # First, convert to BINARY, so in case the encoding is |
|
65 | 65 | # wrong, we can still find an encoding tag |
|
66 | 66 | # (<%# encoding %>) inside the String using a regular |
|
67 | 67 | # expression |
|
68 | 68 | template_source = template.source.dup.force_encoding("BINARY") |
|
69 | 69 | |
|
70 | 70 | erb = template_source.gsub(ENCODING_TAG, '') |
|
71 | 71 | encoding = $2 |
|
72 | 72 | |
|
73 | 73 | erb.force_encoding valid_encoding(template.source.dup, encoding) |
|
74 | 74 | |
|
75 | 75 | # Always make sure we return a String in the default_internal |
|
76 | 76 | erb.encode! |
|
77 | 77 | else |
|
78 | 78 | erb = template.source.dup |
|
79 | 79 | end |
|
80 | 80 | |
|
81 | 81 | self.class.erb_implementation.new( |
|
82 | 82 | erb, |
|
83 | 83 | :trim => (self.class.erb_trim_mode == "-"), |
|
84 | 84 | :escape => template.identifier =~ /\.text/ # only escape HTML templates |
|
85 | 85 | ).src |
|
86 | 86 | end |
|
87 | 87 | end |
|
88 | 88 | end |
|
89 | 89 | end |
|
90 | 90 | end |
|
91 | 91 | |
|
92 | 92 | ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| html_tag || ''.html_safe } |
|
93 | 93 | |
|
94 | 94 | # HTML5: <option value=""></option> is invalid, use <option value=""> </option> instead |
|
95 | 95 | module ActionView |
|
96 | 96 | module Helpers |
|
97 | 97 | class InstanceTag |
|
98 | 98 | private |
|
99 | 99 | def add_options_with_non_empty_blank_option(option_tags, options, value = nil) |
|
100 | 100 | if options[:include_blank] == true |
|
101 | 101 | options = options.dup |
|
102 | 102 | options[:include_blank] = ' '.html_safe |
|
103 | 103 | end |
|
104 | 104 | add_options_without_non_empty_blank_option(option_tags, options, value) |
|
105 | 105 | end |
|
106 | 106 | alias_method_chain :add_options, :non_empty_blank_option |
|
107 | 107 | end |
|
108 | 108 | |
|
109 | 109 | module FormTagHelper |
|
110 | 110 | def select_tag_with_non_empty_blank_option(name, option_tags = nil, options = {}) |
|
111 | 111 | if options.delete(:include_blank) |
|
112 | 112 | options[:prompt] = ' '.html_safe |
|
113 | 113 | end |
|
114 | 114 | select_tag_without_non_empty_blank_option(name, option_tags, options) |
|
115 | 115 | end |
|
116 | 116 | alias_method_chain :select_tag, :non_empty_blank_option |
|
117 | 117 | end |
|
118 | 118 | |
|
119 | 119 | module FormOptionsHelper |
|
120 | 120 | def options_for_select_with_non_empty_blank_option(container, selected = nil) |
|
121 | 121 | if container.is_a?(Array) |
|
122 | 122 | container = container.map {|element| element.blank? ? [" ".html_safe, ""] : element} |
|
123 | 123 | end |
|
124 | 124 | options_for_select_without_non_empty_blank_option(container, selected) |
|
125 | 125 | end |
|
126 | 126 | alias_method_chain :options_for_select, :non_empty_blank_option |
|
127 | 127 | end |
|
128 | 128 | end |
|
129 | 129 | end |
|
130 | 130 | |
|
131 | 131 | require 'mail' |
|
132 | 132 | |
|
133 | 133 | module DeliveryMethods |
|
134 | 134 | class AsyncSMTP < ::Mail::SMTP |
|
135 | 135 | def deliver!(*args) |
|
136 | 136 | Thread.start do |
|
137 | 137 | super *args |
|
138 | 138 | end |
|
139 | 139 | end |
|
140 | 140 | end |
|
141 | 141 | |
|
142 | 142 | class AsyncSendmail < ::Mail::Sendmail |
|
143 | 143 | def deliver!(*args) |
|
144 | 144 | Thread.start do |
|
145 | 145 | super *args |
|
146 | 146 | end |
|
147 | 147 | end |
|
148 | 148 | end |
|
149 | 149 | |
|
150 | 150 | class TmpFile |
|
151 | 151 | def initialize(*args); end |
|
152 | 152 | |
|
153 | 153 | def deliver!(mail) |
|
154 | 154 | dest_dir = File.join(Rails.root, 'tmp', 'emails') |
|
155 | 155 | Dir.mkdir(dest_dir) unless File.directory?(dest_dir) |
|
156 | 156 | File.open(File.join(dest_dir, mail.message_id.gsub(/[<>]/, '') + '.eml'), 'wb') {|f| f.write(mail.encoded) } |
|
157 | 157 | end |
|
158 | 158 | end |
|
159 | 159 | end |
|
160 | 160 | |
|
161 | 161 | ActionMailer::Base.add_delivery_method :async_smtp, DeliveryMethods::AsyncSMTP |
|
162 | 162 | ActionMailer::Base.add_delivery_method :async_sendmail, DeliveryMethods::AsyncSendmail |
|
163 | 163 | ActionMailer::Base.add_delivery_method :tmp_file, DeliveryMethods::TmpFile |
|
164 | 164 | |
|
165 | 165 | # Changes how sent emails are logged |
|
166 | 166 | # Rails doesn't log cc and bcc which is misleading when using bcc only (#12090) |
|
167 | 167 | module ActionMailer |
|
168 | 168 | class LogSubscriber < ActiveSupport::LogSubscriber |
|
169 | 169 | def deliver(event) |
|
170 | 170 | recipients = [:to, :cc, :bcc].inject("") do |s, header| |
|
171 | 171 | r = Array.wrap(event.payload[header]) |
|
172 | 172 | if r.any? |
|
173 | 173 | s << "\n #{header}: #{r.join(', ')}" |
|
174 | 174 | end |
|
175 | 175 | s |
|
176 | 176 | end |
|
177 | 177 | info("\nSent email \"#{event.payload[:subject]}\" (%1.fms)#{recipients}" % event.duration) |
|
178 | 178 | debug(event.payload[:mail]) |
|
179 | 179 | end |
|
180 | 180 | end |
|
181 | 181 | end |
|
182 | 182 | |
|
183 | 183 | module ActionController |
|
184 | 184 | module MimeResponds |
|
185 | 185 | class Collector |
|
186 | 186 | def api(&block) |
|
187 | 187 | any(:xml, :json, &block) |
|
188 | 188 | end |
|
189 | 189 | end |
|
190 | 190 | end |
|
191 | 191 | end |
|
192 | 192 | |
|
193 | 193 | module ActionController |
|
194 | 194 | class Base |
|
195 | 195 | # Displays an explicit message instead of a NoMethodError exception |
|
196 | 196 | # when trying to start Redmine with an old session_store.rb |
|
197 | 197 | # TODO: remove it in a later version |
|
198 | 198 | def self.session=(*args) |
|
199 | 199 | $stderr.puts "Please remove config/initializers/session_store.rb and run `rake generate_secret_token`.\n" + |
|
200 | 200 | "Setting the session secret with ActionController.session= is no longer supported in Rails 3." |
|
201 | 201 | exit 1 |
|
202 | 202 | end |
|
203 | 203 | end |
|
204 | 204 | end |
|
205 | 205 | |
|
206 | 206 | if Rails::VERSION::MAJOR < 4 && RUBY_VERSION >= "2.1" |
|
207 | 207 | module ActiveSupport |
|
208 | 208 | class HashWithIndifferentAccess |
|
209 | 209 | def select(*args, &block) |
|
210 | 210 | dup.tap { |hash| hash.select!(*args, &block) } |
|
211 | 211 | end |
|
212 | 212 | |
|
213 | 213 | def reject(*args, &block) |
|
214 | 214 | dup.tap { |hash| hash.reject!(*args, &block) } |
|
215 | 215 | end |
|
216 | 216 | end |
|
217 | 217 | |
|
218 | 218 | class OrderedHash |
|
219 | 219 | def select(*args, &block) |
|
220 | 220 | dup.tap { |hash| hash.select!(*args, &block) } |
|
221 | 221 | end |
|
222 | 222 | |
|
223 | 223 | def reject(*args, &block) |
|
224 | 224 | dup.tap { |hash| hash.reject!(*args, &block) } |
|
225 | 225 | end |
|
226 | 226 | end |
|
227 | 227 | end |
|
228 | 228 | end |
|
229 | 229 | |
|
230 | require 'awesome_nested_set/version' | |
|
231 | ||
|
232 | 230 | module CollectiveIdea |
|
233 | 231 | module Acts |
|
234 | 232 | module NestedSet |
|
235 | 233 | module Model |
|
236 | 234 | def leaf_with_new_record? |
|
237 | 235 | new_record? || leaf_without_new_record? |
|
238 | 236 | end |
|
239 | 237 | alias_method_chain :leaf?, :new_record |
|
240 | # Reload is needed because children may have updated | |
|
241 | # their parent (self) during deletion. | |
|
242 | if ::AwesomeNestedSet::VERSION > "2.1.6" | |
|
243 | module Prunable | |
|
244 | def destroy_descendants_with_reload | |
|
245 | destroy_descendants_without_reload | |
|
246 | reload | |
|
247 | end | |
|
248 | alias_method_chain :destroy_descendants, :reload | |
|
249 | end | |
|
250 | else | |
|
251 | def destroy_descendants_with_reload | |
|
252 | destroy_descendants_without_reload | |
|
253 | reload | |
|
254 | end | |
|
255 | alias_method_chain :destroy_descendants, :reload | |
|
256 | end | |
|
257 | 238 | end |
|
258 | 239 | end |
|
259 | 240 | end |
|
260 | 241 | end |
General Comments 0
You need to be logged in to leave comments.
Login now