Skip to content

Commit

Permalink
Merge pull request #1238 from nanoc/remove-rouge-1
Browse files Browse the repository at this point in the history
Remove support for Rouge 1.x
  • Loading branch information
denisdefreyne committed Nov 8, 2017
2 parents 3763e15 + 88b626b commit c2acabc
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 133 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ matrix:
env: DISABLE_NOKOGIRI=1
script:
- bundle exec rake test_ci
- bundle exec appraisal install && FOCUS=rouge bundle exec appraisal rake spec
cache: bundler
sudo: false
git:
Expand Down
13 changes: 0 additions & 13 deletions Appraisals

This file was deleted.

2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ group :plugins do
gem 'rdiscount', '~> 2.2', platforms: %i[ruby mswin]
gem 'redcarpet', platforms: %i[ruby mswin]
gem 'RedCloth', platforms: :ruby
gem 'rouge'
gem 'rouge', '~> 3.0'
gem 'rubypants'
gem 'sass'
gem 'slim', '~> 3.0'
Expand Down
5 changes: 2 additions & 3 deletions lib/nanoc/filters/colorize_syntax/colorizers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,15 @@ class RougeColorizer < Abstract
def process(code, language, params = {})
require 'rouge'

if Rouge.version < '2' || params.fetch(:legacy, false)
# Rouge 1.x or Rouge 2.x legacy options
if params.fetch(:legacy, false)
formatter_options = {
css_class: params.fetch(:css_class, 'highlight'),
inline_theme: params.fetch(:inline_theme, nil),
line_numbers: params.fetch(:line_numbers, false),
start_line: params.fetch(:start_line, 1),
wrap: params.fetch(:wrap, false),
}
formatter_cls = Rouge::Formatters.const_get(Rouge.version < '2' ? 'HTML' : 'HTMLLegacy')
formatter_cls = Rouge::Formatters::HTMLLegacy
formatter = formatter_cls.new(formatter_options)
else
formatter = params.fetch(:formatter, Rouge::Formatters::HTML.new)
Expand Down
1 change: 0 additions & 1 deletion nanoc.manifest
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.rspec
.rubocop.yml
Appraisals
CODE_OF_CONDUCT.md
LICENSE
nanoc.gemspec
Expand Down
174 changes: 66 additions & 108 deletions spec/nanoc/filters/colorize_syntax/rouge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'rouge'

describe Nanoc::Filters::ColorizeSyntax, filter: true, rouge: true do
describe Nanoc::Filters::ColorizeSyntax, filter: true do
subject { filter.setup_and_run(input, default_colorizer: :rouge, rouge: params) }
let(:filter) { ::Nanoc::Filters::ColorizeSyntax.new }
let(:params) { {} }
Expand All @@ -28,10 +28,15 @@ def foo
end

context 'with Rouge' do
context 'with 1.x', if: Rouge.version < '2' do
context 'with default options' do
it { is_expected.to eql output }
end
context 'with default options' do
it { is_expected.to eql output }
end

context 'with legacy' do
let(:legacy) { true }
let(:params) { super().merge(legacy: legacy) }

it { is_expected.to eql output }

context 'with pygments wrapper' do
let(:wrap) { true }
Expand All @@ -53,12 +58,12 @@ def foo
let(:output) do
<<~EOS
before
<pre><code class="language-ruby"><table style="border-spacing: 0"><tbody><tr>
<td class="gutter gl" style="text-align: right"><pre class="lineno">1
2</pre></td>
<td class="code"><pre> <span class="k">def</span> <span class="nf">foo</span>
<span class="k">end</span><span class="w">
</span></pre></td>
<pre><code class="language-ruby"><table class="rouge-table"><tbody><tr>
<td class="rouge-gutter gl"><pre class="lineno">1
2
</pre></td>
<td class="rouge-code"><pre> <span class="k">def</span> <span class="nf">foo</span>
<span class="k">end</span></pre></td>
</tr></tbody></table></code></pre>
after
EOS
Expand All @@ -68,129 +73,82 @@ def foo
end
end

context 'with 2.x', if: Rouge.version >= '2' do
context 'with default options' do
it { is_expected.to eql output }
end

context 'with legacy' do
let(:legacy) { true }
let(:params) { super().merge(legacy: legacy) }

it { is_expected.to eql output }

context 'with pygments wrapper' do
let(:wrap) { true }
let(:params) { super().merge(wrap: wrap) }

it { is_expected.to eql output }

context 'with css_class' do
let(:css_class) { 'nanoc' }
let(:params) { super().merge(css_class: css_class) }
context 'with formater' do
let(:params) { super().merge(formatter: formatter) }

it { is_expected.to eql output }
end
end
context 'with inline' do
let(:formatter) { Rouge::Formatters::HTMLInline.new(theme) }

