Skip to content

Commit

Permalink
Redmine 3.4 compatibility
Browse files Browse the repository at this point in the history
* drop ie6 and ie7 support
* add Redmine 3.4 support
* remove unnecessary view layout hook
  • Loading branch information
Michael Skrynski committed Jul 28, 2017
1 parent 4fd67b7 commit 7d7a073
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
30 changes: 18 additions & 12 deletions assets/javascripts/plantuml.js
@@ -1,14 +1,20 @@
if(typeof(jsToolBar) != 'undefined') {

jsToolBar.prototype.elements.plantuml = {
type: 'button',
after: 'h3',
title: 'Add PlantUML diagramm',
fn: {
wiki: function() {
this.encloseLineSelection('{{plantuml(png)\n', '\n}}')
}
/**
* Extend the jsToolBar function to add the plantUML buttons to editor toolbar.
* Needs to run after the jsToolbar function is defined and before toolbars are drawn
*
* The position cannot be set (see http://www.redmine.org/issues/14936 )
*/
if (typeof(jsToolBar) != 'undefined') {
jsToolBar.prototype.elements.plantuml = {
type: 'button',
title: 'Add PlantUML diagramm',
fn: {
wiki: function () {
// this.singleTag('{{plantuml(png)\n', '\n}}');
this.encloseLineSelection('{{plantuml(png)\n', '\n}}')
}
}
}
}

} else {
throw 'could not add plantUML button to Toolbar. jsToolbar is undefined';
}
3 changes: 1 addition & 2 deletions init.rb
Expand Up @@ -5,7 +5,7 @@
version '0.3.0'
url 'https://github.com/dkd/plantuml'

requires_redmine version: '2.6'..'3.3'
requires_redmine version: '2.6'..'3.4'

settings(partial: 'settings/plantuml',
default: { 'plantuml_binary' => {}, 'cache_seconds' => '0' })
Expand Down Expand Up @@ -38,6 +38,5 @@

unless Redmine::WikiFormatting::Textile::Helper.included_modules.include? PlantumlHelperPatch
Redmine::WikiFormatting::Textile::Helper.send(:include, PlantumlHelperPatch)
require_dependency 'plantuml/hooks/views_layouts_hook'
end
end
27 changes: 10 additions & 17 deletions lib/plantuml_helper_patch.rb
Expand Up @@ -12,24 +12,17 @@ def self.included(base) # :nodoc:
end

module HelperMethodsWikiExtensions
# extend the editor Toolbar for adding a plantuml button
# overwrite this helper method to have full control about the load order
def heads_for_wiki_formatter_with_plantuml
heads_for_wiki_formatter_without_plantuml
return if ie6_or_ie7?

unless @heads_for_wiki_plantuml_included
content_for :header_tags do
o = javascript_include_tag('plantuml.js', plugin: 'plantuml')
o << stylesheet_link_tag('plantuml.css', plugin: 'plantuml')
o.html_safe
end
@heads_for_wiki_plantuml_included = true
return if @heads_for_wiki_plantuml_included
content_for :header_tags do
javascript_include_tag('jstoolbar/jstoolbar-textile.min') +
javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language.to_s.downcase}") +
stylesheet_link_tag('jstoolbar') +
javascript_include_tag('plantuml.js', plugin: 'plantuml') +
stylesheet_link_tag('plantuml.css', plugin: 'plantuml')
end
end

private

def ie6_or_ie7?
useragent = request.env['HTTP_USER_AGENT'].to_s
useragent.match(/IE[ ]+[67]./).nil?
@heads_for_wiki_plantuml_included = true
end
end

0 comments on commit 7d7a073

Please sign in to comment.