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