Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Raw tag for jekyll. Keeps liquid from parsing text betweeen {% raw %} and {% endraw %}
module Jekyll
class RawTag < Liquid::Block
def parse(tokens)
@nodelist ||= []
@nodelist.clear
while token = tokens.shift
if token =~ FullToken
if block_delimiter == $1
end_tag
return
end
end
@nodelist << token if not token.empty?
end
end
end
end
Liquid::Template.register_tag('raw', Jekyll::RawTag)
@phaer

This comment has been minimized.

Show comment Hide comment
@phaer

phaer Jun 13, 2011

titanous added it to shopify's liquid fork and wrote a test for it: https://github.com/Shopify/liquid/blob/4087a94d881c53b803f1d682db7e4676a6f4d714/test/lib/liquid/tags/raw_test.rb

require 'test_helper'

class RawTest < Test::Unit::TestCase
include Liquid

  def test_tag_in_raw
    assert_template_result '{% comment %} test {% endcomment %}',
                           '{% raw %}{% comment %} test {% endcomment %}{% endraw %}'
  end

  def test_output_in_raw
    assert_template_result '{{ test }}',
                           '{% raw %}{{ test }}{% endraw %}'
  end
end

Thanks!

Owner

phaer commented Jun 13, 2011

titanous added it to shopify's liquid fork and wrote a test for it: https://github.com/Shopify/liquid/blob/4087a94d881c53b803f1d682db7e4676a6f4d714/test/lib/liquid/tags/raw_test.rb

require 'test_helper'

class RawTest < Test::Unit::TestCase
include Liquid

  def test_tag_in_raw
    assert_template_result '{% comment %} test {% endcomment %}',
                           '{% raw %}{% comment %} test {% endcomment %}{% endraw %}'
  end

  def test_output_in_raw
    assert_template_result '{{ test }}',
                           '{% raw %}{{ test }}{% endraw %}'
  end
end

Thanks!

@marcysutton

This comment has been minimized.

Show comment Hide comment
@marcysutton

marcysutton Jun 23, 2014

Does this work with Sass in Jekyll 2x?

Does this work with Sass in Jekyll 2x?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment