feature-32528.patch

Mizuki ISHIKAWA, 2019-11-29 03:24

Download (6.85 KB)

View differences:

app/models/user_preference.rb
35 35
    'no_self_notified',
36 36
    'textarea_font',
37 37
    'recently_used_projects',
38
    'history_default_tab')
38
    'history_default_tab',
39
    'code_highlighting_languages')
39 40

  
40 41
  TEXTAREA_FONT_OPTIONS = ['monospace', 'proportional']
42
  DEFAULT_CODE_HIGHLIGHTING_LANGUAGES = %w[c cpp csharp css diff go groovy html java javascript objc perl php python r ruby sass scala shell sql swift xml yaml]
41 43

  
42 44
  def initialize(attributes=nil, *args)
43 45
    super
......
98 100
  def history_default_tab; self[:history_default_tab]; end
99 101
  def history_default_tab=(value); self[:history_default_tab]=value; end
100 102

  
103
  def code_highlighting_languages; self[:code_highlighting_languages]; end
104
  def code_highlighting_languages=(value)
105
    languages = value.to_s.gsub(' ', '').split(',').select{|lang| Redmine::SyntaxHighlighting.language_supported?(lang) }.compact
106
    self[:code_highlighting_languages] = languages.join(',')
107
  end
108

  
101 109
  # Returns the names of groups that are displayed on user's page
102 110
  # Example:
103 111
  #   preferences.my_page_groups
app/views/users/_preferences.html.erb
6 6
<p><%= pref_fields.select :textarea_font, textarea_font_options %></p>
7 7
<p><%= pref_fields.text_field :recently_used_projects, :size => 2 %></p>
8 8
<p><%= pref_fields.select :history_default_tab, history_default_tab_options %></p>
9
<p><%= pref_fields.text_area :code_highlighting_languages, :placeholder => UserPreference::DEFAULT_CODE_HIGHLIGHTING_LANGUAGES.join(','), :rows => 4 %></p>
9 10
<% end %>
config/locales/en.yml
389 389
  field_recently_used_projects: Number of recently used projects in jump box
390 390
  field_history_default_tab: Issue's history default tab
391 391
  field_unique_id: Unique ID
392
  field_code_highlighting_languages: Code highlighting languages menu
392 393

  
393 394
  setting_app_title: Application title
394 395
  setting_welcome_text: Welcome text
lib/redmine/wiki_formatting/markdown/helper.rb
33 33

  
34 34
        def heads_for_wiki_formatter
35 35
          unless @heads_for_wiki_formatter_included
36
            code_highlighting_languages = User.current && User.current.pref.code_highlighting_languages.presence
36 37
            content_for :header_tags do
37 38
              javascript_include_tag('jstoolbar/jstoolbar') +
38 39
              javascript_include_tag('jstoolbar/markdown') +
39 40
              javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language.to_s.downcase}") +
40
              javascript_tag("var wikiImageMimeTypes = #{Redmine::MimeType.by_type('image').to_json};") +
41
              javascript_tag("var wikiImageMimeTypes = #{Redmine::MimeType.by_type('image').to_json};" +
42
                             "var userHlLanguages = #{(code_highlighting_languages.nil? ? UserPreference::DEFAULT_CODE_HIGHLIGHTING_LANGUAGES : code_highlighting_languages.split(',')).to_json};") +
41 43
              stylesheet_link_tag('jstoolbar')
42 44
            end
43 45
            @heads_for_wiki_formatter_included = true
lib/redmine/wiki_formatting/textile/helper.rb
34 34

  
35 35
        def heads_for_wiki_formatter
36 36
          unless @heads_for_wiki_formatter_included
37
            code_highlighting_languages = User.current && User.current.pref.code_highlighting_languages.presence
37 38
            content_for :header_tags do
38 39
              javascript_include_tag('jstoolbar/jstoolbar') +
39 40
              javascript_include_tag('jstoolbar/textile') +
40 41
              javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language.to_s.downcase}") +
41
              javascript_tag("var wikiImageMimeTypes = #{Redmine::MimeType.by_type('image').to_json};") +
42
              javascript_tag("var wikiImageMimeTypes = #{Redmine::MimeType.by_type('image').to_json};" +
43
                             "var userHlLanguages = #{(code_highlighting_languages.nil? ? UserPreference::DEFAULT_CODE_HIGHLIGHTING_LANGUAGES : code_highlighting_languages.split(',')).to_json};") +
42 44
              stylesheet_link_tag('jstoolbar')
43 45
            end
44 46
            @heads_for_wiki_formatter_included = true
public/javascripts/jstoolbar/jstoolbar.js
453 453

  
454 454
/* Code highlighting menu */
455 455
jsToolBar.prototype.precodeMenu = function(fn){
456
  var hlLanguages = ["c", "cpp", "csharp", "css", "diff", "go", "groovy", "html", "java", "javascript", "objc", "perl", "php", "python", "r", "ruby", "sass", "scala", "shell", "sql", "swift", "xml", "yaml"];
456
  var hlLanguages = window.userHlLanguages;
457 457
  var menu = $("<ul style='position:absolute;'></ul>");
458 458
  for (var i = 0; i < hlLanguages.length; i++) {
459 459
    $("<li></li>").text(hlLanguages[i]).appendTo(menu).mousedown(function(){
test/integration/layout_test.rb
66 66

  
67 67
    get '/projects/ecookbook/issues/new'
68 68
    assert_select 'head script[src^=?]', '/javascripts/jstoolbar/jstoolbar.js?'
69
    assert_include "var userHlLanguages = #{UserPreference::DEFAULT_CODE_HIGHLIGHTING_LANGUAGES.to_json};", response.body
69 70
  end
70 71

  
71 72
  def test_calendar_header_tags
test/unit/user_preference_test.rb
110 110
    up.save!
111 111
    assert_equal ['documents'], up.my_page_settings.keys
112 112
  end
113

  
114
  def test_code_highlighting_languages_setter_should_remove_except_supported_languages
115
    up = User.find(2).pref
116
    # bar is not a supported language
117
    up.code_highlighting_languages = 'ruby,cpp,bar,c'
118
    assert_equal 'ruby,cpp,c', up.code_highlighting_languages
119
  end
113 120
end