Sha256: ac529a67b7402dc796012771b93fbe9f7e690de3675a27979c8ca8f6c0d3eb13
Contents?: true
Size: 940 Bytes
Versions: 3
Compression:
Stored size: 940 Bytes
Contents
# frozen_string_literal: true module Liquid class Tokenizer attr_reader :line_number, :for_liquid_tag def initialize(source, line_numbers = false, line_number: nil, for_liquid_tag: false) @source = source @line_number = line_number || (line_numbers ? 1 : nil) @for_liquid_tag = for_liquid_tag @offset = 0 @tokens = tokenize end def shift token = @tokens[@offset] return nil unless token @offset += 1 if @line_number @line_number += @for_liquid_tag ? 1 : token.count("\n") end token end private def tokenize return [] if @source.empty? return @source.split("\n") if @for_liquid_tag tokens = @source.split(TemplateParser) # removes the rogue empty element at the beginning of the array if tokens[0]&.empty? @offset += 1 end tokens end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
liquid-5.6.0.rc1 | lib/liquid/tokenizer.rb |
liquid-5.5.1 | lib/liquid/tokenizer.rb |
liquid-5.5.0 | lib/liquid/tokenizer.rb |