You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

helper.rb 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2022 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. module Redmine
  19. module WikiFormatting
  20. module CommonMark
  21. module Helper
  22. def wikitoolbar_for(field_id, preview_url = preview_text_path)
  23. heads_for_wiki_formatter
  24. help_file = "/help/#{current_language.to_s.downcase}/wiki_syntax_common_mark.html"
  25. # fall back to the english help page if there is none for the current
  26. # language
  27. unless File.readable? Rails.root.join("public", help_file)
  28. help_file = "/help/en/wiki_syntax_common_mark.html"
  29. end
  30. url = "#{Redmine::Utils.relative_url_root}#{help_file}"
  31. javascript_tag(
  32. "var wikiToolbar = new jsToolBar(document.getElementById('#{field_id}')); " \
  33. "wikiToolbar.setHelpLink('#{escape_javascript url}'); " \
  34. "wikiToolbar.setPreviewUrl('#{escape_javascript preview_url}'); " \
  35. "wikiToolbar.draw();"
  36. )
  37. end
  38. def initial_page_content(page)
  39. "# #{@page.pretty_title}"
  40. end
  41. def heads_for_wiki_formatter
  42. unless @heads_for_wiki_formatter_included
  43. toolbar_language_options = User.current && User.current.pref.toolbar_language_options
  44. lang =
  45. if toolbar_language_options.nil?
  46. UserPreference::DEFAULT_TOOLBAR_LANGUAGE_OPTIONS
  47. else
  48. toolbar_language_options.split(',')
  49. end
  50. content_for :header_tags do
  51. javascript_include_tag('jstoolbar/jstoolbar') +
  52. javascript_include_tag('jstoolbar/common_mark') +
  53. javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language.to_s.downcase}") +
  54. javascript_tag(
  55. "var wikiImageMimeTypes = #{Redmine::MimeType.by_type('image').to_json};" \
  56. "var userHlLanguages = #{lang.to_json};"
  57. ) +
  58. stylesheet_link_tag('jstoolbar')
  59. end
  60. @heads_for_wiki_formatter_included = true
  61. end
  62. end
  63. end
  64. end
  65. end
  66. end