0002-Nest-the-exported-html-table-of-contents.patch

Mizuki ISHIKAWA, 2018-03-08 06:20

Download (4.49 KB)

View differences:

app/helpers/application_helper.rb
317 317
      content << "<ul class=\"pages-hierarchy\">\n"
318 318
      pages[node].each do |page|
319 319
        content << "<li>"
320
        content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'show', :project_id => page.project, :id => page.title, :version => nil},
320
        if controller.controller_name == 'wiki' && controller.action_name == 'export'
321
          href = "##{page.title}"
322
        else
323
          href = {:controller => 'wiki', :action => 'show', :project_id => page.project, :id => page.title, :version => nil}
324
        end
325
        content << link_to(h(page.pretty_title), href,
321 326
                           :title => (options[:timestamp] && page.updated_on ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil))
322 327
        content << "\n" + render_page_hierarchy(pages, page.id, options) if pages[page.id]
323 328
        content << "</li>\n"
app/views/wiki/export_multiple.html.erb
18 18
<body>
19 19

  
20 20
<strong><%= l(:label_index_by_title) %></strong>
21
<ul>
22
<% @pages.each do |page| %>
23
    <li><a href="#<%= page.title %>"><%= page.pretty_title %></a></li>
24
<% end %>
25
</ul>
21
<%= render_page_hierarchy(@pages.group_by(&:parent_id), nil, :timestamp => true) %>
26 22

  
27 23
<% @pages.each do |page| %>
28 24
<hr />
test/helpers/application_helper_test.rb
1286 1286
    end
1287 1287
  end
1288 1288

  
1289
  def test_render_page_hierarchy
1290
    parent_page = WikiPage.find(1)
1291
    child_page = WikiPage.find_by(parent_id: parent_page.id)
1292
    pages_by_parent_id = { nil =>[parent_page], parent_page.id => [child_page] }
1293
    result = render_page_hierarchy(pages_by_parent_id, nil)
1294
    assert_select_in result, 'ul.pages-hierarchy li a[href=?]', project_wiki_page_path(project_id: parent_page.project, id: parent_page.title, version: nil )
1295
    assert_select_in result, 'ul.pages-hierarchy li ul.pages-hierarchy a[href=?]', project_wiki_page_path(project_id: child_page.project, id: child_page.title, version: nil )
1296
  end
1297

  
1298
  def test_render_page_hierarchy_with_options_timestamp_should_include_timestamp
1299
    parent_page = WikiPage.find(1)
1300
    child_page = WikiPage.find_by(parent_id: parent_page.id)
1301
    pages_by_parent_id = { nil =>[parent_page], parent_page.id => [child_page] }
1302
    result = render_page_hierarchy(pages_by_parent_id, nil, :timestamp => true)
1303
    assert_select_in result, 'ul.pages-hierarchy li a[title=?]', l(:label_updated_time, distance_of_time_in_words(Time.now, parent_page.updated_on))
1304
    assert_select_in result, 'ul.pages-hierarchy li ul.pages-hierarchy a[title=?]', l(:label_updated_time, distance_of_time_in_words(Time.now, child_page.updated_on))
1305
  end
1306

  
1307
  def test_render_page_hierarchy_when_action_is_export
1308
    parent_page = WikiPage.find(1)
1309
    child_page = WikiPage.find_by(parent_id: parent_page.id)
1310
    pages_by_parent_id = { nil =>[parent_page], parent_page.id => [child_page] }
1311

  
1312
    # Change controller and action using stub
1313
    controller.stubs(:controller_name).returns('wiki')
1314
    controller.stubs(:action_name).returns("export")
1315

  
1316
    result = render_page_hierarchy(pages_by_parent_id, nil)
1317
    assert_select_in result, 'ul.pages-hierarchy li a[href=?]', "##{parent_page.title}"
1318
    assert_select_in result, 'ul.pages-hierarchy li ul.pages-hierarchy a[href=?]', "##{child_page.title}"
1319
  end
1320

  
1289 1321
  def test_avatar_enabled
1290 1322
    tag_for_anonymous_re = %r{src="/images/anonymous.png(\?\d+)?"}
1291 1323
    with_settings :gravatar_enabled => '1' do
1292
-