Class: Jekyll::RawInclude

Inherits:
Liquid::Block
  • Object
show all
Includes:
LiquidFilters
Defined in:
rawinclude.rb

Constant Summary collapse

FullTokenPossiblyInvalid =
/\A(.*)#{Liquid::TagStart}\s*(\w+)\s*(.*)?#{Liquid::TagEnd}\z/om

Instance Method Summary collapse

Methods included from LiquidFilters

#liquidify, #unliquidify

Constructor Details

#initialize(tag_name, params, tokens) ⇒ RawInclude

Returns a new instance of RawInclude.



18
19
20
21
# File 'rawinclude.rb', line 18

def initialize(tag_name, params, tokens)
  super
  @params = params
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'rawinclude.rb', line 48

def blank?
  @body.empty?
end

#nodelistObject



44
45
46
# File 'rawinclude.rb', line 44

def nodelist
  [@body]
end

#parse(tokens) ⇒ Object

Raises:

  • (Liquid::SyntaxError)


23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'rawinclude.rb', line 23

def parse(tokens)
  @body = ''
  while token = tokens.shift
    if token =~ FullTokenPossiblyInvalid
      @body << Regexp.last_match(1) if Regexp.last_match(1) != ''.freeze
      return if block_delimiter == Regexp.last_match(2)
    end
    @body << token unless token.empty?
  end

  raise Liquid::SyntaxError,
        parse_context.locale.t('errors.syntax.tag_never_closed'.freeze, block_name: block_name)
end

#render(context) ⇒ Object



37
38
39
40
41
42
# File 'rawinclude.rb', line 37

def render(context)
  uri_data = escape_quotes(URI.escape(@body.slice(1, @body.length)))
  Liquid::Template.parse("{% include #{@params}
                             block='#{escape_quotes(unliquidify(@body))}'
                             uri_data='#{uri_data}' %}").render(context)
end