@@ -405,11 +405,19 module ApplicationHelper | |||||
405 | raise ArgumentError, 'invalid arguments to textilizable' |
|
405 | raise ArgumentError, 'invalid arguments to textilizable' | |
406 | end |
|
406 | end | |
407 | return '' if text.blank? |
|
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 | text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) { |macro, args| exec_macro(macro, obj, args) } |
|
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 | # when using an image link, try to use an attachment, if possible |
|
421 | # when using an image link, try to use an attachment, if possible | |
414 | if options[:attachments] || (obj && obj.respond_to?(:attachments)) |
|
422 | if options[:attachments] || (obj && obj.respond_to?(:attachments)) | |
415 | attachments = nil |
|
423 | attachments = nil | |
@@ -429,22 +437,8 module ApplicationHelper | |||||
429 | end |
|
437 | end | |
430 | end |
|
438 | end | |
431 | end |
|
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 | link_project = project |
|
454 | link_project = project | |
460 | esc, all, page, title = $1, $2, $3, $5 |
|
455 | esc, all, page, title = $1, $2, $3, $5 | |
461 | if esc.nil? |
|
456 | if esc.nil? | |
@@ -473,8 +468,13 module ApplicationHelper | |||||
473 | end |
|
468 | end | |
474 | # check if page exists |
|
469 | # check if page exists | |
475 | wiki_page = link_project.wiki.find_page(page) |
|
470 | wiki_page = link_project.wiki.find_page(page) | |
476 | link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page), anchor), |
|
471 | url = case options[:wiki_links] | |
477 | :class => ('wiki-page' + (wiki_page ? '' : ' new'))) |
|
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 | else |
|
478 | else | |
479 | # project or wiki doesn't exist |
|
479 | # project or wiki doesn't exist | |
480 | all |
|
480 | all | |
@@ -483,6 +483,7 module ApplicationHelper | |||||
483 | all |
|
483 | all | |
484 | end |
|
484 | end | |
485 | end |
|
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 | leading, esc, prefix, sep, identifier = $1, $2, $3, $5 || $7, $6 || $8 |
|
516 | leading, esc, prefix, sep, identifier = $1, $2, $3, $5 || $7, $6 || $8 | |
515 | link = nil |
|
517 | link = nil | |
516 | if esc.nil? |
|
518 | if esc.nil? | |
@@ -602,8 +604,6 module ApplicationHelper | |||||
602 | end |
|
604 | end | |
603 | leading + (link || "#{prefix}#{sep}#{identifier}") |
|
605 | leading + (link || "#{prefix}#{sep}#{identifier}") | |
604 | end |
|
606 | end | |
605 |
|
||||
606 | text |
|
|||
607 | end |
|
607 | end | |
608 |
|
608 | |||
609 | # Same as Rails' simple_format helper without using paragraphs |
|
609 | # Same as Rails' simple_format helper without using paragraphs |
General Comments 0
You need to be logged in to leave comments.
Login now