liquid_debug 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 57811020ce04cde0d01a92b390e07da1cc07570fd4a4f00dfc1a6f1ad06ac190
4
+ data.tar.gz: '029fca25a639048845e1234365cc593859e995d9c4e36c5a6dbbfaff70e0bdfb'
5
+ SHA512:
6
+ metadata.gz: b32f623950ab79e8b62b53796afe7853b80ea0b1d4693b0ec34bd08837370d83adb7dbd6344daeaf91b8ba739d934f5c85105dfbc6908d4e6b7d6938eba311f4
7
+ data.tar.gz: ee5b851bf75baf69141e2819b3e9a4555e83146e9336e4b1f9605cf716996a5303727c19b6ab4af675ccfb0d4f30a340d210ed669261b03cf9c0dd037cfd20ae
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ *.swp
13
+ *.swo
14
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in liquid_debug.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,60 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ liquid_debug (0.0.1)
5
+ paint (= 2.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.0)
11
+ concurrent-ruby (1.1.5)
12
+ diff-lcs (1.3)
13
+ i18n (1.6.0)
14
+ concurrent-ruby (~> 1.0)
15
+ jaro_winkler (1.5.2)
16
+ paint (2.1.0)
17
+ parallel (1.17.0)
18
+ parser (2.6.3.0)
19
+ ast (~> 2.4.0)
20
+ rainbow (3.0.0)
21
+ rake (10.5.0)
22
+ rspec (3.8.0)
23
+ rspec-core (~> 3.8.0)
24
+ rspec-expectations (~> 3.8.0)
25
+ rspec-mocks (~> 3.8.0)
26
+ rspec-core (3.8.0)
27
+ rspec-support (~> 3.8.0)
28
+ rspec-expectations (3.8.3)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.8.0)
31
+ rspec-mocks (3.8.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.8.0)
34
+ rspec-support (3.8.0)
35
+ rubocop (0.68.1)
36
+ jaro_winkler (~> 1.5.1)
37
+ parallel (~> 1.10)
38
+ parser (>= 2.5, != 2.5.1.1)
39
+ rainbow (>= 2.2.2, < 4.0)
40
+ ruby-progressbar (~> 1.7)
41
+ unicode-display_width (>= 1.4.0, < 1.6)
42
+ ruby-progressbar (1.10.0)
43
+ strong_versions (0.3.2)
44
+ i18n (>= 0.5.0)
45
+ paint (~> 2.0)
46
+ unicode-display_width (1.5.0)
47
+
48
+ PLATFORMS
49
+ ruby
50
+
51
+ DEPENDENCIES
52
+ bundler (~> 2.0)
53
+ liquid_debug!
54
+ rake (~> 10.0)
55
+ rspec (~> 3.0)
56
+ rubocop (~> 0.68.1)
57
+ strong_versions (~> 0.3.2)
58
+
59
+ BUNDLED WITH
60
+ 2.0.1
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # LiquidDebug
2
+
3
+ ## Overview
4
+
5
+ _LiquidDebug_ provides a stack trace of executed [_Liquid_](https://shopify.github.io/liquid/) code when an error occurs, supplementing the [typically vague] default error format provided by _Liquid_.
6
+
7
+ It is _not_ suitable for a production environment as it makes no effort to account for performance or memory leak issues and so should only be used in a development environment when debugging specific issues.
8
+
9
+ ## Installation
10
+
11
+ Add the following to your `Gemfile`:
12
+
13
+ ```
14
+ gem 'liquid_debug', '~> 0.0.1'
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ Include the _LiquidDebug_ extension (e.g. in an initializer or in `config/application.rb`):
20
+
21
+ ```
22
+ # config/initializers/liquid_debug.rb
23
+ require 'liquid/debug' if Rails.env.development?
24
+ ```
25
+
26
+ You should now see something like this in your server output when a _Liquid_ error occurs:
27
+
28
+ ![example](images/screenshot.png)
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "liquid_debug"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
Binary file
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'liquid_debug'
4
+
5
+ module LiquidDebug
6
+ module TagTracker
7
+ def render(*_args)
8
+ LiquidDebug.track(@tag_name, @markup)
9
+ super
10
+ end
11
+ end
12
+
13
+ module ContextErrorHandler
14
+ def handle_error(error, *args)
15
+ LiquidDebug::ErrorHandler.new(error, LiquidDebug.stack).print
16
+ LiquidDebug.reset
17
+ super
18
+ end
19
+ end
20
+ end
21
+
22
+ require 'liquid'
23
+
24
+ unless ENV.key?('LIQUID_DEBUG_DISABLE')
25
+ Liquid::Context.prepend LiquidDebug::ContextErrorHandler
26
+ Liquid::Tag.descendants.each { |tag| tag.prepend(LiquidDebug::TagTracker) }
27
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LiquidDebug
4
+ class ErrorHandler
5
+ def initialize(error, stack)
6
+ @error = error
7
+ @stack = stack
8
+ end
9
+
10
+ def print(limit = 10)
11
+ report(limit)
12
+ end
13
+
14
+ private
15
+
16
+ # rubocop:disable Metrics/AbcSize
17
+ def report(limit)
18
+ backtrace = trace(limit)
19
+ return nil if backtrace.empty?
20
+
21
+ puts("\n" + red(@error.to_s))
22
+ puts(message(limit, backtrace))
23
+ if backtrace.size > 1
24
+ backtrace[0...-1].each { |frame| puts(" #{frame}") }
25
+ end
26
+
27
+ puts(open_highlight + backtrace[-1] + close_highlight)
28
+ puts("\n")
29
+ end
30
+ # rubocop:enable Metrics/AbcSize
31
+
32
+ def trace(limit)
33
+ @stack.last(limit).map { |frame| format(frame) }.compact
34
+ end
35
+
36
+ def format(frame)
37
+ return nil if frame[:tag_name].nil? && frame[:markup].nil?
38
+
39
+ tag = frame[:tag_name]
40
+ "#{open_tag} #{tag_name(tag)} #{markup(frame[:markup])}#{close_tag}"
41
+ end
42
+
43
+ def open_tag
44
+ Paint['{%', :cyan]
45
+ end
46
+
47
+ def close_tag
48
+ Paint['%}', :cyan]
49
+ end
50
+
51
+ def open_highlight
52
+ Paint['=> ', :red, :bright]
53
+ end
54
+
55
+ def close_highlight
56
+ Paint[' <=', :red, :bright]
57
+ end
58
+
59
+ def tag_name(name)
60
+ Paint[name, :yellow]
61
+ end
62
+
63
+ def markup(text)
64
+ Paint[text, :cyan, :bright]
65
+ end
66
+
67
+ def message(_limit, _backtrace)
68
+ Paint['Backtrace:', :white] + "\n\n"
69
+ end
70
+
71
+ def red(text)
72
+ Paint[text, :red]
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LiquidDebug
4
+ VERSION = '0.0.1'
5
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'liquid_debug/version'
4
+ require 'liquid_debug/error_handler'
5
+
6
+ module LiquidDebug
7
+ class Error < StandardError; end
8
+
9
+ def self.track(tag_name, markup)
10
+ stack.push(tag_name: tag_name, markup: markup)
11
+ end
12
+
13
+ def self.reset
14
+ stack.clear
15
+ end
16
+
17
+ def self.stack
18
+ @stack ||= []
19
+ end
20
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'liquid_debug/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'liquid_debug'
9
+ spec.version = LiquidDebug::VERSION
10
+ spec.authors = ['Bob Farrell']
11
+ spec.email = ['robertanthonyfarrell@gmail.com']
12
+
13
+ spec.summary = "Debug Shopify's Liquid templating language"
14
+ spec.description = 'Extends Liquid for enhanced debugging'
15
+ spec.homepage = 'https://github.com/bobf/liquid_debug'
16
+
17
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
18
+ `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ end
22
+
23
+ spec.bindir = 'exe'
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ['lib']
26
+
27
+ spec.add_runtime_dependency 'paint', '2.1'
28
+
29
+ spec.add_development_dependency 'bundler', '~> 2.0'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rspec', '~> 3.0'
32
+ spec.add_development_dependency 'rubocop', '~> 0.68.1'
33
+ spec.add_development_dependency 'strong_versions', '~> 0.3.2'
34
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: liquid_debug
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Bob Farrell
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: paint
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.68.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.68.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: strong_versions
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.3.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.3.2
97
+ description: Extends Liquid for enhanced debugging
98
+ email:
99
+ - robertanthonyfarrell@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - images/screenshot.png
114
+ - lib/liquid/debug.rb
115
+ - lib/liquid_debug.rb
116
+ - lib/liquid_debug/error_handler.rb
117
+ - lib/liquid_debug/version.rb
118
+ - liquid_debug.gemspec
119
+ homepage: https://github.com/bobf/liquid_debug
120
+ licenses: []
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.7.6
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Debug Shopify's Liquid templating language
142
+ test_files: []