liquid_debug 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 57811020ce04cde0d01a92b390e07da1cc07570fd4a4f00dfc1a6f1ad06ac190
4
- data.tar.gz: '029fca25a639048845e1234365cc593859e995d9c4e36c5a6dbbfaff70e0bdfb'
3
+ metadata.gz: e1861e7bad6122012f2eb6e61ce15f8f8a988b2b39d608593ac178a5a4697388
4
+ data.tar.gz: aee73e856a973625288ec1b8659949c0677c992b6a7635230ee079f67a1b57e0
5
5
  SHA512:
6
- metadata.gz: b32f623950ab79e8b62b53796afe7853b80ea0b1d4693b0ec34bd08837370d83adb7dbd6344daeaf91b8ba739d934f5c85105dfbc6908d4e6b7d6938eba311f4
7
- data.tar.gz: ee5b851bf75baf69141e2819b3e9a4555e83146e9336e4b1f9605cf716996a5303727c19b6ab4af675ccfb0d4f30a340d210ed669261b03cf9c0dd037cfd20ae
6
+ metadata.gz: 2be0f5d00d93a7bd405df86c359179f57c83b24cae040a7d29e4bcc8dc7c9684d911cb9b6d61955636db607b0ada3a6393d7a8675d1db1776b5ca7e6fcd39e7c
7
+ data.tar.gz: b055558c45eaf8c85d45a940b07bfcc12af2d098c5748da8fdc3880d2e553d4e04dce3eead8a3897d412eb15ef3494a9a117ccbadd1e031e942ae1947d892e25
@@ -0,0 +1,5 @@
1
+ Style/Documentation:
2
+ Enabled: false
3
+ Metrics/BlockLength:
4
+ Exclude:
5
+ - 'spec/**/*'
@@ -2,17 +2,21 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  liquid_debug (0.0.1)
5
- paint (= 2.1)
5
+ liquid (~> 4.0)
6
+ paint (~> 2.1)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
11
  ast (2.4.0)
12
+ betterp (0.1.3)
13
+ paint (~> 2.0)
11
14
  concurrent-ruby (1.1.5)
12
15
  diff-lcs (1.3)
13
16
  i18n (1.6.0)
14
17
  concurrent-ruby (~> 1.0)
15
18
  jaro_winkler (1.5.2)
19
+ liquid (4.0.3)
16
20
  paint (2.1.0)
17
21
  parallel (1.17.0)
18
22
  parser (2.6.3.0)
@@ -28,6 +32,9 @@ GEM
28
32
  rspec-expectations (3.8.3)
29
33
  diff-lcs (>= 1.2.0, < 2.0)
30
34
  rspec-support (~> 3.8.0)
35
+ rspec-its (1.3.0)
36
+ rspec-core (>= 3.0.0)
37
+ rspec-expectations (>= 3.0.0)
31
38
  rspec-mocks (3.8.0)
32
39
  diff-lcs (>= 1.2.0, < 2.0)
33
40
  rspec-support (~> 3.8.0)
@@ -49,10 +56,12 @@ PLATFORMS
49
56
  ruby
50
57
 
51
58
  DEPENDENCIES
59
+ betterp (~> 0.1.3)
52
60
  bundler (~> 2.0)
53
61
  liquid_debug!
54
62
  rake (~> 10.0)
55
63
  rspec (~> 3.0)
64
+ rspec-its (~> 1.3)
56
65
  rubocop (~> 0.68.1)
57
66
  strong_versions (~> 0.3.2)
58
67
 
@@ -0,0 +1,4 @@
1
+ test:
2
+ bundle exec rspec
3
+ bundle exec rubocop
4
+ bundle exec strong_versions
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "liquid_debug"
4
+ require 'bundler/setup'
5
+ require 'liquid_debug'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "liquid_debug"
10
11
  # require "pry"
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
@@ -10,6 +10,13 @@ module LiquidDebug
10
10
  end
11
11
  end
12
12
 
13
+ module VariableTracker
14
+ def render(*_args)
15
+ LiquidDebug.track(nil, @markup)
16
+ super
17
+ end
18
+ end
19
+
13
20
  module ContextErrorHandler
14
21
  def handle_error(error, *args)
15
22
  LiquidDebug::ErrorHandler.new(error, LiquidDebug.stack).print
@@ -23,5 +30,8 @@ require 'liquid'
23
30
 
24
31
  unless ENV.key?('LIQUID_DEBUG_DISABLE')
25
32
  Liquid::Context.prepend LiquidDebug::ContextErrorHandler
26
- Liquid::Tag.descendants.each { |tag| tag.prepend(LiquidDebug::TagTracker) }
33
+ ObjectSpace.each_object(Class)
34
+ .select { |class_| class_ < Liquid::Tag }
35
+ .each { |class_| class_.prepend(LiquidDebug::TagTracker) }
36
+ Liquid::Variable.prepend(LiquidDebug::VariableTracker)
27
37
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'paint'
4
+
3
5
  require 'liquid_debug/version'
4
6
  require 'liquid_debug/error_handler'
5
7
 
@@ -17,4 +19,8 @@ module LiquidDebug
17
19
  def self.stack
18
20
  @stack ||= []
19
21
  end
22
+
23
+ def self.output
24
+ STDOUT
25
+ end
20
26
  end
@@ -2,30 +2,34 @@
2
2
 
3
3
  module LiquidDebug
