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.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006- 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. javascript_tag(
  25. "var wikiToolbar = new jsToolBar(document.getElementById('#{field_id}')); " \
  26. "wikiToolbar.setHelpLink('#{escape_javascript help_wiki_syntax_path}'); " \
  27. "wikiToolbar.setPreviewUrl('#{escape_javascript preview_url}'); " \
  28. "wikiToolbar.draw();"
  29. )
  30. end
  31. def initial_page_content(page)
  32. "# #{@page.pretty_title}"
  33. end
  34. def heads_for_wiki_formatter
  35. unless @heads_for_wiki_formatter_included
  36. toolbar_language_options = User.current && User.current.pref.toolbar_language_options
  37. lang =
  38. if toolbar_language_options.nil?
  39. UserPreference::DEFAULT_TOOLBAR_LANGUAGE_OPTIONS
  40. else
  41. toolbar_language_options.split(',')
  42. end
  43. content_for :header_tags do
  44. javascript_include_tag('jstoolbar/jstoolbar') +
  45. javascript_include_tag('jstoolbar/common_mark') +
  46. javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language.to_s.downcase}") +
  47. javascript_tag(
  48. "var wikiImageMimeTypes = #{Redmine::MimeType.by_type('image').to_json};" \
  49. "var userHlLanguages = #{lang.to_json};"
  50. ) +
  51. stylesheet_link_tag('jstoolbar')
  52. end
  53. @heads_for_wiki_formatter_included = true
  54. end
  55. end
  56. end
  57. end
  58. end
  59. end