Sha256: f66462975660559e302b0dbac7de78b61f454a651da565b536ae2e69940ee90a

Contents?: true

Size: 1.52 KB

Versions: 17

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

module PlatformosCheck
  class LiquidFile < AppFile
    def write
      content = rewriter.to_s
      return unless source != content

      @storage.write(@relative_path, content.gsub("\n", @eol))
      @source = content
      @rewriter = nil
    end

    def liquid?
      true
    end

    def notification?
      false
    end

    def migration?
      false
    end

    def page?
      false
    end

    def form?
      false
    end

    def partial?
      false
    end

    def layout?
      false
    end

    def rewriter
      @rewriter ||= AppFileRewriter.new(@relative_path, source)
    end

    def source_excerpt(line)
      original_lines = source.split("\n")
      original_lines[bounded(0, line - 1, original_lines.size - 1)].strip
    rescue StandardError => e
      PlatformosCheck.bug(<<~EOS)
        Exception while running `source_excerpt(#{line})`:
        ```
        #{e.class}: #{e.message}
          #{e.backtrace.join("\n  ")}
        ```

        path: #{path}

        source:
        ```
        #{source}
        ```
      EOS
    end

    def parse
      @ast ||= self.class.parse(source)
    end

    def warnings
      @ast.warnings
    end

    def root
      parse.root
    end

    def self.parse(source)
      Tags.register_tags!
      Liquid::Template.parse(
        source,
        line_numbers: true,
        error_mode: :warn,
        disable_liquid_c_nodes: true
      )
    end

    private

    def bounded(lower, x, upper)
      [lower, [x, upper].min].max
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
platformos-check-0.4.7 lib/platformos_check/liquid_file.rb
platformos-check-0.4.6 lib/platformos_check/liquid_file.rb
platformos-check-0.4.5 lib/platformos_check/liquid_file.rb
platformos-check-0.4.4 lib/platformos_check/liquid_file.rb
platformos-check-0.4.3 lib/platformos_check/liquid_file.rb
platformos-check-0.4.2 lib/platformos_check/liquid_file.rb
platformos-check-0.4.1 lib/platformos_check/liquid_file.rb
platformos-check-0.4.0 lib/platformos_check/liquid_file.rb
platformos-check-0.3.3 lib/platformos_check/liquid_file.rb
platformos-check-0.3.1 lib/platformos_check/liquid_file.rb
platformos-check-0.3.0 lib/platformos_check/liquid_file.rb
platformos-check-0.2.2 lib/platformos_check/liquid_file.rb
platformos-check-0.2.1 lib/platformos_check/liquid_file.rb
platformos-check-0.2.0 lib/platformos_check/liquid_file.rb
platformos-check-0.1.0 lib/platformos_check/liquid_file.rb
platformos-check-0.0.3 lib/platformos_check/liquid_file.rb
platformos-check-0.0.2 lib/platformos_check/liquid_file.rb