From 63dd863618623a69f26b8bdc9c6eeb0b4ba2ba6c Mon Sep 17 00:00:00 2001 From: Bart Kamphorst Date: Tue, 1 Aug 2023 16:27:00 +0200 Subject: [PATCH] Remove octicons altogether from gollum-lib. (#441) * Remove octicons altogether from gollum-lib. * Rename Octicon macro to Icon. Leave finding and rendering the actual icon to frontend (gollum). * Remove hardcoded octicon names from gollum-lib. * Add Flash macro that comes without default icon. * Upgrade minitest-reporters. --- HISTORY.md | 3 --- gemspec.rb | 5 ++--- lib/gollum-lib/filter/macro.rb | 6 ++---- lib/gollum-lib/macro.rb | 2 +- lib/gollum-lib/macro/flash.rb | 11 +++++++++++ lib/gollum-lib/macro/icon.rb | 9 +++++++++ lib/gollum-lib/macro/note.rb | 14 ++------------ lib/gollum-lib/macro/octicon.rb | 12 ------------ lib/gollum-lib/macro/warn.rb | 4 +--- test/test_macros.rb | 23 +++++++++++++---------- 10 files changed, 41 insertions(+), 48 deletions(-) create mode 100644 lib/gollum-lib/macro/flash.rb create mode 100644 lib/gollum-lib/macro/icon.rb delete mode 100644 lib/gollum-lib/macro/octicon.rb diff --git a/HISTORY.md b/HISTORY.md index 54a03832f..b2cbfed96 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,13 +2,10 @@ * Bugfix release: address XSS vulnerability ( @6661620a, @dometto) - # 5.2.3 / 2023-03-13 * Bugfix release: update adapter dependencies for Ruby 3.2 support. - - # 5.2.2 / 2023-01-18 * Bugfix release: set Nokogiri default XHTML conversion options more relaibly. See https://github.com/sparklemotion/nokogiri/issues/2761 diff --git a/gemspec.rb b/gemspec.rb index 4f54d6a32..ebe3f378a 100644 --- a/gemspec.rb +++ b/gemspec.rb @@ -26,7 +26,6 @@ def specification(version, default_adapter, platform = nil) s.add_dependency 'loofah', '~> 2.3' s.add_dependency 'github-markup', '~> 4.0' s.add_dependency 'gemojione', '~> 4.1' - s.add_dependency 'octicons', '~> 17.0' s.add_dependency 'twitter-text', '1.14.7' s.add_development_dependency 'org-ruby', '~> 0.9.9' @@ -45,7 +44,7 @@ def specification(version, default_adapter, platform = nil) s.add_development_dependency 'rb-readline', '~> 0.5.1' # updating minitest-reporters requires a new minitest which fails with gollum's tests. s.add_development_dependency 'test-unit', '~> 3.3' - s.add_development_dependency 'minitest-reporters', '~> 1.4' + s.add_development_dependency 'minitest-reporters', '~> 1.5' s.add_development_dependency 'nokogiri-diff', '~> 0.2.0' s.add_development_dependency 'guard', '~> 2.16' s.add_development_dependency 'guard-minitest', '~> 2.4' @@ -93,7 +92,7 @@ def specification(version, default_adapter, platform = nil) lib/gollum-lib/macro/global_toc.rb lib/gollum-lib/macro/navigation.rb lib/gollum-lib/macro/note.rb - lib/gollum-lib/macro/octicon.rb + lib/gollum-lib/macro/icon.rb lib/gollum-lib/macro/series.rb lib/gollum-lib/macro/video.rb lib/gollum-lib/macro/warn.rb diff --git a/lib/gollum-lib/filter/macro.rb b/lib/gollum-lib/filter/macro.rb index 5f79ac108..03e0ba88e 100644 --- a/lib/gollum-lib/filter/macro.rb +++ b/lib/gollum-lib/filter/macro.rb @@ -1,5 +1,5 @@ # ~*~ encoding: utf-8 ~*~ -require 'octicons' + # Replace specified tokens with dynamically generated content. class Gollum::Filter::Macro < Gollum::Filter @@ -53,9 +53,7 @@ def process(data) begin Gollum::Macro.instance(macro, @markup.wiki, @markup.page).render(*args) rescue StandardError => e - icon = Octicons::Octicon.new('zap', {width: 24, height: 24}) - icon.options[:class] << ' mr-2' - "
#{icon.to_svg}Macro Error for #{macro}: #{e.message}
" + %Q(
Macro Error for #{macro}: #{e.message}
) end end end diff --git a/lib/gollum-lib/macro.rb b/lib/gollum-lib/macro.rb index 870bf4750..077c645d0 100644 --- a/lib/gollum-lib/macro.rb +++ b/lib/gollum-lib/macro.rb @@ -38,7 +38,7 @@ def initialize(macro_name) end def render(*_args) - "!!!Unknown macro: #{@macro_name}!!!" + html_error("Unknown macro: #{@macro_name}") end end end diff --git a/lib/gollum-lib/macro/flash.rb b/lib/gollum-lib/macro/flash.rb new file mode 100644 index 000000000..9c7a91890 --- /dev/null +++ b/lib/gollum-lib/macro/flash.rb @@ -0,0 +1,11 @@ +module Gollum + class Macro + class Flash < Gollum::Macro + def render(message, icon='', type='') + flash_type = ['warn', 'error', 'success'].include?(type) ? "flash-#{type}" : '' + flash_icon = icon.empty? ? '' : %Q(data-gollum-icon="#{icon}") + %Q(
#{message}
) + end + end + end +end \ No newline at end of file diff --git a/lib/gollum-lib/macro/icon.rb b/lib/gollum-lib/macro/icon.rb new file mode 100644 index 000000000..7b9bdd8bf --- /dev/null +++ b/lib/gollum-lib/macro/icon.rb @@ -0,0 +1,9 @@ +module Gollum + class Macro + class Icon < Gollum::Macro + def render(icon) + %Q(
) + end + end + end +end \ No newline at end of file diff --git a/lib/gollum-lib/macro/note.rb b/lib/gollum-lib/macro/note.rb index 4c0a7c7bf..67133b430 100644 --- a/lib/gollum-lib/macro/note.rb +++ b/lib/gollum-lib/macro/note.rb @@ -1,18 +1,8 @@ module Gollum class Macro class Note < Gollum::Macro - def render(notice, octicon = 'info') - icon = "" - unless octicon.empty? - begin - icon = Octicons::Octicon.new(octicon, {width: 24, height: 24}) - rescue RuntimeError - icon = Octicons::Octicon.new('info', {width: 24, height: 24}) - end - icon.options[:class] << ' mr-2' - icon = icon.to_svg - end - "
#{icon}#{notice}
" + def render(notice) + %Q(
#{notice}
) end end end diff --git a/lib/gollum-lib/macro/octicon.rb b/lib/gollum-lib/macro/octicon.rb deleted file mode 100644 index de8ab8ff0..000000000 --- a/lib/gollum-lib/macro/octicon.rb +++ /dev/null @@ -1,12 +0,0 @@ -module Gollum - class Macro - class Octicon < Gollum::Macro - def render(symbol, height = nil, width = nil) - parameters = {} - parameters[:height] = height if height - parameters[:width] = width if width - "
#{Octicons::Octicon.new(symbol, parameters).to_svg}
" - end - end - end -end \ No newline at end of file diff --git a/lib/gollum-lib/macro/warn.rb b/lib/gollum-lib/macro/warn.rb index 892b8a36d..1e7cc502b 100644 --- a/lib/gollum-lib/macro/warn.rb +++ b/lib/gollum-lib/macro/warn.rb @@ -2,9 +2,7 @@ module Gollum class Macro class Warn < Gollum::Macro def render(warning) - icon = Octicons::Octicon.new('alert', {width: 24, height: 24}) - icon.options[:class] << ' mr-2' - "
#{icon.to_svg}#{warning}
" + %Q(
#{warning}
) end end end diff --git a/test/test_macros.rb b/test/test_macros.rb index 246049056..d3fb0f6be 100644 --- a/test/test_macros.rb +++ b/test/test_macros.rb @@ -185,26 +185,29 @@ def render(opts) assert_match /