From 769f8ec8d6b3e80db051018119c5fc957e586591 Mon Sep 17 00:00:00 2001 From: Bart Kamphorst Date: Thu, 8 Nov 2018 16:11:38 +0100 Subject: [PATCH 1/2] Implements frontend support for CriticMarkup. Related to #1016. --- bin/gollum | 3 ++ lib/gollum/app.rb | 1 + lib/gollum/assets.rb | 2 +- .../javascript/editor/langs/asciidoc.js | 29 ++++++++++++- .../gollum/javascript/editor/langs/creole.js | 28 ++++++++++++- .../javascript/editor/langs/markdown.js | 28 ++++++++++++- .../gollum/javascript/editor/langs/org.js | 29 ++++++++++++- .../gollum/javascript/editor/langs/pod.js | 29 ++++++++++++- .../gollum/javascript/editor/langs/rdoc.js | 29 ++++++++++++- .../gollum/javascript/editor/langs/textile.js | 29 ++++++++++++- .../public/gollum/javascript/gollum.js.erb | 8 ++++ lib/gollum/public/gollum/stylesheets/app.scss | 1 + .../gollum/stylesheets/criticmarkup.scss | 42 +++++++++++++++++++ .../public/gollum/stylesheets/editor.scss | 4 +- lib/gollum/templates/editor.mustache | 6 +++ lib/gollum/templates/layout.mustache | 1 + lib/gollum/views/edit.rb | 4 ++ lib/gollum/views/layout.rb | 4 ++ 18 files changed, 267 insertions(+), 10 deletions(-) create mode 100644 lib/gollum/public/gollum/stylesheets/criticmarkup.scss diff --git a/bin/gollum b/bin/gollum index 56e8f728..6a3cf2cf 100755 --- a/bin/gollum +++ b/bin/gollum @@ -135,6 +135,9 @@ MSG "By default, uses the 'TeX-AMS-MML_HTMLorMML' config with the 'autoload-all' extension.") do wiki_options[:mathjax] = true end + opts.on("--critic-markup", "Enable CriticMarkup support.") do + wiki_options[:critic_markup] = true + end opts.on("--irb", "Launch Gollum in 'console mode', with a predefined API.") do options[:irb] = true end diff --git a/lib/gollum/app.rb b/lib/gollum/app.rb index 0da65acd..1192cf1c 100644 --- a/lib/gollum/app.rb +++ b/lib/gollum/app.rb @@ -84,6 +84,7 @@ module Precious before do settings.wiki_options[:allow_editing] = settings.wiki_options.fetch(:allow_editing, true) @allow_editing = settings.wiki_options[:allow_editing] + @critic_markup = settings.wiki_options[:critic_markup] forbid unless @allow_editing || request.request_method == "GET" Precious::App.set(:mustache, {:templates => settings.wiki_options[:template_dir]}) if settings.wiki_options[:template_dir] @base_url = url('/', false).chomp('/') diff --git a/lib/gollum/assets.rb b/lib/gollum/assets.rb index 50003804..c01ed0b8 100644 --- a/lib/gollum/assets.rb +++ b/lib/gollum/assets.rb @@ -1,6 +1,6 @@ module Precious module Assets - MANIFEST = %w(app.js app.css fileview.css ie7.css print.css *.png *.jpg *.svg *.eot *.ttf *.woff *.woff2) + MANIFEST = %w(app.js app.css criticmarkup.css fileview.css ie7.css print.css *.png *.jpg *.svg *.eot *.ttf *.woff *.woff2) ASSET_URL = 'gollum/assets' def self.sprockets(dir = File.dirname(File.expand_path(__FILE__))) diff --git a/lib/gollum/public/gollum/javascript/editor/langs/asciidoc.js b/lib/gollum/public/gollum/javascript/editor/langs/asciidoc.js index 8703bbee..b4a7a5b9 100644 --- a/lib/gollum/public/gollum/javascript/editor/langs/asciidoc.js +++ b/lib/gollum/public/gollum/javascript/editor/langs/asciidoc.js @@ -113,7 +113,34 @@ var AsciiDoc = { } }); } - } + }, + + 'function-critic-accept' : { + exec: function( txt, selText, $field) { + var toReplace = selText. + replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1"). + replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, ""). + replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$2"). + replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1"). + replace(/\{>>(.*?)<<\}/gm, "") + $.GollumEditor.replaceSelection( toReplace ); + } + + }, + + 'function-critic-reject' : { + exec: function( txt, selText, $field) { + var toReplace = selText. + replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, ""). + replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1"). + replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$1"). + replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1"). + replace(/\{>>(.*?)<<\}/gm, "") + $.GollumEditor.replaceSelection( toReplace ); + } + + } + }; diff --git a/lib/gollum/public/gollum/javascript/editor/langs/creole.js b/lib/gollum/public/gollum/javascript/editor/langs/creole.js index b32e95b6..90c4cd0e 100644 --- a/lib/gollum/public/gollum/javascript/editor/langs/creole.js +++ b/lib/gollum/public/gollum/javascript/editor/langs/creole.js @@ -96,7 +96,33 @@ var Creole = { } }); } - } + }, + 'function-critic-accept' : { + exec: function( txt, selText, $field) { + var toReplace = selText. + replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1"). + replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, ""). + replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$2"). + replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1"). + replace(/\{>>(.*?)<<\}/gm, "") + $.GollumEditor.replaceSelection( toReplace ); + } + + }, + + 'function-critic-reject' : { + exec: function( txt, selText, $field) { + var toReplace = selText. + replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, ""). + replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1"). + replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$1"). + replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1"). + replace(/\{>>(.*?)<<\}/gm, "") + $.GollumEditor.replaceSelection( toReplace ); + } + + } + }; diff --git a/lib/gollum/public/gollum/javascript/editor/langs/markdown.js b/lib/gollum/public/gollum/javascript/editor/langs/markdown.js index b1f917eb..5b2cb55a 100644 --- a/lib/gollum/public/gollum/javascript/editor/langs/markdown.js +++ b/lib/gollum/public/gollum/javascript/editor/langs/markdown.js @@ -139,7 +139,33 @@ var MarkDown = { } }); } - } + }, + + 'function-critic-accept' : { + exec: function( txt, selText, $field) { + var toReplace = selText. + replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1"). + replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, ""). + replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$2"). + replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1"). + replace(/\{>>(.*?)<<\}/gm, "") + $.GollumEditor.replaceSelection( toReplace ); + } + + }, + + 'function-critic-reject' : { + exec: function( txt, selText, $field) { + var toReplace = selText. + replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, ""). + replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1"). + replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$1"). + replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1"). + replace(/\{>>(.*?)<<\}/gm, "") + $.GollumEditor.replaceSelection( toReplace ); + } + + } }; diff --git a/lib/gollum/public/gollum/javascript/editor/langs/org.js b/lib/gollum/public/gollum/javascript/editor/langs/org.js index 072cf388..f6a0c5e2 100644 --- a/lib/gollum/public/gollum/javascript/editor/langs/org.js +++ b/lib/gollum/public/gollum/javascript/editor/langs/org.js @@ -105,7 +105,34 @@ var OrgMode = { } }); } - } + }, + + 'function-critic-accept' : { + exec: function( txt, selText, $field) { + var toReplace = selText. + replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1"). + replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, ""). + replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$2"). + replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1"). + replace(/\{>>(.*?)<<\}/gm, "") + $.GollumEditor.replaceSelection( toReplace ); + } + + }, + + 'function-critic-reject' : { + exec: function( txt, selText, $field) { + var toReplace = selText. + replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, ""). + replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1"). + replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$1"). + replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1"). + replace(/\{>>(.*?)<<\}/gm, "") + $.GollumEditor.replaceSelection( toReplace ); + } + + } + }; diff --git a/lib/gollum/public/gollum/javascript/editor/langs/pod.js b/lib/gollum/public/gollum/javascript/editor/langs/pod.js index 1cb7957c..89125bb3 100644 --- a/lib/gollum/public/gollum/javascript/editor/langs/pod.js +++ b/lib/gollum/public/gollum/javascript/editor/langs/pod.js @@ -63,7 +63,34 @@ var Pod = { } }); } - } + }, + + 'function-critic-accept' : { + exec: function( txt, selText, $field) { + var toReplace = selText. + replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1"). + replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, ""). + replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$2"). + replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1"). + replace(/\{>>(.*?)<<\}/gm, "") + $.GollumEditor.replaceSelection( toReplace ); + } + + }, + + 'function-critic-reject' : { + exec: function( txt, selText, $field) { + var toReplace = selText. + replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, ""). + replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1"). + replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$1"). + replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1"). + replace(/\{>>(.*?)<<\}/gm, "") + $.GollumEditor.replaceSelection( toReplace ); + } + + } + }; diff --git a/lib/gollum/public/gollum/javascript/editor/langs/rdoc.js b/lib/gollum/public/gollum/javascript/editor/langs/rdoc.js index f0df80b8..e0f5fe1f 100644 --- a/lib/gollum/public/gollum/javascript/editor/langs/rdoc.js +++ b/lib/gollum/public/gollum/javascript/editor/langs/rdoc.js @@ -65,7 +65,34 @@ var RDoc = { 'function-h3' : { search: /(.+)([\n]?)/gi, replace: "=== $1$2" - } + }, + + 'function-critic-accept' : { + exec: function( txt, selText, $field) { + var toReplace = selText. + replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1"). + replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, ""). + replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$2"). + replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1"). + replace(/\{>>(.*?)<<\}/gm, "") + $.GollumEditor.replaceSelection( toReplace ); + } + + }, + + 'function-critic-reject' : { + exec: function( txt, selText, $field) { + var toReplace = selText. + replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, ""). + replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1"). + replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$1"). + replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1"). + replace(/\{>>(.*?)<<\}/gm, "") + $.GollumEditor.replaceSelection( toReplace ); + } + + } + }; diff --git a/lib/gollum/public/gollum/javascript/editor/langs/textile.js b/lib/gollum/public/gollum/javascript/editor/langs/textile.js index 4e27433d..999ce2f4 100644 --- a/lib/gollum/public/gollum/javascript/editor/langs/textile.js +++ b/lib/gollum/public/gollum/javascript/editor/langs/textile.js @@ -102,7 +102,34 @@ var Textile = { } }); } - } + }, + + 'function-critic-accept' : { + exec: function( txt, selText, $field) { + var toReplace = selText. + replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1"). + replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, ""). + replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$2"). + replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1"). + replace(/\{>>(.*?)<<\}/gm, "") + $.GollumEditor.replaceSelection( toReplace ); + } + + }, + + 'function-critic-reject' : { + exec: function( txt, selText, $field) { + var toReplace = selText. + replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, ""). + replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1"). + replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$1"). + replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1"). + replace(/\{>>(.*?)<<\}/gm, "") + $.GollumEditor.replaceSelection( toReplace ); + } + + } + }; diff --git a/lib/gollum/public/gollum/javascript/gollum.js.erb b/lib/gollum/public/gollum/javascript/gollum.js.erb index 173bf27d..0c5e6542 100755 --- a/lib/gollum/public/gollum/javascript/gollum.js.erb +++ b/lib/gollum/public/gollum/javascript/gollum.js.erb @@ -358,6 +358,14 @@ $(document).ready(function() { $.GollumEditor({ NewFile: true, MarkupType: default_markup }); } + // CriticMarkup + if(criticMarkup == 'true') { + $('#wiki-content').addClass('criticmarkup'); + $('ins.break').unwrap(); + $('span.critic.comment').wrap(''); + $('span.critic.comment').filter(function() {return $(this).text()!="";}).before('‡'); + } + if( $('#wiki-history').length ){ var lookup = {}; $('img.identicon').each(function(index, element){ diff --git a/lib/gollum/public/gollum/stylesheets/app.scss b/lib/gollum/public/gollum/stylesheets/app.scss index b650ae9f..78c716d1 100644 --- a/lib/gollum/public/gollum/stylesheets/app.scss +++ b/lib/gollum/public/gollum/stylesheets/app.scss @@ -1,4 +1,5 @@ //= require gollum //= require editor //= require dialog +//= require criticmarkup //= require template \ No newline at end of file diff --git a/lib/gollum/public/gollum/stylesheets/criticmarkup.scss b/lib/gollum/public/gollum/stylesheets/criticmarkup.scss new file mode 100644 index 00000000..d376554e --- /dev/null +++ b/lib/gollum/public/gollum/stylesheets/criticmarkup.scss @@ -0,0 +1,42 @@ +.criticmarkup mark { + background-color: #fffd38; + text-decoration: none; +} + +.criticmarkup del { + background-color: #f6a9a9; + text-decoration: line-through; +} +.criticmarkup ins { + background-color: #a9f6a9; + text-decoration: none; +} +.criticmarkup ins.break { + display: block; + line-height: 2px; + padding: 0 !important; + margin: 0 !important; +} +.criticmarkup ins.break span { + line-height: 1.5em; +} +.criticmarkup .popover { + background-color: #fffd38; + color: #000; +} +.criticmarkup .critic.comment { + display: none; +} + +.criticmarkup .popover:hover span.critic.comment { + display: block; + position: absolute; + width: 200px; + left: 30%; + font-size: 0.8em; + color: #ccc; + background-color: #333; + z-index: 10; + padding: 0.5em 1em; + border-radius: 0.5em; +} \ No newline at end of file diff --git a/lib/gollum/public/gollum/stylesheets/editor.scss b/lib/gollum/public/gollum/stylesheets/editor.scss index 0b543732..6a6ffe19 100644 --- a/lib/gollum/public/gollum/stylesheets/editor.scss +++ b/lib/gollum/public/gollum/stylesheets/editor.scss @@ -367,8 +367,8 @@ a#function-h2 { @include editor-button(9); } a#function-h3 { @include editor-button(10); } a#function-link { @include editor-button(11); } a#function-image { @include editor-button(12); } -a#function-plus { @include editor-button(13); } -a#function-minus { @include editor-button(14); } +a#function-critic-accept { @include editor-button(13); } +a#function-critic-reject { @include editor-button(14); } a#function-help { @include editor-button(15); } a#function-search { @include editor-button(16); } diff --git a/lib/gollum/templates/editor.mustache b/lib/gollum/templates/editor.mustache index 7b3eead6..fbb4e0e7 100644 --- a/lib/gollum/templates/editor.mustache +++ b/lib/gollum/templates/editor.mustache @@ -49,6 +49,12 @@ Link Image + {{#critic_markup}} + + Accept Selected CriticMarkup + + Reject Selected CriticMarkup + {{/critic_markup}}   Help diff --git a/lib/gollum/templates/layout.mustache b/lib/gollum/templates/layout.mustache index c972591f..b24f9ea9 100644 --- a/lib/gollum/templates/layout.mustache +++ b/lib/gollum/templates/layout.mustache @@ -20,6 +20,7 @@ {{#page}} var pageFullPath = '{{url_path}}'; {{/page}} + var criticMarkup = '{{critic_markup}}'; {{#sprockets_javascript_tag}}app{{/sprockets_javascript_tag}} {{#use_identicon}} diff --git a/lib/gollum/views/edit.rb b/lib/gollum/views/edit.rb index b5579b55..df531c14 100755 --- a/lib/gollum/views/edit.rb +++ b/lib/gollum/views/edit.rb @@ -60,6 +60,10 @@ module Precious true end + def critic_markup + @critic_markup + end + def allow_uploads @allow_uploads end diff --git a/lib/gollum/views/layout.rb b/lib/gollum/views/layout.rb index 0777c0e5..885029b8 100644 --- a/lib/gollum/views/layout.rb +++ b/lib/gollum/views/layout.rb @@ -43,6 +43,10 @@ module Precious def js # custom js @js end + + def critic_markup + @critic_markup + end end end From 6d0b42b18f3c7ce78dfecac385bd46b7ae3d1273 Mon Sep 17 00:00:00 2001 From: Bart Kamphorst Date: Sun, 11 Nov 2018 15:35:51 +0100 Subject: [PATCH 2/2] Fix superfluous code in edit.rb. Add more descriptive help sentence for CriticMarkup. --- bin/gollum | 2 +- lib/gollum/views/edit.rb | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/bin/gollum b/bin/gollum index 6a3cf2cf..1ab9526d 100755 --- a/bin/gollum +++ b/bin/gollum @@ -135,7 +135,7 @@ MSG "By default, uses the 'TeX-AMS-MML_HTMLorMML' config with the 'autoload-all' extension.") do wiki_options[:mathjax] = true end - opts.on("--critic-markup", "Enable CriticMarkup support.") do + opts.on("--critic-markup", "Enable support for annotations using CriticMarkup.") do wiki_options[:critic_markup] = true end opts.on("--irb", "Launch Gollum in 'console mode', with a predefined API.") do diff --git a/lib/gollum/views/edit.rb b/lib/gollum/views/edit.rb index df531c14..203b8d0f 100755 --- a/lib/gollum/views/edit.rb +++ b/lib/gollum/views/edit.rb @@ -60,9 +60,6 @@ module Precious true end - def critic_markup - @critic_markup - end def allow_uploads @allow_uploads