-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
task #3: No highlight in view-source mode
Task-Url: http://github.com/dominch/redmine_highlightjs/issues/issue/3 Signed-off-by: Dominik Chmaj <[email protected]>
- Loading branch information
Dominik Chmaj
committed
Sep 16, 2015
1 parent
d8e8191
commit 1473167
Showing
12 changed files
with
191 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
|
||
class CodeThemeUserSetting < ActiveRecord::Base | ||
unloadable | ||
belongs_to :user | ||
validates_presence_of :user | ||
|
||
DEFAULT_CODE_THEME = '__default_code_theme__' | ||
CODE_THEMES = { | ||
'agate' => 'agate', | ||
'androidstudio' => 'androidstudio', | ||
'arta' => 'arta', | ||
'ascetic' => 'ascetic', | ||
'atelier cave (light)' => 'atelier-cave.light', | ||
'atelier cave (dark)' => 'atelier-cave.dark', | ||
'atelier dune (light)' => 'atelier-dune.light', | ||
'atelier dune (dark)' => 'atelier-dune.dark', | ||
'atelier estuary (light)' => 'atelier-estuary.light', | ||
'atelier estuary (dark)' => 'atelier-estuary.dark', | ||
'atelier forest (light)' => 'atelier-forest.light', | ||
'atelier forest (dark)' => 'atelier-forest.dark', | ||
'atelier heath (light)' => 'atelier-heath.light', | ||
'atelier heath (dark)' => 'atelier-heath.dark', | ||
'atelier lakeside (light)' => 'atelier-lakeside.light', | ||
'atelier lakeside (dark)' => 'atelier-lakeside.dark', | ||
'atelier plateau (light)' => 'atelier-plateau.light', | ||
'atelier plateau (dark)' => 'atelier-plateau.dark', | ||
'atelier savanna (light)' => 'atelier-savanna.light', | ||
'atelier savanna (dark)' => 'atelier-savanna.dark', | ||
'atelier seaside (light)' => 'atelier-seaside.light', | ||
'atelier seaside (dark)' => 'atelier-seaside.dark', | ||
'atelier sulphurpool (light)' => 'atelier-sulphurpool.light', | ||
'atelier sulphurpool (dark)' => 'atelier-sulphurpool.dark', | ||
'brown paper' => 'brown_paper', | ||
'codepen embed' => 'codepen-embed', | ||
'color brewer' => 'color-brewer', | ||
'dark' => 'dark', | ||
'darkula' => 'darkula', | ||
'default' => 'default', | ||
'docco' => 'docco', | ||
'far' => 'far', | ||
'foundation' => 'foundation', | ||
'github' => 'github', | ||
'github gist' => 'github-gist', | ||
'googlecode' => 'googlecode', | ||
'grayscale' => 'grayscale', | ||
'hopscotch' => 'hopscotch', | ||
'hybrid' => 'hybrid', | ||
'idea' => 'idea', | ||
'ir_black' => 'ir_black', | ||
'kimbie (light)' => 'kimbie.light', | ||
'kimbie (dark)' => 'kimbie.dark', | ||
'magula' => 'magula', | ||
'mono-blue' => 'mono-blue', | ||
'monokai' => 'monokai', | ||
'monokai sublime' => 'monokai_sublime', | ||
'obsidian' => 'obsidian', | ||
'paraiso (light)' => 'paraiso.light', | ||
'paraiso (dark)' => 'paraiso.dark', | ||
'pojoaque' => 'pojoaque', | ||
'pojoaque.jpg' => 'pojoaque.jpg', | ||
'railscasts' => 'railscasts', | ||
'rainbow' => 'rainbow', | ||
'school_book' => 'school_book', | ||
'solarized (light)' => 'solarized_light', | ||
'solarized (dark)' => 'solarized_dark', | ||
'sunburst' => 'sunburst', | ||
'tomorrow night' => 'tomorrow-night', | ||
'tomorrow night (blue)' => 'tomorrow-night-blue', | ||
'tomorrow night (bright)' => 'tomorrow-night-bright', | ||
'tomorrow night (eighties)' => 'tomorrow-night-eighties', | ||
'tomorrow' => 'tomorrow', | ||
'vs' => 'vs', | ||
'xcode' => 'xcode', | ||
'zenburn' => 'zenburn' | ||
} | ||
|
||
def self.find_code_theme_by_user_id(user_id) | ||
CodeThemeUserSetting.find(:first, :conditions => ['user_id = ?', user_id]) | ||
end | ||
|
||
def self.find_or_create_code_theme_by_user_id(user_id) | ||
code_theme = find_code_theme_by_user_id(user_id) | ||
unless code_theme | ||
code_theme = CodeThemeUserSetting.new | ||
code_theme.user_id = user_id | ||
end | ||
return code_theme | ||
end | ||
|
||
def code_theme_name | ||
return '' if code_theme == DEFAULT_CODE_THEME | ||
code_theme | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<fieldset class="box <%= 'hidden' if Setting.plugin_redmine_highlightjs[:allow_redefine].nil? %>"> | ||
|
||
<legend><%=h l(:code_theme_title) %></legend> | ||
<div class="tabular"> | ||
<p> | ||
<label><%=h l(:code_theme) %></label> | ||
<%=select_tag("pref[code_theme]", options_for_select( | ||
{ | ||
l(:label_default) => CodeThemeUserSetting::DEFAULT_CODE_THEME | ||
}.merge(CodeThemeUserSetting::CODE_THEMES), | ||
user.preference.code_theme)) | ||
%> | ||
</p> | ||
<p> | ||
<em><span class="helpLink"> <%= l(:try_it_link) %> <a href="https://highlightjs.org/static/demo/" target="_blank">https://highlightjs.org/static/demo/</a> </span></em> | ||
</p> | ||
</div> | ||
|
||
</fieldset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class CreateCodeThemeUserSettings < ActiveRecord::Migration | ||
def self.up | ||
create_table :code_theme_user_settings do |t| | ||
t.column :user_id, :integer | ||
t.column :code_theme, :string | ||
t.column :updated_at, :timestamp | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :code_theme_user_settings | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class CodeThemeMyAccountHooks < Redmine::Hook::ViewListener | ||
render_on :view_my_account, :partial => 'settings/code_theme_form', :multipart => true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module ApplicationHelper | ||
def get_code_theme | ||
setting = CodeThemeUserSetting.find_code_theme_by_user_id(User.current.id) | ||
return Setting.ui_theme unless setting | ||
return Setting.ui_theme if setting.code_theme == CodeThemeUserSetting::DEFAULT_CODE_THEME | ||
return setting.code_theme_name | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module CodeThemeUserPreferencePatch | ||
def self.included(base) | ||
base.send(:include, UserPreferenceInstanceMethodsForCodeTheme) | ||
base.class_eval do | ||
unloadable | ||
end | ||
end | ||
end | ||
|
||
module UserPreferenceInstanceMethodsForCodeTheme | ||
|
||
def code_theme | ||
code_theme_setting = CodeThemeUserSetting.find_code_theme_by_user_id(user.id) | ||
return nil unless code_theme_setting | ||
code_theme_setting.code_theme | ||
end | ||
|
||
def code_theme=(name) | ||
code_theme_setting = CodeThemeUserSetting.find_or_create_code_theme_by_user_id(user.id) | ||
code_theme_setting.code_theme = name | ||
code_theme_setting.save! | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters