Feature #32528 » feature-32528-3.patch
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 |
'toolbar_language_options') |
|
39 | 40 | |
40 | 41 |
TEXTAREA_FONT_OPTIONS = ['monospace', 'proportional'] |
42 |
DEFAULT_TOOLBAR_LANGUAGE_OPTIONS = %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 toolbar_language_options |
|
104 |
self[:toolbar_language_options].presence || DEFAULT_TOOLBAR_LANGUAGE_OPTIONS.join(',') |
|
105 |
end |
|
106 | ||
107 |
def toolbar_language_options=(value) |
|
108 |
languages = value.to_s.delete(' ').split(',').select{|lang| Redmine::SyntaxHighlighting.language_supported?(lang) }.compact |
|
109 |
self[:toolbar_language_options] = languages.join(',') |
|
110 |
end |
|
111 | ||
101 | 112 |
# Returns the names of groups that are displayed on user's page |
102 | 113 |
# Example: |
103 | 114 |
# 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 :toolbar_language_options, :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_toolbar_language_options: Code highlighting toolbar options |
|
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 |
toolbar_language_options = User.current && User.current.pref.toolbar_language_options |
|
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 = #{(toolbar_language_options.nil? ? UserPreference::DEFAULT_TOOLBAR_LANGUAGE_OPTIONS : toolbar_language_options.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 |
toolbar_language_options = User.current && User.current.pref.toolbar_language_options |
|
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 = #{(toolbar_language_options.nil? ? UserPreference::DEFAULT_TOOLBAR_LANGUAGE_OPTIONS : toolbar_language_options.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_TOOLBAR_LANGUAGE_OPTIONS.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_toolbar_language_options_setter_should_remove_except_supported_languages |
|
115 |
up = User.find(2).pref |
|
116 |
# bar is not a supported language |
|
117 |
up.toolbar_language_options = 'ruby,cpp,bar,c' |
|
118 |
assert_equal 'ruby,cpp,c', up.toolbar_language_options |
|
119 |
end |
|
113 | 120 |
end |
- « Previous
- 1
- …
- 3
- 4
- 5
- Next »