annotate .svn/pristine/17/1751b405084d5f3027dcc49f2f10ccbdc9c84321.svn-base @ 1613:90bed4e10cc8 deploy

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