annotate app/helpers/application_helper.rb @ 1452:d6b9fd02bb89 feature_36_js_refactoring

Deprecated develoment branch.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Fri, 11 Oct 2013 17:01:24 +0100
parents 5d608412b003
children 5e80956cc792
rev   line source
chris@37 1 # Redmine - project management software
Chris@441 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@0 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@0 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@0 18 require 'forwardable'
Chris@0 19 require 'cgi'
Chris@0 20
Chris@0 21 module ApplicationHelper
Chris@0 22 include Redmine::WikiFormatting::Macros::Definitions
Chris@0 23 include Redmine::I18n
Chris@0 24 include GravatarHelper::PublicMethods
Chris@0 25
Chris@0 26 extend Forwardable
Chris@0 27 def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter
Chris@0 28
Chris@0 29 # Return true if user is authorized for controller/action, otherwise false
Chris@0 30 def authorize_for(controller, action)
Chris@0 31 User.current.allowed_to?({:controller => controller, :action => action}, @project)
Chris@0 32 end
Chris@0 33
Chris@0 34 # Display a link if user is authorized
chris@22 35 #
chris@22 36 # @param [String] name Anchor text (passed to link_to)
chris@37 37 # @param [Hash] options Hash params. This will checked by authorize_for to see if the user is authorized
chris@22 38 # @param [optional, Hash] html_options Options passed to link_to
chris@22 39 # @param [optional, Hash] parameters_for_method_reference Extra parameters for link_to
Chris@0 40 def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
chris@37 41 link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action])
Chris@0 42 end
Chris@0 43
Chris@0 44 # Display a link to remote if user is authorized
Chris@0 45 def link_to_remote_if_authorized(name, options = {}, html_options = nil)
Chris@0 46 url = options[:url] || {}
Chris@0 47 link_to_remote(name, options, html_options) if authorize_for(url[:controller] || params[:controller], url[:action])
Chris@0 48 end
Chris@0 49
Chris@0 50 # Displays a link to user's account page if active
Chris@0 51 def link_to_user(user, options={})
Chris@0 52 if user.is_a?(User)
Chris@0 53 name = h(user.name(options[:format]))
Chris@0 54 if user.active?
chris@140 55 link_to(name, :controller => 'users', :action => 'show', :id => user)
Chris@0 56 else
Chris@0 57 name
Chris@0 58 end
Chris@0 59 else
Chris@0 60 h(user.to_s)
Chris@0 61 end
Chris@0 62 end
Chris@0 63
Chris@0 64 # Displays a link to +issue+ with its subject.
Chris@0 65 # Examples:
Chris@441 66 #
Chris@0 67 # link_to_issue(issue) # => Defect #6: This is the subject
Chris@0 68 # link_to_issue(issue, :truncate => 6) # => Defect #6: This i...
Chris@0 69 # link_to_issue(issue, :subject => false) # => Defect #6
Chris@0 70 # link_to_issue(issue, :project => true) # => Foo - Defect #6
Chris@0 71 #
Chris@0 72 def link_to_issue(issue, options={})
Chris@0 73 title = nil
Chris@0 74 subject = nil
Chris@0 75 if options[:subject] == false
Chris@0 76 title = truncate(issue.subject, :length => 60)
Chris@0 77 else
Chris@0 78 subject = issue.subject
Chris@0 79 if options[:truncate]
Chris@0 80 subject = truncate(subject, :length => options[:truncate])
Chris@0 81 end
Chris@0 82 end
Chris@441 83 s = link_to "#{issue.tracker} ##{issue.id}", {:controller => "issues", :action => "show", :id => issue},
Chris@0 84 :class => issue.css_classes,
Chris@0 85 :title => title
Chris@0 86 s << ": #{h subject}" if subject
Chris@0 87 s = "#{h issue.project} - " + s if options[:project]
Chris@0 88 s
Chris@0 89 end
Chris@0 90
Chris@0 91 # Generates a link to an attachment.
Chris@0 92 # Options:
Chris@0 93 # * :text - Link text (default to attachment filename)
Chris@0 94 # * :download - Force download (default: false)
Chris@0 95 def link_to_attachment(attachment, options={})
Chris@0 96 text = options.delete(:text) || attachment.filename
Chris@0 97 action = options.delete(:download) ? 'download' : 'show'
Chris@0 98
Chris@0 99 link_to(h(text), {:controller => 'attachments', :action => action, :id => attachment, :filename => attachment.filename }, options)
Chris@0 100 end
Chris@0 101
Chris@0 102 # Generates a link to a SCM revision
Chris@0 103 # Options:
Chris@0 104 # * :text - Link text (default to the formatted revision)
Chris@0 105 def link_to_revision(revision, project, options={})
Chris@0 106 text = options.delete(:text) || format_revision(revision)
Chris@119 107 rev = revision.respond_to?(:identifier) ? revision.identifier : revision
Chris@0 108
Chris@119 109 link_to(text, {:controller => 'repositories', :action => 'revision', :id => project, :rev => rev},
Chris@119 110 :title => l(:label_revision_id, format_revision(revision)))
Chris@0 111 end
Chris@441 112
Chris@210 113 # Generates a link to a message
Chris@210 114 def link_to_message(message, options={}, html_options = nil)
Chris@210 115 link_to(
Chris@210 116 h(truncate(message.subject, :length => 60)),
Chris@210 117 { :controller => 'messages', :action => 'show',
Chris@210 118 :board_id => message.board_id,
Chris@210 119 :id => message.root,
Chris@210 120 :r => (message.parent_id && message.id),
Chris@210 121 :anchor => (message.parent_id ? "message-#{message.id}" : nil)
Chris@210 122 }.merge(options),
Chris@210 123 html_options
Chris@210 124 )
Chris@210 125 end
Chris@0 126
Chris@14 127 # Generates a link to a project if active
Chris@14 128 # Examples:
Chris@441 129 #
Chris@14 130 # link_to_project(project) # => link to the specified project overview
Chris@14 131 # link_to_project(project, :action=>'settings') # => link to project settings
Chris@14 132 # link_to_project(project, {:only_path => false}, :class => "project") # => 3rd arg adds html options
Chris@14 133 # link_to_project(project, {}, :class => "project") # => html options with default url (project overview)
Chris@14 134 #
Chris@14 135 def link_to_project(project, options={}, html_options = nil)
Chris@14 136 if project.active?
Chris@14 137 url = {:controller => 'projects', :action => 'show', :id => project}.merge(options)
Chris@14 138 link_to(h(project), url, html_options)
Chris@14 139 else
Chris@14 140 h(project)
Chris@14 141 end
Chris@14 142 end
Chris@14 143
Chris@0 144 def toggle_link(name, id, options={})
Chris@0 145 onclick = "Element.toggle('#{id}'); "
Chris@0 146 onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ")
Chris@0 147 onclick << "return false;"
Chris@0 148 link_to(name, "#", :onclick => onclick)
Chris@0 149 end
Chris@0 150
Chris@0 151 def image_to_function(name, function, html_options = {})
Chris@0 152 html_options.symbolize_keys!
Chris@0 153 tag(:input, html_options.merge({
Chris@0 154 :type => "image", :src => image_path(name),
Chris@0 155 :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};"
Chris@0 156 }))
Chris@0 157 end
Chris@0 158
Chris@0 159 def prompt_to_remote(name, text, param, url, html_options = {})
Chris@0 160 html_options[:onclick] = "promptToRemote('#{text}', '#{param}', '#{url_for(url)}'); return false;"
Chris@0 161 link_to name, {}, html_options
Chris@0 162 end
Chris@441 163
Chris@0 164 def format_activity_title(text)
Chris@0 165 h(truncate_single_line(text, :length => 100))
Chris@0 166 end
Chris@441 167
Chris@0 168 def format_activity_day(date)
Chris@0 169 date == Date.today ? l(:label_today).titleize : format_date(date)
Chris@0 170 end
Chris@441 171
Chris@0 172 def format_activity_description(text)
Chris@0 173 h(truncate(text.to_s, :length => 120).gsub(%r{[\r\n]*<(pre|code)>.*$}m, '...')).gsub(/[\r\n]+/, "<br />")
Chris@0 174 end
Chris@0 175
Chris@0 176 def format_version_name(version)
Chris@0 177 if version.project == @project
Chris@0 178 h(version)
Chris@0 179 else
Chris@0 180 h("#{version.project} - #{version}")
Chris@0 181 end
Chris@0 182 end
Chris@441 183
Chris@0 184 def due_date_distance_in_words(date)
Chris@0 185 if date
Chris@0 186 l((date < Date.today ? :label_roadmap_overdue : :label_roadmap_due_in), distance_of_date_in_words(Date.today, date))
Chris@0 187 end
Chris@0 188 end
Chris@0 189
Chris@441 190 def render_page_hierarchy(pages, node=nil, options={})
Chris@0 191 content = ''
Chris@0 192 if pages[node]
Chris@0 193 content << "<ul class=\"pages-hierarchy\">\n"
Chris@0 194 pages[node].each do |page|
Chris@0 195 content << "<li>"
chris@37 196 content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'show', :project_id => page.project, :id => page.title},
Chris@441 197 :title => (options[:timestamp] && page.updated_on ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil))
Chris@441 198 content << "\n" + render_page_hierarchy(pages, page.id, options) if pages[page.id]
Chris@0 199 content << "</li>\n"
Chris@0 200 end
Chris@0 201 content << "</ul>\n"
Chris@0 202 end
Chris@0 203 content
Chris@0 204 end
Chris@441 205
Chris@0 206 # Renders flash messages
Chris@0 207 def render_flash_messages
Chris@0 208 s = ''
Chris@0 209 flash.each do |k,v|
Chris@0 210 s << content_tag('div', v, :class => "flash #{k}")
Chris@0 211 end
Chris@0 212 s
Chris@0 213 end
Chris@441 214
Chris@0 215 # Renders tabs and their content
Chris@0 216 def render_tabs(tabs)
Chris@0 217 if tabs.any?
Chris@0 218 render :partial => 'common/tabs', :locals => {:tabs => tabs}
Chris@0 219 else
Chris@0 220 content_tag 'p', l(:label_no_data), :class => "nodata"
Chris@0 221 end
Chris@0 222 end
Chris@441 223
Chris@0 224 # Renders the project quick-jump box
Chris@0 225 def render_project_jump_box
Chris@441 226 return unless User.current.logged?
Chris@441 227 projects = User.current.memberships.collect(&:project).compact.uniq
Chris@0 228 if projects.any?
Chris@0 229 s = '<select onchange="if (this.value != \'\') { window.location = this.value; }">' +
Chris@0 230 "<option value=''>#{ l(:label_jump_to_a_project) }</option>" +
Chris@0 231 '<option value="" disabled="disabled">---</option>'
Chris@0 232 s << project_tree_options_for_select(projects, :selected => @project) do |p|
Chris@0 233 { :value => url_for(:controller => 'projects', :action => 'show', :id => p, :jump => current_menu_item) }
Chris@0 234 end
Chris@0 235 s << '</select>'
Chris@0 236 s
Chris@0 237 end
Chris@0 238 end
Chris@441 239
Chris@0 240 def project_tree_options_for_select(projects, options = {})
Chris@0 241 s = ''
Chris@0 242 project_tree(projects) do |project, level|
Chris@0 243 name_prefix = (level > 0 ? ('&nbsp;' * 2 * level + '&#187; ') : '')
Chris@0 244 tag_options = {:value => project.id}
Chris@0 245 if project == options[:selected] || (options[:selected].respond_to?(:include?) && options[:selected].include?(project))
Chris@0 246 tag_options[:selected] = 'selected'
Chris@0 247 else
Chris@0 248 tag_options[:selected] = nil
Chris@0 249 end
Chris@0 250 tag_options.merge!(yield(project)) if block_given?
Chris@0 251 s << content_tag('option', name_prefix + h(project), tag_options)
Chris@0 252 end
Chris@0 253 s
Chris@0 254 end
Chris@441 255
Chris@0 256 # Yields the given block for each project with its level in the tree
chris@37 257 #
chris@37 258 # Wrapper for Project#project_tree
Chris@0 259 def project_tree(projects, &block)
chris@37 260 Project.project_tree(projects, &block)
Chris@0 261 end
Chris@441 262
Chris@0 263 def project_nested_ul(projects, &block)
Chris@0 264 s = ''
Chris@0 265 if projects.any?
Chris@0 266 ancestors = []
Chris@0 267 projects.sort_by(&:lft).each do |project|
Chris@0 268 if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
Chris@0 269 s << "<ul>\n"
Chris@0 270 else
Chris@0 271 ancestors.pop
Chris@0 272 s << "</li>"
Chris@441 273 while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
Chris@0 274 ancestors.pop
Chris@0 275 s << "</ul></li>\n"
Chris@0 276 end
Chris@0 277 end
Chris@0 278 s << "<li>"
Chris@0 279 s << yield(project).to_s
Chris@0 280 ancestors << project
Chris@0 281 end
Chris@0 282 s << ("</li></ul>\n" * ancestors.size)
Chris@0 283 end
Chris@0 284 s
Chris@0 285 end
Chris@441 286
Chris@0 287 def principals_check_box_tags(name, principals)
Chris@0 288 s = ''
Chris@0 289 principals.sort.each do |principal|
chris@135 290 s << "<label>#{ check_box_tag name, principal.id, false } #{link_to_user principal}</label>\n"
Chris@0 291 end
Chris@441 292 s
Chris@0 293 end
Chris@0 294
Chris@0 295 # Truncates and returns the string as a single line
Chris@0 296 def truncate_single_line(string, *args)
Chris@0 297 truncate(string.to_s, *args).gsub(%r{[\r\n]+}m, ' ')
Chris@0 298 end
Chris@441 299
Chris@0 300 # Truncates at line break after 250 characters or options[:length]
Chris@0 301 def truncate_lines(string, options={})
Chris@0 302 length = options[:length] || 250
Chris@0 303 if string.to_s =~ /\A(.{#{length}}.*?)$/m
Chris@0 304 "#{$1}..."
Chris@0 305 else
Chris@0 306 string
Chris@0 307 end
Chris@0 308 end
Chris@0 309
Chris@0 310 def html_hours(text)
Chris@0 311 text.gsub(%r{(\d+)\.(\d+)}, '<span class="hours hours-int">\1</span><span class="hours hours-dec">.\2</span>')
Chris@0 312 end
Chris@0 313
Chris@0 314 def authoring(created, author, options={})
Chris@0 315 l(options[:label] || :label_added_time_by, :author => link_to_user(author), :age => time_tag(created))
Chris@0 316 end
Chris@441 317
Chris@0 318 def time_tag(time)
Chris@0 319 text = distance_of_time_in_words(Time.now, time)
Chris@0 320 if @project
chris@22 321 link_to(text, {:controller => 'activities', :action => 'index', :id => @project, :from => time.to_date}, :title => format_time(time))
Chris@0 322 else
Chris@0 323 content_tag('acronym', text, :title => format_time(time))
Chris@0 324 end
Chris@0 325 end
Chris@0 326
Chris@0 327 def syntax_highlight(name, content)
Chris@0 328 Redmine::SyntaxHighlighting.highlight_by_filename(content, name)
Chris@0 329 end
Chris@0 330
Chris@0 331 def to_path_param(path)
Chris@0 332 path.to_s.split(%r{[/\\]}).select {|p| !p.blank?}
Chris@0 333 end
Chris@0 334
Chris@0 335 def pagination_links_full(paginator, count=nil, options={})
Chris@0 336 page_param = options.delete(:page_param) || :page
Chris@0 337 per_page_links = options.delete(:per_page_links)
Chris@0 338 url_param = params.dup
Chris@0 339
Chris@0 340 html = ''
Chris@0 341 if paginator.current.previous
Chris@441 342 html << link_to_content_update('&#171; ' + l(:label_previous), url_param.merge(page_param => paginator.current.previous)) + ' '
Chris@0 343 end
Chris@0 344
Chris@0 345 html << (pagination_links_each(paginator, options) do |n|
Chris@441 346 link_to_content_update(n.to_s, url_param.merge(page_param => n))
Chris@0 347 end || '')
Chris@441 348
Chris@0 349 if paginator.current.next
Chris@441 350 html << ' ' + link_to_content_update((l(:label_next) + ' &#187;'), url_param.merge(page_param => paginator.current.next))
Chris@0 351 end
Chris@0 352
Chris@0 353 unless count.nil?
Chris@0 354 html << " (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})"
Chris@0 355 if per_page_links != false && links = per_page_links(paginator.items_per_page)
Chris@0 356 html << " | #{links}"
Chris@0 357 end
Chris@0 358 end
Chris@0 359
Chris@0 360 html
Chris@0 361 end
Chris@441 362
Chris@0 363 def per_page_links(selected=nil)
Chris@0 364 links = Setting.per_page_options_array.collect do |n|
Chris@441 365 n == selected ? n : link_to_content_update(n, params.merge(:per_page => n))
Chris@0 366 end
Chris@0 367 links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil
Chris@0 368 end
Chris@441 369
Chris@0 370 def reorder_links(name, url)
Chris@0 371 link_to(image_tag('2uparrow.png', :alt => l(:label_sort_highest)), url.merge({"#{name}[move_to]" => 'highest'}), :method => :post, :title => l(:label_sort_highest)) +
Chris@0 372 link_to(image_tag('1uparrow.png', :alt => l(:label_sort_higher)), url.merge({"#{name}[move_to]" => 'higher'}), :method => :post, :title => l(:label_sort_higher)) +
Chris@0 373 link_to(image_tag('1downarrow.png', :alt => l(:label_sort_lower)), url.merge({"#{name}[move_to]" => 'lower'}), :method => :post, :title => l(:label_sort_lower)) +
Chris@0 374 link_to(image_tag('2downarrow.png', :alt => l(:label_sort_lowest)), url.merge({"#{name}[move_to]" => 'lowest'}), :method => :post, :title => l(:label_sort_lowest))
Chris@0 375 end
Chris@0 376
Chris@0 377 def breadcrumb(*args)
Chris@0 378 elements = args.flatten
Chris@0 379 elements.any? ? content_tag('p', args.join(' &#187; ') + ' &#187; ', :class => 'breadcrumb') : nil
Chris@0 380 end
Chris@441 381
Chris@0 382 def other_formats_links(&block)
Chris@0 383 concat('<p class="other-formats">' + l(:label_export_to))
Chris@0 384 yield Redmine::Views::OtherFormatsBuilder.new(self)
Chris@0 385 concat('</p>')
Chris@0 386 end
Chris@441 387
Chris@0 388 def page_header_title
Chris@0 389 if @project.nil? || @project.new_record?
luisf@144 390 a = [h(Setting.app_title), '']
luisf@144 391
Chris@0 392 else
luisf@144 393 pname = []
Chris@0 394 b = []
Chris@441 395 ancestors = (@project.root? ? [] : @project.ancestors.visible.all)
Chris@0 396 if ancestors.any?
Chris@0 397 root = ancestors.shift
Chris@14 398 b << link_to_project(root, {:jump => current_menu_item}, :class => 'root')
Chris@0 399 if ancestors.size > 2
luisf@144 400 b << '&#8230;'
Chris@0 401 ancestors = ancestors[-2, 2]
Chris@0 402 end
Chris@14 403 b += ancestors.collect {|p| link_to_project(p, {:jump => current_menu_item}, :class => 'ancestor') }
luisf@144 404 b = b.join(' &#187; ')
luisf@144 405 b << (' &#187;')
Chris@0 406 end
luisf@144 407
luisf@144 408 pname << h(@project)
luisf@144 409
luisf@144 410 a = [pname, b]
luisf@144 411
Chris@0 412 end
Chris@0 413 end
Chris@0 414
Chris@0 415 def html_title(*args)
Chris@0 416 if args.empty?
Chris@0 417 title = []
Chris@0 418 title << @project.name if @project
Chris@0 419 title += @html_title if @html_title
Chris@0 420 title << Setting.app_title
Chris@0 421 title.select {|t| !t.blank? }.join(' - ')
Chris@0 422 else
Chris@0 423 @html_title ||= []
Chris@0 424 @html_title += args
Chris@0 425 end
Chris@0 426 end
Chris@0 427
Chris@14 428 # Returns the theme, controller name, and action as css classes for the
Chris@14 429 # HTML body.
Chris@14 430 def body_css_classes
Chris@14 431 css = []
Chris@14 432 if theme = Redmine::Themes.theme(Setting.ui_theme)
Chris@14 433 css << 'theme-' + theme.name
Chris@14 434 end
Chris@14 435
Chris@14 436 css << 'controller-' + params[:controller]
Chris@14 437 css << 'action-' + params[:action]
Chris@14 438 css.join(' ')
Chris@14 439 end
Chris@14 440
Chris@0 441 def accesskey(s)
Chris@0 442 Redmine::AccessKeys.key_for s
Chris@0 443 end
Chris@0 444
Chris@0 445 # Formats text according to system settings.
Chris@0 446 # 2 ways to call this method:
Chris@0 447 # * with a String: textilizable(text, options)
Chris@0 448 # * with an object and one of its attribute: textilizable(issue, :description, options)
Chris@0 449 def textilizable(*args)
Chris@0 450 options = args.last.is_a?(Hash) ? args.pop : {}
Chris@0 451 case args.size
Chris@0 452 when 1
Chris@0 453 obj = options[:object]
Chris@0 454 text = args.shift
Chris@0 455 when 2
Chris@0 456 obj = args.shift
Chris@0 457 attr = args.shift
Chris@0 458 text = obj.send(attr).to_s
Chris@0 459 else
Chris@0 460 raise ArgumentError, 'invalid arguments to textilizable'
Chris@0 461 end
Chris@0 462 return '' if text.blank?
Chris@0 463 project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
Chris@0 464 only_path = options.delete(:only_path) == false ? false : true
Chris@0 465
Chris@0 466 text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) { |macro, args| exec_macro(macro, obj, args) }
Chris@441 467
Chris@119 468 @parsed_headings = []
Chris@119 469 text = parse_non_pre_blocks(text) do |text|
chris@37 470 [:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links, :parse_headings].each do |method_name|
Chris@0 471 send method_name, text, project, obj, attr, only_path, options
Chris@0 472 end
Chris@0 473 end
Chris@441 474
Chris@119 475 if @parsed_headings.any?
Chris@119 476 replace_toc(text, @parsed_headings)
Chris@119 477 end
Chris@441 478
Chris@119 479 text
Chris@0 480 end
Chris@441 481
Chris@0 482 def parse_non_pre_blocks(text)
Chris@0 483 s = StringScanner.new(text)
Chris@0 484 tags = []
Chris@0 485 parsed = ''
Chris@0 486 while !s.eos?
Chris@0 487 s.scan(/(.*?)(<(\/)?(pre|code)(.*?)>|\z)/im)
Chris@0 488 text, full_tag, closing, tag = s[1], s[2], s[3], s[4]
Chris@0 489 if tags.empty?
Chris@0 490 yield text
Chris@0 491 end
Chris@0 492 parsed << text
Chris@0 493 if tag
Chris@0 494 if closing
Chris@0 495 if tags.last == tag.downcase
Chris@0 496 tags.pop
Chris@0 497 end
Chris@0 498 else
Chris@0 499 tags << tag.downcase
Chris@0 500 end
Chris@0 501 parsed << full_tag
Chris@0 502 end
Chris@0 503 end
Chris@0 504 # Close any non closing tags
Chris@0 505 while tag = tags.pop
Chris@0 506 parsed << "</#{tag}>"
Chris@0 507 end
Chris@0 508 parsed
Chris@0 509 end
Chris@441 510
Chris@0 511 def parse_inline_attachments(text, project, obj, attr, only_path, options)
Chris@0 512 # when using an image link, try to use an attachment, if possible
Chris@0 513 if options[:attachments] || (obj && obj.respond_to?(:attachments))
Chris@0 514 attachments = nil
Chris@0 515 text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m|
Chris@441 516 filename, ext, alt, alttext = $1.downcase, $2, $3, $4
Chris@0 517 attachments ||= (options[:attachments] || obj.attachments).sort_by(&:created_on).reverse
Chris@0 518 # search for the picture in attachments
Chris@0 519 if found = attachments.detect { |att| att.filename.downcase == filename }
Chris@0 520 image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found
Chris@0 521 desc = found.description.to_s.gsub('"', '')
Chris@0 522 if !desc.blank? && alttext.blank?
Chris@0 523 alt = " title=\"#{desc}\" alt=\"#{desc}\""
Chris@0 524 end
Chris@0 525 "src=\"#{image_url}\"#{alt}"
Chris@0 526 else
Chris@0 527 m
Chris@0 528 end
Chris@0 529 end
Chris@0 530 end
Chris@0 531 end
Chris@0 532
Chris@0 533 # Wiki links
Chris@0 534 #
Chris@0 535 # Examples:
Chris@0 536 # [[mypage]]
Chris@0 537 # [[mypage|mytext]]
Chris@0 538 # wiki links can refer other project wikis, using project name or identifier:
Chris@0 539 # [[project:]] -> wiki starting page
Chris@0 540 # [[project:|mytext]]
Chris@0 541 # [[project:mypage]]
Chris@0 542 # [[project:mypage|mytext]]
Chris@0 543 def parse_wiki_links(text, project, obj, attr, only_path, options)
Chris@0 544 text.gsub!(/(!)?(\[\[([^\]\n\|]+)(\|([^\]\n\|]+))?\]\])/) do |m|
Chris@0 545 link_project = project
Chris@0 546 esc, all, page, title = $1, $2, $3, $5
Chris@0 547 if esc.nil?
Chris@0 548 if page =~ /^([^\:]+)\:(.*)$/
chris@37 549 link_project = Project.find_by_identifier($1) || Project.find_by_name($1)
Chris@0 550 page = $2
Chris@0 551 title ||= $1 if page.blank?
Chris@0 552 end
Chris@0 553
Chris@0 554 if link_project && link_project.wiki
Chris@0 555 # extract anchor
Chris@0 556 anchor = nil
Chris@0 557 if page =~ /^(.+?)\#(.+)$/
Chris@0 558 page, anchor = $1, $2
Chris@0 559 end
Chris@0 560 # check if page exists
Chris@0 561 wiki_page = link_project.wiki.find_page(page)
Chris@0 562 url = case options[:wiki_links]
Chris@0 563 when :local; "#{title}.html"
Chris@0 564 when :anchor; "##{title}" # used for single-file wiki export
Chris@0 565 else
chris@37 566 wiki_page_id = page.present? ? Wiki.titleize(page) : nil
chris@37 567 url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project, :id => wiki_page_id, :anchor => anchor)
Chris@0 568 end
Chris@0 569 link_to((title || page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new')))
Chris@0 570 else
Chris@0 571 # project or wiki doesn't exist
Chris@0 572 all
Chris@0 573 end
Chris@0 574 else
Chris@0 575 all
Chris@0 576 end
Chris@0 577 end
Chris@0 578 end
Chris@441 579
Chris@0 580 # Redmine links
Chris@0 581 #
Chris@0 582 # Examples:
Chris@0 583 # Issues:
Chris@0 584 # #52 -> Link to issue #52
Chris@0 585 # Changesets:
Chris@0 586 # r52 -> Link to revision 52
Chris@0 587 # commit:a85130f -> Link to scmid starting with a85130f
Chris@0 588 # Documents:
Chris@0 589 # document#17 -> Link to document with id 17
Chris@0 590 # document:Greetings -> Link to the document with title "Greetings"
Chris@0 591 # document:"Some document" -> Link to the document with title "Some document"
Chris@0 592 # Versions:
Chris@0 593 # version#3 -> Link to version with id 3
Chris@0 594 # version:1.0.0 -> Link to version named "1.0.0"
Chris@0 595 # version:"1.0 beta 2" -> Link to version named "1.0 beta 2"
Chris@0 596 # Attachments:
Chris@0 597 # attachment:file.zip -> Link to the attachment of the current object named file.zip
Chris@0 598 # Source files:
Chris@0 599 # source:some/file -> Link to the file located at /some/file in the project's repository
Chris@0 600 # source:some/file@52 -> Link to the file's revision 52
Chris@0 601 # source:some/file#L120 -> Link to line 120 of the file
Chris@0 602 # source:some/file@52#L120 -> Link to line 120 of the file's revision 52
Chris@0 603 # export:some/file -> Force the download of the file
Chris@210 604 # Forum messages:
Chris@0 605 # message#1218 -> Link to message with id 1218
Chris@210 606 #
Chris@210 607 # Links can refer other objects from other projects, using project identifier:
Chris@210 608 # identifier:r52
Chris@210 609 # identifier:document:"Some document"
Chris@210 610 # identifier:version:1.0.0
Chris@210 611 # identifier:source:some/file
Chris@0 612 def parse_redmine_links(text, project, obj, attr, only_path, options)
Chris@210 613 text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(([a-z0-9\-]+):)?(attachment|document|version|commit|source|export|message|project)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|\]|<|$)}) do |m|
Chris@210 614 leading, esc, project_prefix, project_identifier, prefix, sep, identifier = $1, $2, $3, $4, $5, $7 || $9, $8 || $10
Chris@0 615 link = nil
Chris@210 616 if project_identifier
Chris@210 617 project = Project.visible.find_by_identifier(project_identifier)
Chris@210 618 end
Chris@0 619 if esc.nil?
Chris@0 620 if prefix.nil? && sep == 'r'
Chris@210 621 # project.changesets.visible raises an SQL error because of a double join on repositories
Chris@210 622 if project && project.repository && (changeset = Changeset.visible.find_by_repository_id_and_revision(project.repository.id, identifier))
Chris@210 623 link = link_to("#{project_prefix}r#{identifier}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
Chris@0 624 :class => 'changeset',
Chris@0 625 :title => truncate_single_line(changeset.comments, :length => 100))
Chris@0 626 end
Chris@0 627 elsif sep == '#'
Chris@0 628 oid = identifier.to_i
Chris@0 629 case prefix
Chris@0 630 when nil
Chris@0 631 if issue = Issue.visible.find_by_id(oid, :include => :status)
Chris@0 632 link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid},
Chris@0 633 :class => issue.css_classes,
Chris@0 634 :title => "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})")
Chris@0 635 end
Chris@0 636 when 'document'
Chris@210 637 if document = Document.visible.find_by_id(oid)
Chris@0 638 link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
Chris@0 639 :class => 'document'
Chris@0 640 end
Chris@0 641 when 'version'
Chris@210 642 if version = Version.visible.find_by_id(oid)
Chris@0 643 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
Chris@0 644 :class => 'version'
Chris@0 645 end
Chris@0 646 when 'message'
Chris@210 647 if message = Message.visible.find_by_id(oid, :include => :parent)
Chris@210 648 link = link_to_message(message, {:only_path => only_path}, :class => 'message')
Chris@0 649 end
Chris@0 650 when 'project'
Chris@0 651 if p = Project.visible.find_by_id(oid)
Chris@14 652 link = link_to_project(p, {:only_path => only_path}, :class => 'project')
Chris@0 653 end
Chris@0 654 end
Chris@0 655 elsif sep == ':'
Chris@0 656 # removes the double quotes if any
Chris@0 657 name = identifier.gsub(%r{^"(.*)"$}, "\\1")
Chris@0 658 case prefix
Chris@0 659 when 'document'
Chris@210 660 if project && document = project.documents.visible.find_by_title(name)
Chris@0 661 link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
Chris@0 662 :class => 'document'
Chris@0 663 end
Chris@0 664 when 'version'
Chris@210 665 if project && version = project.versions.visible.find_by_name(name)
Chris@0 666 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
Chris@0 667 :class => 'version'
Chris@0 668 end
Chris@0 669 when 'commit'
Chris@210 670 if project && project.repository && (changeset = Changeset.visible.find(:first, :conditions => ["repository_id = ? AND scmid LIKE ?", project.repository.id, "#{name}%"]))
Chris@210 671 link = link_to h("#{project_prefix}#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.identifier},
Chris@0 672 :class => 'changeset',
Chris@0 673 :title => truncate_single_line(changeset.comments, :length => 100)
Chris@0 674 end
Chris@0 675 when 'source', 'export'
Chris@210 676 if project && project.repository && User.current.allowed_to?(:browse_repository, project)
Chris@0 677 name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$}
Chris@0 678 path, rev, anchor = $1, $3, $5
Chris@210 679 link = link_to h("#{project_prefix}#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project,
Chris@0 680 :path => to_path_param(path),
Chris@0 681 :rev => rev,
Chris@0 682 :anchor => anchor,
Chris@0 683 :format => (prefix == 'export' ? 'raw' : nil)},
Chris@0 684 :class => (prefix == 'export' ? 'source download' : 'source')
Chris@0 685 end
Chris@0 686 when 'attachment'
Chris@0 687 attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil)
Chris@0 688 if attachments && attachment = attachments.detect {|a| a.filename == name }
Chris@0 689 link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment},
Chris@0 690 :class => 'attachment'
Chris@0 691 end
Chris@0 692 when 'project'
Chris@0 693 if p = Project.visible.find(:first, :conditions => ["identifier = :s OR LOWER(name) = :s", {:s => name.downcase}])
Chris@14 694 link = link_to_project(p, {:only_path => only_path}, :class => 'project')
Chris@0 695 end
Chris@0 696 end
Chris@0 697 end
Chris@0 698 end
Chris@210 699 leading + (link || "#{project_prefix}#{prefix}#{sep}#{identifier}")
Chris@0 700 end
Chris@0 701 end
Chris@441 702
chris@37 703 HEADING_RE = /<h(1|2|3|4)( [^>]+)?>(.+?)<\/h(1|2|3|4)>/i unless const_defined?(:HEADING_RE)
Chris@441 704
chris@37 705 # Headings and TOC
Chris@119 706 # Adds ids and links to headings unless options[:headings] is set to false
chris@37 707 def parse_headings(text, project, obj, attr, only_path, options)
Chris@119 708 return if options[:headings] == false
Chris@441 709
chris@37 710 text.gsub!(HEADING_RE) do
chris@37 711 level, attrs, content = $1.to_i, $2, $3
chris@37 712 item = strip_tags(content).strip
chris@37 713 anchor = item.gsub(%r{[^\w\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-')
Chris@119 714 @parsed_headings << [level, anchor, item]
Chris@441 715 "<a name=\"#{anchor}\"></a>\n<h#{level} #{attrs}>#{content}<a href=\"##{anchor}\" class=\"wiki-anchor\">&para;</a></h#{level}>"
Chris@119 716 end
Chris@119 717 end
Chris@441 718
Chris@119 719 TOC_RE = /<p>\{\{([<>]?)toc\}\}<\/p>/i unless const_defined?(:TOC_RE)
Chris@441 720
Chris@119 721 # Renders the TOC with given headings
Chris@119 722 def replace_toc(text, headings)
chris@37 723 text.gsub!(TOC_RE) do
chris@37 724 if headings.empty?
chris@37 725 ''
chris@37 726 else
chris@37 727 div_class = 'toc'
chris@37 728 div_class << ' right' if $1 == '>'
chris@37 729 div_class << ' left' if $1 == '<'
chris@37 730 out = "<ul class=\"#{div_class}\"><li>"
chris@37 731 root = headings.map(&:first).min
chris@37 732 current = root
chris@37 733 started = false
chris@37 734 headings.each do |level, anchor, item|
chris@37 735 if level > current
chris@37 736 out << '<ul><li>' * (level - current)
chris@37 737 elsif level < current
chris@37 738 out << "</li></ul>\n" * (current - level) + "</li><li>"
chris@37 739 elsif started
chris@37 740 out << '</li><li>'
chris@37 741 end
chris@37 742 out << "<a href=\"##{anchor}\">#{item}</a>"
chris@37 743 current = level
chris@37 744 started = true
chris@37 745 end
chris@37 746 out << '</li></ul>' * (current - root)
chris@37 747 out << '</li></ul>'
chris@37 748 end
chris@37 749 end
chris@37 750 end
Chris@0 751
Chris@0 752 # Same as Rails' simple_format helper without using paragraphs
Chris@0 753 def simple_format_without_paragraph(text)
Chris@0 754 text.to_s.
Chris@0 755 gsub(/\r\n?/, "\n"). # \r\n and \r -> \n
Chris@0 756 gsub(/\n\n+/, "<br /><br />"). # 2+ newline -> 2 br
Chris@0 757 gsub(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
Chris@0 758 end
Chris@0 759
Chris@0 760 def lang_options_for_select(blank=true)
Chris@0 761 (blank ? [["(auto)", ""]] : []) +
Chris@0 762 valid_languages.collect{|lang| [ ll(lang.to_s, :general_lang_name), lang.to_s]}.sort{|x,y| x.last <=> y.last }
Chris@0 763 end
Chris@0 764
Chris@0 765 def label_tag_for(name, option_tags = nil, options = {})
Chris@0 766 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
Chris@0 767 content_tag("label", label_text)
Chris@0 768 end
Chris@0 769
Chris@0 770 def labelled_tabular_form_for(name, object, options, &proc)
Chris@0 771 options[:html] ||= {}
Chris@0 772 options[:html][:class] = 'tabular' unless options[:html].has_key?(:class)
Chris@0 773 form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
Chris@0 774 end
Chris@0 775
Chris@0 776 def back_url_hidden_field_tag
Chris@0 777 back_url = params[:back_url] || request.env['HTTP_REFERER']
Chris@0 778 back_url = CGI.unescape(back_url.to_s)
Chris@0 779 hidden_field_tag('back_url', CGI.escape(back_url)) unless back_url.blank?
Chris@0 780 end
Chris@0 781
Chris@0 782 def check_all_links(form_name)
Chris@0 783 link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
Chris@0 784 " | " +
Chris@0 785 link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
Chris@0 786 end
Chris@0 787
Chris@0 788 def progress_bar(pcts, options={})
Chris@0 789 pcts = [pcts, pcts] unless pcts.is_a?(Array)
Chris@0 790 pcts = pcts.collect(&:round)
Chris@0 791 pcts[1] = pcts[1] - pcts[0]
Chris@0 792 pcts << (100 - pcts[1] - pcts[0])
Chris@0 793 width = options[:width] || '100px;'
Chris@0 794 legend = options[:legend] || ''
Chris@0 795 content_tag('table',
Chris@0 796 content_tag('tr',
Chris@0 797 (pcts[0] > 0 ? content_tag('td', '', :style => "width: #{pcts[0]}%;", :class => 'closed') : '') +
Chris@0 798 (pcts[1] > 0 ? content_tag('td', '', :style => "width: #{pcts[1]}%;", :class => 'done') : '') +
Chris@0 799 (pcts[2] > 0 ? content_tag('td', '', :style => "width: #{pcts[2]}%;", :class => 'todo') : '')
Chris@0 800 ), :class => 'progress', :style => "width: #{width};") +
Chris@0 801 content_tag('p', legend, :class => 'pourcent')
Chris@0 802 end
Chris@441 803
Chris@0 804 def checked_image(checked=true)
Chris@0 805 if checked
Chris@0 806 image_tag 'toggle_check.png'
Chris@0 807 end
Chris@0 808 end
Chris@441 809
Chris@0 810 def context_menu(url)
Chris@0 811 unless @context_menu_included
Chris@0 812 content_for :header_tags do
Chris@0 813 javascript_include_tag('context_menu') +
Chris@0 814 stylesheet_link_tag('context_menu')
Chris@0 815 end
Chris@14 816 if l(:direction) == 'rtl'
Chris@14 817 content_for :header_tags do
Chris@14 818 stylesheet_link_tag('context_menu_rtl')
Chris@14 819 end
Chris@14 820 end
Chris@0 821 @context_menu_included = true
Chris@0 822 end
Chris@0 823 javascript_tag "new ContextMenu('#{ url_for(url) }')"
Chris@0 824 end
Chris@0 825
Chris@0 826 def context_menu_link(name, url, options={})
Chris@0 827 options[:class] ||= ''
Chris@0 828 if options.delete(:selected)
Chris@0 829 options[:class] << ' icon-checked disabled'
Chris@0 830 options[:disabled] = true
Chris@0 831 end
Chris@0 832 if options.delete(:disabled)
Chris@0 833 options.delete(:method)
Chris@0 834 options.delete(:confirm)
Chris@0 835 options.delete(:onclick)
Chris@0 836 options[:class] << ' disabled'
Chris@0 837 url = '#'
Chris@0 838 end
Chris@0 839 link_to name, url, options
Chris@0 840 end
Chris@0 841
Chris@0 842 def calendar_for(field_id)
Chris@0 843 include_calendar_headers_tags
Chris@0 844 image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) +
Chris@0 845 javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });")
Chris@0 846 end
Chris@0 847
Chris@0 848 def include_calendar_headers_tags
Chris@0 849 unless @calendar_headers_tags_included
Chris@0 850 @calendar_headers_tags_included = true
Chris@0 851 content_for :header_tags do
Chris@0 852 start_of_week = case Setting.start_of_week.to_i
Chris@0 853 when 1
Chris@0 854 'Calendar._FD = 1;' # Monday
Chris@0 855 when 7
Chris@0 856 'Calendar._FD = 0;' # Sunday
Chris@441 857 when 6
Chris@441 858 'Calendar._FD = 6;' # Saturday
Chris@0 859 else
Chris@0 860 '' # use language
Chris@0 861 end
Chris@441 862
Chris@0 863 javascript_include_tag('calendar/calendar') +
Chris@0 864 javascript_include_tag("calendar/lang/calendar-#{current_language.to_s.downcase}.js") +
Chris@441 865 javascript_tag(start_of_week) +
Chris@0 866 javascript_include_tag('calendar/calendar-setup') +
Chris@0 867 stylesheet_link_tag('calendar')
Chris@0 868 end
Chris@0 869 end
Chris@0 870 end
Chris@0 871
Chris@0 872 def content_for(name, content = nil, &block)
Chris@0 873 @has_content ||= {}
Chris@0 874 @has_content[name] = true
Chris@0 875 super(name, content, &block)
Chris@0 876 end
Chris@0 877
Chris@0 878 def has_content?(name)
Chris@0 879 (@has_content && @has_content[name]) || false
Chris@0 880 end
Chris@0 881
Chris@0 882 # Returns the avatar image tag for the given +user+ if avatars are enabled
Chris@0 883 # +user+ can be a User or a string that will be scanned for an email address (eg. 'joe <joe@foo.bar>')
Chris@0 884 def avatar(user, options = { })
Chris@0 885 if Setting.gravatar_enabled?
chris@22 886 options.merge!({:ssl => (defined?(request) && request.ssl?), :default => Setting.gravatar_default})
Chris@0 887 email = nil
Chris@0 888 if user.respond_to?(:mail)
Chris@0 889 email = user.mail
Chris@0 890 elsif user.to_s =~ %r{<(.+?)>}
Chris@0 891 email = $1
Chris@0 892 end
Chris@0 893 return gravatar(email.to_s.downcase, options) unless email.blank? rescue nil
chris@22 894 else
chris@22 895 ''
Chris@0 896 end
Chris@0 897 end
Chris@441 898
Chris@245 899 # Returns the javascript tags that are included in the html layout head
Chris@245 900 def javascript_heads
Chris@245 901 tags = javascript_include_tag(:defaults)
Chris@245 902 unless User.current.pref.warn_on_leaving_unsaved == '0'
Chris@245 903 tags << "\n" + javascript_tag("Event.observe(window, 'load', function(){ new WarnLeavingUnsaved('#{escape_javascript( l(:text_warn_on_leaving_unsaved) )}'); });")
Chris@245 904 end
Chris@245 905 tags
Chris@245 906 end
Chris@0 907
Chris@14 908 def favicon
Chris@14 909 "<link rel='shortcut icon' href='#{image_path('/favicon.ico')}' />"
Chris@14 910 end
Chris@441 911
Chris@441 912 def robot_exclusion_tag
Chris@441 913 '<meta name="robots" content="noindex,follow,noarchive" />'
Chris@441 914 end
Chris@441 915
chris@503 916 def stylesheet_platform_font_tag
chris@503 917 agent = request.env['HTTP_USER_AGENT']
chris@503 918 name = 'fonts-generic'
chris@503 919 if agent and agent =~ %r{Windows}
chris@503 920 name = 'fonts-ms'
chris@503 921 elsif agent and agent =~ %r{Macintosh}
chris@503 922 name = 'fonts-mac'
chris@503 923 end
chris@503 924 stylesheet_link_tag name, :media => 'all'
chris@503 925 end
chris@503 926
Chris@119 927 # Returns true if arg is expected in the API response
Chris@119 928 def include_in_api_response?(arg)
Chris@119 929 unless @included_in_api_response
Chris@119 930 param = params[:include]
Chris@119 931 @included_in_api_response = param.is_a?(Array) ? param.collect(&:to_s) : param.to_s.split(',')
Chris@119 932 @included_in_api_response.collect!(&:strip)
Chris@119 933 end
Chris@119 934 @included_in_api_response.include?(arg.to_s)
Chris@119 935 end
Chris@14 936
Chris@119 937 # Returns options or nil if nometa param or X-Redmine-Nometa header
Chris@119 938 # was set in the request
Chris@119 939 def api_meta(options)
Chris@119 940 if params[:nometa].present? || request.headers['X-Redmine-Nometa']
Chris@119 941 # compatibility mode for activeresource clients that raise
Chris@119 942 # an error when unserializing an array with attributes
Chris@119 943 nil
Chris@119 944 else
Chris@119 945 options
Chris@119 946 end
Chris@119 947 end
Chris@441 948
Chris@0 949 private
Chris@0 950
Chris@0 951 def wiki_helper
Chris@0 952 helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting)
Chris@0 953 extend helper
Chris@0 954 return self
Chris@0 955 end
Chris@441 956
Chris@441 957 def link_to_content_update(text, url_params = {}, html_options = {})
Chris@441 958 link_to(text, url_params, html_options)
Chris@0 959 end
Chris@0 960 end