From 0d5c9e4313d4416dd18235cdfb5c52608e73823d Mon Sep 17 00:00:00 2001 From: Shawn Van Ittersum Date: Tue, 31 May 2016 13:15:21 -0700 Subject: [PATCH] Prevent overwrite of Slim embedded options (#1927) * Fix middleman/middleman#1925: Slim embedded options overwrite * Remove context_hack from Slim renderer * Remove debugging output --- .../markdown_redcarpet_in_slim.feature | 41 +++++++++++++++++++ middleman-core/features/sass_in_slim.feature | 40 ++++++++++++++++++ .../fixtures/sass-in-slim-app/config.rb | 0 .../lib/middleman-core/renderers/slim.rb | 6 +-- 4 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 middleman-core/features/markdown_redcarpet_in_slim.feature create mode 100644 middleman-core/features/sass_in_slim.feature create mode 100644 middleman-core/fixtures/sass-in-slim-app/config.rb diff --git a/middleman-core/features/markdown_redcarpet_in_slim.feature b/middleman-core/features/markdown_redcarpet_in_slim.feature new file mode 100644 index 00000000..250c6857 --- /dev/null +++ b/middleman-core/features/markdown_redcarpet_in_slim.feature @@ -0,0 +1,41 @@ +Feature: Markdown support in Slim + In order to test support of the Slim markdown filter + + Scenario: Markdown filter in Slim works + Given a fixture app "markdown-in-slim-app" + And a file named "config.rb" with: + """ + set :markdown_engine, :redcarpet + activate :directory_indexes + """ + And a file named "source/markdown_filter.html.slim" with: + """ + markdown: + # H1 + + paragraph + """ + Given the Server is running at "markdown-in-slim-app" + When I go to "/markdown_filter/" + Then I should see ">H1" + Then I should see "

paragraph

" + + + Scenario: Markdown filter in Slim uses our link_to and image_tag helpers + Given a fixture app "markdown-in-slim-app" + And a file named "config.rb" with: + """ + set :markdown_engine, :redcarpet + activate :directory_indexes + """ + And a file named "source/link_and_image.html.slim" with: + """ + markdown: + [A link](/link_target.html) + + ![image](blank.gif) + """ + Given the Server is running at "markdown-in-slim-app" + When I go to "/link_and_image/" + Then I should see "/link_target/" + Then I should see 'src="/images/blank.gif"' diff --git a/middleman-core/features/sass_in_slim.feature b/middleman-core/features/sass_in_slim.feature new file mode 100644 index 00000000..d04055e4 --- /dev/null +++ b/middleman-core/features/sass_in_slim.feature @@ -0,0 +1,40 @@ +Feature: Sass/SCSS support in Slim + In order to test support of the Slim sass and scss filters + + Scenario: Sass filter in Slim works + Given a fixture app "sass-in-slim-app" + And a file named "config.rb" with: + """ + activate :directory_indexes + """ + And a file named "source/sass_filter.html.slim" with: + """ + sass: + .sass + margin: 0 + """ + Given the Server is running at "sass-in-slim-app" + When I go to "/sass_filter/" + Then I should see "text/css" + Then I should see ".sass" + Then I should see "margin:0" + + + Scenario: SCSS filter in Slim works + Given a fixture app "sass-in-slim-app" + And a file named "config.rb" with: + """ + activate :directory_indexes + """ + And a file named "source/scss_filter.html.slim" with: + """ + scss: + .scss { + margin: 0; + } + """ + Given the Server is running at "sass-in-slim-app" + When I go to "/scss_filter/" + Then I should see "text/css" + Then I should see ".scss" + Then I should see "margin:0" diff --git a/middleman-core/fixtures/sass-in-slim-app/config.rb b/middleman-core/fixtures/sass-in-slim-app/config.rb new file mode 100644 index 00000000..e69de29b diff --git a/middleman-core/lib/middleman-core/renderers/slim.rb b/middleman-core/lib/middleman-core/renderers/slim.rb index 16640f4a..818382ad 100644 --- a/middleman-core/lib/middleman-core/renderers/slim.rb +++ b/middleman-core/lib/middleman-core/renderers/slim.rb @@ -12,13 +12,9 @@ class ::Slim::Template def initialize(file, line, opts, &block) if opts.key?(:context) - context_hack = { - context: opts[:context] - } - ::Slim::Embedded::SassEngine.disable_option_validator! %w(sass scss markdown).each do |engine| - ::Slim::Embedded.options[engine.to_sym] = context_hack + (::Slim::Embedded.options[engine.to_sym] ||= {})[:context] = opts[:context] end end