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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 Textile
  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}'); wikiToolbar.draw();"
  28. )
  29. end
  30. def initial_page_content(page)
  31. "h1. #{page.pretty_title}"
  32. end
  33. def heads_for_wiki_formatter
  34. unless @heads_for_wiki_formatter_included
  35. toolbar_language_options = User.current && User.current.pref.toolbar_language_options
  36. lang =
  37. if toolbar_language_options.nil?
  38. UserPreference::DEFAULT_TOOLBAR_LANGUAGE_OPTIONS
  39. else
  40. toolbar_language_options.split(',')
  41. end
  42. content_for :header_tags do
  43. javascript_include_tag('jstoolbar/jstoolbar') +
  44. javascript_include_tag('jstoolbar/textile') +
  45. javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language.to_s.downcase}") +
  46. javascript_tag(
  47. "var wikiImageMimeTypes = #{Redmine::MimeType.by_type('image').to_json};" \
  48. "var userHlLanguages = #{lang.to_json};") +
  49. stylesheet_link_tag('jstoolbar')
  50. end
  51. @heads_for_wiki_formatter_included = true
  52. end
  53. end
  54. end
  55. end
  56. end
  57. end