context 'with line number' do
let(:line_numbers) { true }
let(:params) { super().merge(line_numbers: line_numbers) }
context 'with github theme' do
let(:theme) { Rouge::Themes::Github.new }
let(:output) do
<<~EOS
before
<pre><code class="language-ruby"><table class="rouge-table"><tbody><tr>
<td class="rouge-gutter gl"><pre class="lineno">1
2
</pre></td>
<td class="rouge-code"><pre> <span class="k">def</span> <span class="nf">foo</span>
<span class="k">end</span></pre></td>
</tr></tbody></table></code></pre>
<pre><code class="language-ruby"> <span style="color: #000000;font-weight: bold">def</span> <span style="color: #990000;font-weight: bold">foo</span>
<span style="color: #000000;font-weight: bold">end</span></code></pre>
after
EOS
end

it { is_expected.to eql output }
end
end

context 'with formater' do
let(:params) { super().merge(formatter: formatter) }

context 'with inline' do
let(:formatter) { Rouge::Formatters::HTMLInline.new(theme) }

context 'with github theme' do
let(:theme) { Rouge::Themes::Github.new }
let(:output) do
<<~EOS
before
<pre><code class="language-ruby"> <span style="color: #000000;font-weight: bold">def</span> <span style="color: #990000;font-weight: bold">foo</span>
<span style="color: #000000;font-weight: bold">end</span></code></pre>
after
EOS
end

it { is_expected.to eql output }
end

context 'with colorful theme' do
let(:theme) { Rouge::Themes::Colorful.new }
let(:output) do
<<~EOS
before
<pre><code class="language-ruby"> <span style="color: #080;font-weight: bold">def</span> <span style="color: #06B;font-weight: bold">foo</span>
<span style="color: #080;font-weight: bold">end</span></code></pre>
after
EOS
end

it { is_expected.to eql output }
end
end

context 'with linewise' do
let(:formatter) { Rouge::Formatters::HTMLLinewise.new(Rouge::Formatters::HTML.new) }
context 'with colorful theme' do
let(:theme) { Rouge::Themes::Colorful.new }
let(:output) do
<<~EOS
before
<pre><code class="language-ruby"><div class="line-1"> <span class="k">def</span> <span class="nf">foo</span>
</div>
<div class="line-2"> <span class="k">end</span>
</div></code></pre>
<pre><code class="language-ruby"> <span style="color: #080;font-weight: bold">def</span> <span style="color: #06B;font-weight: bold">foo</span>
<span style="color: #080;font-weight: bold">end</span></code></pre>
after
EOS
end

it { is_expected.to eql output }
end
end

context 'with pygments' do
let(:wrap) { true }
let(:css_class) { 'codehilite' }
let(:formatter) { Rouge::Formatters::HTMLPygments.new(Rouge::Formatters::HTML.new) }

it { is_expected.to eql output }
context 'with linewise' do
let(:formatter) { Rouge::Formatters::HTMLLinewise.new(Rouge::Formatters::HTML.new) }
let(:output) do
<<~EOS
before
<pre><code class="language-ruby"><div class="line-1"> <span class="k">def</span> <span class="nf">foo</span>
</div>
<div class="line-2"> <span class="k">end</span>
</div></code></pre>
after
EOS
end

context 'with table' do
let(:formatter) { Rouge::Formatters::HTMLTable.new(Rouge::Formatters::HTML.new) }
let(:output) do
<<~EOS
before
<pre><code class="language-ruby"><table class="rouge-table"><tbody><tr>
<td class="rouge-gutter gl"><pre class="lineno">1
2
</pre></td>
<td class="rouge-code"><pre> <span class="k">def</span> <span class="nf">foo</span>
<span class="k">end</span></pre></td>
</tr></tbody></table></code></pre>
after
EOS
end
it { is_expected.to eql output }
end

it { is_expected.to eql output }
context 'with pygments' do
let(:wrap) { true }
let(:css_class) { 'codehilite' }
let(:formatter) { Rouge::Formatters::HTMLPygments.new(Rouge::Formatters::HTML.new) }

it { is_expected.to eql output }
end

context 'with table' do
let(:formatter) { Rouge::Formatters::HTMLTable.new(Rouge::Formatters::HTML.new) }
let(:output) do
<<~EOS
before
<pre><code class="language-ruby"><table class="rouge-table"><tbody><tr>
<td class="rouge-gutter gl"><pre class="lineno">1
2
</pre></td>
<td class="rouge-code"><pre> <span class="k">def</span> <span class="nf">foo</span>
<span class="k">end</span></pre></td>
</tr></tbody></table></code></pre>
after
EOS
end

it { is_expected.to eql output }
end
end
end
Expand Down
6 changes: 0 additions & 6 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@

File.write('Rules', 'passthrough "/**/*"')
end

# Set focus if any
if ENV.fetch('FOCUS', false)
$stdout.puts "Focusing spec on '#{ENV['FOCUS']}'"
c.filter_run_including ENV['FOCUS'].to_sym => true
end
end

RSpec::Matchers.define_negated_matcher :not_match, :match
Expand Down

0 comments on commit c2acabc

Please sign in to comment.