##// END OF EJS Templates
Extract parsing of inline attachments, wiki links and redmine links....
Jean-Philippe Lang -
r3474:a179f261cde4
parent child
Show More
@@ -405,11 +405,19 module ApplicationHelper
405 405 raise ArgumentError, 'invalid arguments to textilizable'
406 406 end
407 407 return '' if text.blank?
408 project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
409 only_path = options.delete(:only_path) == false ? false : true
408 410
409 411 text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) { |macro, args| exec_macro(macro, obj, args) }
410 412
411 only_path = options.delete(:only_path) == false ? false : true
413 [:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links].each do |method_name|
414 send method_name, text, project, obj, attr, only_path, options
415 end
412 416
417 text
418 end
419
420 def parse_inline_attachments(text, project, obj, attr, only_path, options)
413 421 # when using an image link, try to use an attachment, if possible
414 422 if options[:attachments] || (obj && obj.respond_to?(:attachments))
415 423 attachments = nil
@@ -429,22 +437,8 module ApplicationHelper
429 437 end
430 438 end
431 439 end
432
433
434 # different methods for formatting wiki links
435 case options[:wiki_links]
436 when :local
437 # used for local links to html files
438 format_wiki_link = Proc.new {|project, title, anchor| "#{title}.html" }
439 when :anchor
440 # used for single-file wiki export
441 format_wiki_link = Proc.new {|project, title, anchor| "##{title}" }
442 else
443 format_wiki_link = Proc.new {|project, title, anchor| url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => project, :page => title, :anchor => anchor) }
444 440 end
445 441
446 project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
447
448 442 # Wiki links
449 443 #
450 444 # Examples:
@@ -455,7 +449,8 module ApplicationHelper
455 449 # [[project:|mytext]]
456 450 # [[project:mypage]]
457 451 # [[project:mypage|mytext]]
458 text = text.gsub(/(!)?(\[\[([^\]\n\|]+)(\|([^\]\n\|]+))?\]\])/) do |m|
452 def parse_wiki_links(text, project, obj, attr, only_path, options)
453 text.gsub!(/(!)?(\[\[([^\]\n\|]+)(\|([^\]\n\|]+))?\]\])/) do |m|
459 454 link_project = project
460 455 esc, all, page, title = $1, $2, $3, $5
461 456 if esc.nil?
@@ -473,8 +468,13 module ApplicationHelper
473 468 end
474 469 # check if page exists
475 470 wiki_page = link_project.wiki.find_page(page)
476 link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page), anchor),
477 :class => ('wiki-page' + (wiki_page ? '' : ' new')))
471 url = case options[:wiki_links]
472 when :local; "#{title}.html"
473 when :anchor; "##{title}" # used for single-file wiki export
474 else
475 url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => link_project, :page => Wiki.titleize(page), :anchor => anchor)
476 end
477 link_to((title || page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new')))
478 478 else
479 479 # project or wiki doesn't exist
480 480 all
@@ -483,6 +483,7 module ApplicationHelper
483 483 all
484 484 end
485 485 end
486 end
486 487
487 488 # Redmine links
488 489 #
@@ -510,7 +511,8 module ApplicationHelper
510 511 # export:some/file -> Force the download of the file
511 512 # Forum messages:
512 513 # message#1218 -> Link to message with id 1218
513 text = text.gsub(%r{([\s\(,\-\>]|^)(!)?(attachment|document|version|commit|source|export|message|project)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|<|$)}) do |m|
514 def parse_redmine_links(text, project, obj, attr, only_path, options)
515 text.gsub!(%r{([\s\(,\-\>]|^)(!)?(attachment|document|version|commit|source|export|message|project)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|<|$)}) do |m|
514 516 leading, esc, prefix, sep, identifier = $1, $2, $3, $5 || $7, $6 || $8
515 517 link = nil
516 518 if esc.nil?
@@ -602,8 +604,6 module ApplicationHelper
602 604 end
603 605 leading + (link || "#{prefix}#{sep}#{identifier}")
604 606 end
605
606 text
607 607 end
608 608
609 609 # Same as Rails' simple_format helper without using paragraphs
General Comments 0
You need to be logged in to leave comments. Login now