Project

General

Profile

Defect #12981 ยป 12981.diff

Vadim Pushtaev, 2013-11-14 08:29

View differences:

app/helpers/application_helper.rb
630 630
          anchor = sanitize_anchor_name(anchor) if anchor.present?
631 631
          # check if page exists
632 632
          wiki_page = link_project.wiki.find_page(page)
633
          url = if anchor.present? && wiki_page.present? && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)) && obj.page == wiki_page
634
            "##{anchor}"
635
          else
636
            case options[:wiki_links]
637
            when :local; "#{page.present? ? Wiki.titleize(page) : ''}.html" + (anchor.present? ? "##{anchor}" : '')
638
            when :anchor; "##{page.present? ? Wiki.titleize(page) : title}" + (anchor.present? ? "_#{anchor}" : '') # used for single-file wiki export
633
          wiki_links = options[:wiki_links]
634
          url = case
635
            when wiki_links != :full && anchor.present? && wiki_page.present? &&
636
             (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)) && obj.page == wiki_page
637
              "##{anchor}"
638
            when wiki_links == :local
639
              "#{page.present? ? Wiki.titleize(page) : ''}.html" + (anchor.present? ? "##{anchor}" : '')
640
            when wiki_links == :anchor
641
              "##{page.present? ? Wiki.titleize(page) : title}" + (anchor.present? ? "_#{anchor}" : '') # used for single-file wiki export
639 642
            else
640 643
              wiki_page_id = page.present? ? Wiki.titleize(page) : nil
641 644
              parent = wiki_page.nil? && obj.is_a?(WikiContent) && obj.page && project == link_project ? obj.page.title : nil
642 645
              url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project,
643 646
               :id => wiki_page_id, :version => nil, :anchor => anchor, :parent => parent)
644
            end
645 647
          end
646 648
          link_to(title.present? ? title.html_safe : h(page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new')))
647 649
        else
app/views/common/_preview.html.erb
1 1
<fieldset class="preview"><legend><%= l(:label_preview) %></legend>
2
<%= textilizable @text, :attachments => @attachments, :object => @previewed %>
2
<%= textilizable @text, :attachments => @attachments, :object => @previewed, :wiki_links => :full %>
3 3
</fieldset>
test/unit/helpers/application_helper_test.rb
678 678
    to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(WikiContent.new( :text => text, :page => page ), :text) }
679 679
  end
680 680

  
681
  def test_wiki_links_within_wiki_page_context_with_wiki_links_full_param
682

  
683
    page = WikiPage.find_by_title('Another_page' )
684

  
685
    to_test = {
686
      # link to another page
687
      '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
688
      '[[CookBook documentation|documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">documentation</a>',
689
      '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>',
690
      '[[CookBook documentation#One-section|documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">documentation</a>',
691
      # link to the current page
692
      '[[Another page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Another page</a>',
693
      '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>',
694
      '[[Another page#anchor]]' => '<a href="/projects/ecookbook/wiki/Another_page#anchor" class="wiki-page">Another page</a>',
695
      '[[Another page#anchor|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page#anchor" class="wiki-page">Page</a>',
696
      # page that doesn't exist
697
      '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page" class="wiki-page new">Unknown page</a>',
698
      '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page" class="wiki-page new">404</a>',
699
      '[[Unknown page#anchor]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page#anchor" class="wiki-page new">Unknown page</a>',
700
      '[[Unknown page#anchor|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page#anchor" class="wiki-page new">404</a>',
701
    }
702

  
703
    @project = Project.find(1)
704

  
705
    to_test.each { |text, result|
706
      assert_equal "<p>#{result}</p>", textilizable(WikiContent.new( :text => text, :page => page ), :text, :wiki_links=> :full )
707
    }
708
  end
709

  
681 710
  def test_wiki_links_anchor_option_should_prepend_page_title_to_href
682 711

  
683 712
    to_test = {
    (1-1/1)