From 5bf15964140c767b5011f1ee65d5a4f8e7a05231 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 14 Oct 2014 12:04:09 -0700 Subject: [PATCH 1/5] Refactor Highlight tag tests to use a helper method to create the tag. --- Gemfile | 1 + jekyll.gemspec | 2 +- test/test_tags.rb | 40 +++++++++++++++++++++++++++++----------- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/Gemfile b/Gemfile index 25b40ed2..d680ef69 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,6 @@ source 'https://rubygems.org' gemspec +gem "liquid", github: 'Shopify/liquid' if ENV['BENCHMARK'] gem 'rbtrace' diff --git a/jekyll.gemspec b/jekyll.gemspec index 4913951e..c9876c47 100644 --- a/jekyll.gemspec +++ b/jekyll.gemspec @@ -28,7 +28,7 @@ Gem::Specification.new do |s| s.rdoc_options = ['--charset=UTF-8'] s.extra_rdoc_files = %w[README.markdown LICENSE] - s.add_runtime_dependency('liquid', '~> 2.6.1') + #s.add_runtime_dependency('liquid', '') s.add_runtime_dependency('kramdown', '~> 1.3') s.add_runtime_dependency('mercenary', '~> 0.3.3') s.add_runtime_dependency('safe_yaml', '~> 1.0') diff --git a/test/test_tags.rb b/test/test_tags.rb index a47ca897..bc4b48cd 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -43,6 +43,10 @@ CONTENT create_post(content, override) end + def highlight_block_with_opts(options_string) + Jekyll::Tags::HighlightBlock.parse('highlight', options_string, ["test", "{% endhighlight %}", "\n"], {}) + end + context "language name" do should "match only the required set of chars" do r = Jekyll::Tags::HighlightBlock::SYNTAX @@ -59,37 +63,51 @@ CONTENT end end - context "initialized tag" do - should "set the correct options" do - tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby ', ["test", "{% endhighlight %}", "\n"]) + context "highlight tag in unsafe mode" do + should "set the no options with just a language name" do + tag = highlight_block_with_opts('ruby ') assert_equal({}, tag.instance_variable_get(:@options)) + end - tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos ', ["test", "{% endhighlight %}", "\n"]) + should "set the linenos option as 'inline' if no linenos value" do + tag = highlight_block_with_opts('ruby linenos ') assert_equal({ :linenos => 'inline' }, tag.instance_variable_get(:@options)) + end - tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos=table ', ["test", "{% endhighlight %}", "\n"]) + should "set the linenos option to 'table' if the linenos key is given the table value" do + tag = highlight_block_with_opts('ruby linenos=table ') assert_equal({ :linenos => 'table' }, tag.instance_variable_get(:@options)) + end - tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos=table nowrap', ["test", "{% endhighlight %}", "\n"]) + should "recognize nowrap option with linenos set" do + tag = highlight_block_with_opts('ruby linenos=table nowrap ') assert_equal({ :linenos => 'table', :nowrap => true }, tag.instance_variable_get(:@options)) + end - tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos=table cssclass=hl', ["test", "{% endhighlight %}", "\n"]) + should "recognize the cssclass option" do + tag = highlight_block_with_opts('ruby linenos=table cssclass=hl ') assert_equal({ :cssclass => 'hl', :linenos => 'table' }, tag.instance_variable_get(:@options)) + end - tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos=table cssclass=hl hl_linenos=3', ["test", "{% endhighlight %}", "\n"]) + should "recognize the hl_linenos option and its value" do + tag = highlight_block_with_opts('ruby linenos=table cssclass=hl hl_linenos=3 ') assert_equal({ :cssclass => 'hl', :linenos => 'table', :hl_linenos => '3' }, tag.instance_variable_get(:@options)) + end - tag = Jekyll::Tags::HighlightBlock.new('highlight', 'ruby linenos=table cssclass=hl hl_linenos="3 5 6"', ["test", "{% endhighlight %}", "\n"]) + should "recognize multiple values of hl_linenos" do + tag = highlight_block_with_opts('ruby linenos=table cssclass=hl hl_linenos="3 5 6" ') assert_equal({ :cssclass => 'hl', :linenos => 'table', :hl_linenos => ['3', '5', '6'] }, tag.instance_variable_get(:@options)) + end - tag = Jekyll::Tags::HighlightBlock.new('highlight', 'Ruby ', ["test", "{% endhighlight %}", "\n"]) + should "treat language name as case insensitive" do + tag = highlight_block_with_opts('Ruby ') assert_equal "ruby", tag.instance_variable_get(:@lang), "lexers should be case insensitive" end end context "in safe mode" do setup do - @tag = Jekyll::Tags::HighlightBlock.new('highlight', 'text ', ["test", "{% endhighlight %}", "\n"]) + @tag = highlight_block_with_opts('text ') end should "allow linenos" do From 70a331d8547e79454cdbc2e27da392cea30c499b Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 29 Oct 2014 15:04:35 -0700 Subject: [PATCH 2/5] Set the error mode to :strict --- Gemfile | 2 +- lib/jekyll.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index d680ef69..7c91f262 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' gemspec -gem "liquid", github: 'Shopify/liquid' +gem "liquid", github: 'Shopify/liquid', branch: '3-0-0-rc1' if ENV['BENCHMARK'] gem 'rbtrace' diff --git a/lib/jekyll.rb b/lib/jekyll.rb index 911b3ddb..45c9a4d5 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -30,6 +30,7 @@ require 'kramdown' require 'colorator' SafeYAML::OPTIONS[:suppress_warnings] = true +Liquid::Template.error_mode = :strict module Jekyll From 3940e1e9df2573a8ad26727360213c94edd6ca04 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 12 Nov 2014 16:00:26 -0800 Subject: [PATCH 3/5] Bump to Liquid 3.0 --- Gemfile | 1 - jekyll.gemspec | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 7c91f262..25b40ed2 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,5 @@ source 'https://rubygems.org' gemspec -gem "liquid", github: 'Shopify/liquid', branch: '3-0-0-rc1' if ENV['BENCHMARK'] gem 'rbtrace' diff --git a/jekyll.gemspec b/jekyll.gemspec index c9876c47..a7bd0d5b 100644 --- a/jekyll.gemspec +++ b/jekyll.gemspec @@ -28,7 +28,7 @@ Gem::Specification.new do |s| s.rdoc_options = ['--charset=UTF-8'] s.extra_rdoc_files = %w[README.markdown LICENSE] - #s.add_runtime_dependency('liquid', '') + s.add_runtime_dependency('liquid', '~> 3.0') s.add_runtime_dependency('kramdown', '~> 1.3') s.add_runtime_dependency('mercenary', '~> 0.3.3') s.add_runtime_dependency('safe_yaml', '~> 1.0') From b68dd3a5cb8366507c80c37c3ac1f13c71a498c1 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Mon, 15 Dec 2014 16:27:24 -0800 Subject: [PATCH 4/5] Add liquid c if it's available. --- jekyll.gemspec | 1 + lib/jekyll.rb | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/jekyll.gemspec b/jekyll.gemspec index a7bd0d5b..9631b348 100644 --- a/jekyll.gemspec +++ b/jekyll.gemspec @@ -63,6 +63,7 @@ Gem::Specification.new do |s| s.add_development_dependency('jekyll_test_plugin') s.add_development_dependency('jekyll_test_plugin_malicious') s.add_development_dependency('rouge', '~> 1.7') + s.add_development_dependency('liquid-c', '~> 0.0.2') s.add_development_dependency('minitest') if RUBY_PLATFORM =~ /cygwin/ s.add_development_dependency('test-unit') if RUBY_PLATFORM =~ /cygwin/ end diff --git a/lib/jekyll.rb b/lib/jekyll.rb index 45c9a4d5..bde11581 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -29,6 +29,12 @@ require 'liquid' require 'kramdown' require 'colorator' +# Conditional optimizations +begin + require 'liquid-c' +rescue LoadError +end + SafeYAML::OPTIONS[:suppress_warnings] = true Liquid::Template.error_mode = :strict From 8bfc696569057955dbeeb4fe6e0652d0189c163c Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Thu, 25 Dec 2014 14:42:15 -0500 Subject: [PATCH 5/5] liquid-c 0.0.3 --- jekyll.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jekyll.gemspec b/jekyll.gemspec index 9631b348..7d0a97fc 100644 --- a/jekyll.gemspec +++ b/jekyll.gemspec @@ -63,7 +63,7 @@ Gem::Specification.new do |s| s.add_development_dependency('jekyll_test_plugin') s.add_development_dependency('jekyll_test_plugin_malicious') s.add_development_dependency('rouge', '~> 1.7') - s.add_development_dependency('liquid-c', '~> 0.0.2') + s.add_development_dependency('liquid-c', '~> 0.0.3') s.add_development_dependency('minitest') if RUBY_PLATFORM =~ /cygwin/ s.add_development_dependency('test-unit') if RUBY_PLATFORM =~ /cygwin/ end