Project

General

Profile

Defect #39755 ยป 39755.patch

Go MAEDA, 2023-12-01 03:19

View differences:

lib/redmine/wiki_formatting/common_mark/helper.rb
23 23
      module Helper
24 24
        def wikitoolbar_for(field_id, preview_url = preview_text_path)
25 25
          heads_for_wiki_formatter
26
          help_file = "/help/#{current_language.to_s.downcase}/wiki_syntax_common_mark.html"
27
          # fall back to the english help page if there is none for the current
28
          # language
29
          unless File.readable? Rails.public_path.join(help_file)
30
            help_file = "/help/en/wiki_syntax_common_mark.html"
31
          end
32
          url = "#{Redmine::Utils.relative_url_root}#{help_file}"
26
          url = help_path(current_language)
27

  
33 28
          javascript_tag(
34 29
            "var wikiToolbar = new jsToolBar(document.getElementById('#{field_id}')); " \
35 30
            "wikiToolbar.setHelpLink('#{escape_javascript url}'); " \
......
38 33
          )
39 34
        end
40 35

  
36
        def help_path(lang)
37
          help_file = "help/#{lang.to_s.downcase}/wiki_syntax_common_mark.html"
38
          # fall back to the english help page if there is none for the current
39
          # language
40
          unless Rails.public_path.join(help_file).readable?
41
            help_file = "help/en/wiki_syntax_common_mark.html"
42
          end
43
          File.join(Redmine::Utils.relative_url_root, help_file)
44
        end
45

  
41 46
        def initial_page_content(page)
42 47
          "# #{@page.pretty_title}"
43 48
        end
test/unit/lib/redmine/wiki_formatting/common_mark/helper_test.rb
1
# frozen_string_literal: true
2

  
3
# Redmine - project management software
4
# Copyright (C) 2006-2023  Jean-Philippe Lang
5
#
6
# This program is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU General Public License
8
# as published by the Free Software Foundation; either version 2
9
# of the License, or (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19

  
20
require_relative '../../../../../test_helper'
21

  
22
class Redmine::WikiFormatting::CommonMark::HelperTest < Redmine::HelperTest
23
  if Object.const_defined?(:CommonMarker)
24

  
25
    def test_help_path_should_reflect_language
26
      assert_equal '/help/de/wiki_syntax_common_mark.html', help_path('de')
27
    end
28

  
29
    def test_help_path_should_fallback_to_english
30
      assert_equal '/help/en/wiki_syntax_common_mark.html', help_path('xx')
31
    end
32
  end
33
end
    (1-1/1)