4
4
  class ErrorHandler
5
- def initialize(error, stack)
5
+ def initialize(error, stack, output = LiquidDebug.output)
6
6
  @error = error
7
7
  @stack = stack
8
+ @output = output
8
9
  end
9
10
 
10
11
  def print(limit = 10)
11
12
  report(limit)
12
13
  end
13
14
 
15
+ def backtrace(limit = 10)
16
+ @backtrace ||= trace(limit)
17
+ end
18
+
14
19
  private
15
20
 
16
21
  # rubocop:disable Metrics/AbcSize
17
22
  def report(limit)
18
- backtrace = trace(limit)
19
23
  return nil if backtrace.empty?
20
24
 
21
- puts("\n" + red(@error.to_s))
22
- puts(message(limit, backtrace))
25
+ @output.puts("\n" + red(@error.to_s))
26
+ @output.puts(message(limit, backtrace))
23
27
  if backtrace.size > 1
24
- backtrace[0...-1].each { |frame| puts(" #{frame}") }
28
+ backtrace[0...-1].each { |frame| @output.puts(" #{frame}") }
25
29
  end
26
30
 
27
- puts(open_highlight + backtrace[-1] + close_highlight)
28
- puts("\n")
31
+ @output.puts(open_highlight + backtrace[-1] + close_highlight)
32
+ @output.puts("\n")
29
33
  end
30
34
  # rubocop:enable Metrics/AbcSize
31
35
 
@@ -37,6 +41,16 @@ module LiquidDebug
37
41
  return nil if frame[:tag_name].nil? && frame[:markup].nil?
38
42
 
39
43
  tag = frame[:tag_name]
44
+ return variable_tag(frame) if tag.nil?
45
+
46
+ standard_tag(frame, tag)
47
+ end
48
+
49
+ def variable_tag(frame)
50
+ "#{open_var} #{markup(frame[:markup])} #{close_var}"
51
+ end
52
+
53
+ def standard_tag(frame, tag)
40
54
  "#{open_tag} #{tag_name(tag)} #{markup(frame[:markup])}#{close_tag}"
41
55
  end
42
56
 
@@ -48,6 +62,14 @@ module LiquidDebug
48
62
  Paint['%}', :cyan]
49
63
  end
50
64
 
65
+ def open_var
66
+ Paint['{{', :cyan]
67
+ end
68
+
69
+ def close_var
70
+ Paint['}}', :cyan]
71
+ end
72
+
51
73
  def open_highlight
52
74
  Paint['=> ', :red, :bright]
53
75
  end
@@ -61,7 +83,7 @@ module LiquidDebug
61
83
  end
62
84
 
63
85
  def markup(text)
64
- Paint[text, :cyan, :bright]
86
+ Paint[text, :cyan, :bright].strip
65
87
  end
66
88
 
67
89
  def message(_limit, _backtrace)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LiquidDebug
4
- VERSION = '0.0.1'
4
+ VERSION = '0.1.0'
5
5
  end
@@ -3,6 +3,7 @@
3
3
  lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'liquid_debug/version'
6
+ require 'rspec/its'
6
7
 
7
8
  Gem::Specification.new do |spec|
8
9
  spec.name = 'liquid_debug'
@@ -24,11 +25,14 @@ Gem::Specification.new do |spec|
24
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
26
  spec.require_paths = ['lib']
26
27
 
27
- spec.add_runtime_dependency 'paint', '2.1'
28
+ spec.add_runtime_dependency 'liquid', '~> 4.0'
29
+ spec.add_runtime_dependency 'paint', '~> 2.1'
28
30
 
31
+ spec.add_development_dependency 'betterp', '~> 0.1.3'
29
32
  spec.add_development_dependency 'bundler', '~> 2.0'
30
33
  spec.add_development_dependency 'rake', '~> 10.0'
31
34
  spec.add_development_dependency 'rspec', '~> 3.0'
35
+ spec.add_development_dependency 'rspec-its', '~> 1.3'
32
36
  spec.add_development_dependency 'rubocop', '~> 0.68.1'
33
37
  spec.add_development_dependency 'strong_versions', '~> 0.3.2'
34
38
  end
metadata CHANGED
@@ -1,29 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liquid_debug
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Farrell
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-08 00:00:00.000000000 Z
11
+ date: 2019-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: liquid
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: paint
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
- - - '='
31
+ - - "~>"
18
32
  - !ruby/object:Gem::Version
19
33
  version: '2.1'
20
34
  type: :runtime
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
- - - '='
38
+ - - "~>"
25
39
  - !ruby/object:Gem::Version
26
40
  version: '2.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: betterp
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.3
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.3
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: bundler
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +94,20 @@ dependencies:
66
94
  - - "~>"
67
95
  - !ruby/object:Gem::Version
68
96
  version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-its
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.3'
69
111
  - !ruby/object:Gem::Dependency
70
112
  name: rubocop
71
113
  requirement: !ruby/object:Gem::Requirement
@@ -103,9 +145,11 @@ extra_rdoc_files: []
103
145
  files:
104
146
  - ".gitignore"
105
147
  - ".rspec"
148
+ - ".rubocop.yml"
106
149
  - ".travis.yml"
107
150
  - Gemfile
108
151
  - Gemfile.lock
152
+ - Makefile
109
153
  - README.md
110
154
  - Rakefile
111
155
  - bin/console