roda-debug_bar 0.2.0 → 0.3.0.pre.rc1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a81b9b197aece30bf9fb928d9395a6f8a1926053c3cd3d2e6c6e03bf7560bf5
4
- data.tar.gz: 1f33f1cc90ccb8d77dda10f75af4d52b7ef58401151baaabe5b148079ece2f9a
3
+ metadata.gz: 15184bb57f4138f00506b033ca263fec092caf7449065e03b336d4ca8546e0db
4
+ data.tar.gz: a5502c77d34dfe0b90f76d1852c9b75667461125cb7420f5e354ffe2c21f8470
5
5
  SHA512:
6
- metadata.gz: 9742307c5e57fe1ec22ad37061d64bf2239d30f12ecfaec07f806ae16ebb2d2aabf4acbf81c6f8e27059ed460fbad6cf6ea1be469a6683cca35c356a1f74844f
7
- data.tar.gz: 78cf79cf7353d43112235a731d41b9ce4d7a4391b0f8c74244e0d661d0233ef1c36673e726243f2c295617d1a50fb260164067436ffe94917b1524cd07674b6f
6
+ metadata.gz: 64d66a9ae24bd2f321a0d3e1acc4e45d87aa699fc1d1b50d1ec8d1c5e77de594f6999d4b3945ce41751c84ffa3da5fdbec17134736d6d0b45de2a0634a9c6244
7
+ data.tar.gz: 78c82cf53c8a5b272b98b713fff0ec5ac0d8a87fd357c4f9508993ee9d961685e2670e4d9fcac3c5203e46f24be0536584ebf08d2236c341cb9948c446396701
@@ -0,0 +1,120 @@
1
+ module HTMLFormatter
2
+ class RubyHash
3
+
4
+ SCOPE = 'highlight ruby hash'
5
+
6
+ PUNCTUATION = 'p'
7
+ WHITESPACE = 'w'
8
+ INTEGER = 'mi'
9
+ FLOAT = 'mf'
10
+ STRING = 's2' # double-quoted
11
+ CONSTANT = 'kc'
12
+ SYMBOL = 'ss'
13
+
14
+ EXPANDABLE = 'exp'
15
+
16
+
17
+ def initialize
18
+ @index = 0
19
+ end
20
+
21
+ def self.parse(source, start_open: true)
22
+ instance = new
23
+ instance.parse(source, start_open: start_open)
24
+ end
25
+
26
+ def parse(source, start_open: true)
27
+ # Don't apply highlighting if it's a string
28
+ return source if source.is_a? String
29
+
30
+ html = parse_value(source)
31
+ open_states = [false] * @index
32
+ open_states[0] = true if start_open # open to first level
33
+ "<div x-data='{state: #{open_states}}' class='#{SCOPE} w-96'>#{html}</div>"
34
+ end
35
+
36
+ def parse_value(value)
37
+ case value
38
+ in Hash
39
+ parse_hash(value)
40
+ in Array
41
+ parse_array(value)
42
+ in _
43
+ parse_terminal(value)
44
+ end
45
+ end
46
+
47
+ def parse_hash(hash)
48
+ return '{}' if hash.empty?
49
+ i = @index
50
+ @index += 1
51
+ html = "<button x-show='state[#{i}]' @click='state[#{i}] = false' class='focus:outline-none'><span class='#{EXPANDABLE}'>hash:#{hash.size} </span><span>{</span><span class='#{PUNCTUATION}'>▼</span></button>"
52
+ html += "<button x-show='!state[#{i}]' @click='state[#{i}] = true' class='focus:outline-none'><span class='#{EXPANDABLE}'>hash:#{hash.size} </span><span>{</span><span class='#{PUNCTUATION}'>▶</span><span class='#{EXPANDABLE}'></span><span>}</span></button>"
53
+ # html += "<dl x-show='state[#{i}]' class='grid grid-cols-2 ml-4'>"
54
+ html += "<dl x-show='state[#{i}]' class='ml-4'>"
55
+ hash.each do |key, value|
56
+ html += "<span class='flex'>"
57
+ html += "<dt class='#{SYMBOL}'>#{key}:&nbsp</dt>"
58
+ # html += "<span class='#{PUNCTUATION}'>=>&nbsp</span>"
59
+ html += "<dd>#{parse_value(value)}</dd>"
60
+ html += "</span>"
61
+ end
62
+ html += "</dl>"
63
+ html += "<p x-show='state[#{i}]'>}</p>"
64
+ html
65
+ end
66
+
67
+ def parse_array(array)
68
+ return '[]' if array.empty?
69
+ i = @index
70
+ @index += 1
71
+ html = "<button x-show='state[#{i}]' @click='state[#{i}] = false' class='focus:outline-none'><span class='#{EXPANDABLE}'>array:#{array.size} </span><span>[</span><span class='#{PUNCTUATION}'>▼</span></button>"
72
+ html += "<button x-show='!state[#{i}]' @click='state[#{i}] = true' class='focus:outline-none'><span class='#{EXPANDABLE}'>array:#{array.size} </span><span>[</span><span class='#{PUNCTUATION}'>▶</span><span class='#{EXPANDABLE}'></span><span>]</span></button>"
73
+ html += "<ul x-show='state[#{i}]' class='ml-4'>"
74
+ array.each do |value|
75
+ html += "<li>#{parse_value(value)}</li>"
76
+ end
77
+ html += "</ul>"
78
+ html += "<p x-show='state[#{i}]'>]</p>"
79
+ html
80
+ end
81
+
82
+ def parse_terminal(value)
83
+ case value
84
+ in String
85
+ "<span class='#{STRING}'>\"#{value}\"</span>"
86
+ in Integer
87
+ "<span class='#{INTEGER}'>#{value}</span>"
88
+ in Float
89
+ "<span class='#{FLOAT}'>#{value}</span>"
90
+ in TrueClass
91
+ "<span class='#{CONSTANT}'>#{true}</span>"
92
+ in FalseClass
93
+ "<span class='#{CONSTANT}'>#{false}</span>"
94
+ in NilClass
95
+ "<span class='#{CONSTANT}'>#{nil}</span>"
96
+ in _
97
+ "<span class='unknown'>#{value}</span>"
98
+ end
99
+ end
100
+
101
+ end
102
+ end
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+ # hash = {
111
+ # "foo" => "bar",
112
+ # "baz" => [1,2,3,4],
113
+ # "nested" => {
114
+ # "boo": 1,
115
+ # "bop": "ha"
116
+ # }
117
+ # }
118
+
119
+ # puts HTMLFormatter::RubyHash.parse(hash)
120
+ # HTMLFormatter::SQL.parse
@@ -26,6 +26,7 @@
26
26
  <% end %>
27
27
 
28
28
  <!-- This is so tailwind generates the dynamically used styles -->
29
+ <div hidden class="fill-blue-600 fill-red-600 fill-yellow-600"></div>
29
30
  <div hidden class="text-blue-900 text-red-900 text-yellow-900"></div>
30
31
 
31
32
  <span class="ml-1 text-<%= color %>-900">
@@ -1,28 +1,59 @@
1
1
  <%
2
2
 
3
- hash = [
4
- { name: 'request_method', value: request.request_method },
5
- { name: 'request_path', value: request.path },
6
- { name: 'request_params', value: request.params }
7
- ]
3
+ STATUS_TEXTS ||= {
4
+ 200 => "OK",
5
+ 201 => "Created",
6
+ 204 => "No Content",
7
+ 301 => "Moved Permanently",
8
+ 302 => "Found",
9
+ 400 => "Bad Request",
10
+ 401 => "Unauthorized",
11
+ 403 => "Forbidden",
12
+ 404 => "Not Found",
13
+ 500 => "Internal Server Error",
14
+ 502 => "Bad Gateway",
15
+ 503 => "Service Unavailable"
16
+ }.freeze
8
17
 
9
- request.env.each do |key, value|
10
- hash << {name: key.downcase, value: value} if key.start_with?('HTTP_')
11
- end
18
+ # According to Roda docs, response.status returns:
19
+ # > The status code to use for the response.
20
+ # > If none is given, will use 200 code for non-empty responses and a 404 code for empty responses.
21
+ status = response.status || (response.body.empty? ? 404: 200)
12
22
 
13
- # hash << { name: 'request_headers', value: request.env.filter {|k, v| k.to_s.start_with? 'HTTP_' } }
14
- hash << { name: 'request_headers', value: request.env.to_json }
23
+ # This is just to mimic Laravel's debug bar
24
+ format = {'text/html' => 'html', 'application/json' => 'json'}.fetch(response.headers['content-type'], 'not set')
15
25
 
16
- hash << { name: 'response_headers', value: response.headers }
26
+ hash = [
27
+ # { name: 'request_method', value: request.request_method },
28
+ { name: 'path_info', value: request.path },
29
+ { name: 'status_code', value: status },
30
+ { name: 'status_text', value: STATUS_TEXTS[status] },
31
+ { name: 'format', value: format },
32
+ { name: 'content_type', value: response.headers['content-type'] },
33
+ # { name: 'request_params', value: request.params },
34
+ { name: 'request_query', value: request.GET },
35
+ { name: 'request_request', value: request.POST },
36
+ { name: 'request_headers', value: request.env.filter { |v| v.start_with? 'HTTP_' }.transform_keys { |k| k.sub('HTTP_', '').downcase } },
37
+ { name: 'request_cookies', value: request.cookies },
38
+ { name: 'response_headers', value: response.headers },
39
+ { name: 'session_attributes', value: begin request.session rescue {} end }
40
+ ]
17
41
 
42
+ require_relative "../../html_formatter"
18
43
  %>
19
44
 
20
45
  <div class="max-w mx-auto space-y-1 font-mono">
21
46
  <% hash.each do |elem| %>
22
- <div class="px-4 py-2 odd:bg-white even:bg-ruby-50">
23
- <span class="inline-block w-64"><%= elem[:name] %></span><span class=""><%= elem[:value] %></span>
47
+ <div class="flex px-4 py-1 odd:bg-white even:bg-ruby-50">
48
+ <span class="inline-block min-w-64"><%= elem[:name] %></span><span class=""><%= HTMLFormatter::RubyHash.parse(elem[:value]) %></span>
24
49
  </div>
25
50
  <% end %>
51
+
52
+ <%# rack_env should start closed, unlike the others %>
53
+ <div class="flex px-4 py-1 odd:bg-white even:bg-ruby-50">
54
+ <span class="inline-block min-w-64">rack_env</span><span class=""><%= HTMLFormatter::RubyHash.parse(request.env.transform_keys(&:downcase), start_open: false) %></span>
55
+ </div>
56
+
26
57
  </div>
27
58
 
28
59
  <!--
@@ -52,6 +52,15 @@
52
52
  color: #9ca3af;
53
53
  }
54
54
 
55
+ .highlight.ruby.hash .exp {
56
+ color: #487bcd;
57
+ }
58
+
59
+ .highlight.ruby.hash .kc {
60
+ font-weight: bold;
61
+ color: #0086B3;
62
+ }
63
+
55
64
 
56
65
  /******* ruby routes tab *******/
57
66
 
@@ -2,12 +2,11 @@ require "tty-logger"
2
2
  require "pathname"
3
3
  require_relative "../debug_bar/current"
4
4
  require_relative "../debug_bar/instance"
5
+ require_relative "../debug_bar/html_formatter"
5
6
  require_relative "../../sequel/extensions/debug_bar"
6
7
  require_relative "../../sequel/plugins/debug_bar"
7
8
  require 'rouge'
8
9
 
9
- require 'json'
10
-
11
10
  class Roda
12
11
  module RodaPlugins
13
12
  module DebugBar
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module DebugBar
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0-rc1.0"
3
3
  end
data/public/out.css CHANGED
@@ -238,7 +238,7 @@ code:where(.debug-bar,.debug-bar *):where(:not(.no-tailwind,.no-tailwind *)),
238
238
  kbd:where(.debug-bar,.debug-bar *):where(:not(.no-tailwind,.no-tailwind *)),
239
239
  samp:where(.debug-bar,.debug-bar *):where(:not(.no-tailwind,.no-tailwind *)),
240
240
  pre:where(.debug-bar,.debug-bar *):where(:not(.no-tailwind,.no-tailwind *)) {
241
- font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
241
+ font-family: Menlo, Monaco, Consolas, "Liberation Mono", Courier New, monospace;
242
242
  /* 1 */
243
243
  font-feature-settings: normal;
244
244
  /* 2 */
@@ -582,14 +582,14 @@ video:where(.debug-bar,.debug-bar *):where(:not(.no-tailwind,.no-tailwind *)) {
582
582
  margin-left: 1.5rem;
583
583
  }
584
584
 
585
- .mr-2 {
586
- margin-right: 0.5rem;
587
- }
588
-
589
585
  .mr-1 {
590
586
  margin-right: 0.25rem;
591
587
  }
592
588
 
589
+ .mr-2 {
590
+ margin-right: 0.5rem;
591
+ }
592
+
593
593
  .block {
594
594
  display: block;
595
595
  }
@@ -610,13 +610,17 @@ video:where(.debug-bar,.debug-bar *):where(:not(.no-tailwind,.no-tailwind *)) {
610
610
  display: none;
611
611
  }
612
612
 
613
+ .size-4 {
614
+ width: 1rem;
615
+ height: 1rem;
616
+ }
617
+
613
618
  .size-5 {
614
619
  width: 1.25rem;
615
620
  height: 1.25rem;
616
621
  }
617
622
 
618
- .size-4 {
619
- width: 1rem;
623
+ .h-4 {
620
624
  height: 1rem;
621
625
  }
622
626
 
@@ -632,16 +636,12 @@ video:where(.debug-bar,.debug-bar *):where(:not(.no-tailwind,.no-tailwind *)) {
632
636
  height: 1.75rem;
633
637
  }
634
638
 
635
- .h-4 {
636
- height: 1rem;
637
- }
638
-
639
639
  .w-16 {
640
640
  width: 4rem;
641
641
  }
642
642
 
643
- .w-64 {
644
- width: 16rem;
643
+ .w-4 {
644
+ width: 1rem;
645
645
  }
646
646
 
647
647
  .w-8\/12 {
@@ -656,8 +656,8 @@ video:where(.debug-bar,.debug-bar *):where(:not(.no-tailwind,.no-tailwind *)) {
656
656
  width: 100%;
657
657
  }
658
658
 
659
- .w-4 {
660
- width: 1rem;
659
+ .min-w-64 {
660
+ min-width: 16rem;
661
661
  }
662
662
 
663
663
  .flex-1 {
@@ -743,6 +743,11 @@ video:where(.debug-bar,.debug-bar *):where(:not(.no-tailwind,.no-tailwind *)) {
743
743
  border-color: transparent;
744
744
  }
745
745
 
746
+ .bg-blue-400 {
747
+ --tw-bg-opacity: 1;
748
+ background-color: rgb(96 165 250 / var(--tw-bg-opacity, 1));
749
+ }
750
+
746
751
  .bg-gray-100 {
747
752
  --tw-bg-opacity: 1;
748
753
  background-color: rgb(243 244 246 / var(--tw-bg-opacity, 1));
@@ -773,9 +778,16 @@ video:where(.debug-bar,.debug-bar *):where(:not(.no-tailwind,.no-tailwind *)) {
773
778
  background-color: rgb(255 255 255 / var(--tw-bg-opacity, 1));
774
779
  }
775
780
 
776
- .bg-blue-400 {
777
- --tw-bg-opacity: 1;
778
- background-color: rgb(96 165 250 / var(--tw-bg-opacity, 1));
781
+ .fill-blue-600 {
782
+ fill: #2563eb;
783
+ }
784
+
785
+ .fill-red-600 {
786
+ fill: #dc2626;
787
+ }
788
+
789
+ .fill-yellow-600 {
790
+ fill: #ca8a04;
779
791
  }
780
792
 
781
793
  .p-4 {
@@ -796,6 +808,11 @@ video:where(.debug-bar,.debug-bar *):where(:not(.no-tailwind,.no-tailwind *)) {
796
808
  padding-right: 1rem;
797
809
  }
798
810
 
811
+ .py-1 {
812
+ padding-top: 0.25rem;
813
+ padding-bottom: 0.25rem;
814
+ }
815
+
799
816
  .py-2 {
800
817
  padding-top: 0.5rem;
801
818
  padding-bottom: 0.5rem;
@@ -810,6 +827,10 @@ video:where(.debug-bar,.debug-bar *):where(:not(.no-tailwind,.no-tailwind *)) {
810
827
  padding-bottom: 0.5rem;
811
828
  }
812
829
 
830
+ .pl-1 {
831
+ padding-left: 0.25rem;
832
+ }
833
+
813
834
  .pl-2 {
814
835
  padding-left: 0.5rem;
815
836
  }
@@ -822,16 +843,12 @@ video:where(.debug-bar,.debug-bar *):where(:not(.no-tailwind,.no-tailwind *)) {
822
843
  padding-top: 0.5rem;
823
844
  }
824
845
 
825
- .pl-1 {
826
- padding-left: 0.25rem;
827
- }
828
-
829
846
  .text-center {
830
847
  text-align: center;
831
848
  }
832
849
 
833
850
  .font-mono {
834
- font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
851
+ font-family: Menlo, Monaco, Consolas, "Liberation Mono", Courier New, monospace;
835
852
  }
836
853
 
837
854
  .text-sm {
@@ -857,6 +874,11 @@ video:where(.debug-bar,.debug-bar *):where(:not(.no-tailwind,.no-tailwind *)) {
857
874
  color: rgb(59 130 246 / var(--tw-text-opacity, 1));
858
875
  }
859
876
 
877
+ .text-blue-900 {
878
+ --tw-text-opacity: 1;
879
+ color: rgb(30 58 138 / var(--tw-text-opacity, 1));
880
+ }
881
+
860
882
  .text-gray-500 {
861
883
  --tw-text-opacity: 1;
862
884
  color: rgb(107 114 128 / var(--tw-text-opacity, 1));
@@ -872,19 +894,14 @@ video:where(.debug-bar,.debug-bar *):where(:not(.no-tailwind,.no-tailwind *)) {
872
894
  color: rgb(17 24 39 / var(--tw-text-opacity, 1));
873
895
  }
874
896
 
875
- .text-white {
876
- --tw-text-opacity: 1;
877
- color: rgb(255 255 255 / var(--tw-text-opacity, 1));
878
- }
879
-
880
- .text-blue-900 {
897
+ .text-red-900 {
881
898
  --tw-text-opacity: 1;
882
- color: rgb(30 58 138 / var(--tw-text-opacity, 1));
899
+ color: rgb(127 29 29 / var(--tw-text-opacity, 1));
883
900
  }
884
901
 
885
- .text-red-900 {
902
+ .text-white {
886
903
  --tw-text-opacity: 1;
887
- color: rgb(127 29 29 / var(--tw-text-opacity, 1));
904
+ color: rgb(255 255 255 / var(--tw-text-opacity, 1));
888
905
  }
889
906
 
890
907
  .text-yellow-900 {
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda-debug_bar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0.pre.rc1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Avi Feher Sternlieb
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-15 00:00:00.000000000 Z
10
+ date: 2025-01-20 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: roda
@@ -114,6 +114,7 @@ extensions: []
114
114
  extra_rdoc_files: []
115
115
  files:
116
116
  - lib/roda/debug_bar/current.rb
117
+ - lib/roda/debug_bar/html_formatter.rb
117
118
  - lib/roda/debug_bar/instance.rb
118
119
  - lib/roda/debug_bar/views/debug_bar.erb
119
120
  - lib/roda/debug_bar/views/debug_bar/messages.erb
@@ -126,7 +127,6 @@ files:
126
127
  - lib/roda/debug_bar/views/debug_bar/views.erb
127
128
  - lib/roda/plugins/debug_bar.rb
128
129
  - lib/sequel/extensions/debug_bar.rb
129
- - lib/sequel/main.rb
130
130
  - lib/sequel/plugins/debug_bar.rb
131
131
  - lib/version.rb
132
132
  - public/out.css
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  - !ruby/object:Gem::Version
150
150
  version: '0'
151
151
  requirements: []
152
- rubygems_version: 3.6.2
152
+ rubygems_version: 3.6.3
153
153
  specification_version: 4
154
154
  summary: A debug bar for Roda
155
155
  test_files: []
data/lib/sequel/main.rb DELETED
@@ -1,36 +0,0 @@
1
- require 'sequel'
2
- require_relative 'plugins/debug_bar'
3
-
4
- # require 'sequel/plugins/after_initialize'
5
-
6
- DB = Sequel.sqlite('/Users/avi/code/2025/jan/roda-30day-clone/database/database.sqlite')
7
-
8
-
9
- Sequel::Model.plugin :debug_bar
10
-
11
- class Employer < Sequel::Model
12
- end
13
-
14
- # puts Employer.first.inspect
15
-
16
- # puts Employer.plugins.include?(:after_initialize)
17
-
18
-
19
- # Sequel::Model.plugin :after_initialize
20
- # Sequel::Model.plugin :debug_bar
21
-
22
- # class Employer < Sequel::Model
23
- # plugin :debug_bar
24
- # end
25
-
26
- # Employer.plugin :after_initialize
27
- # Employer.plugin :debug_bar
28
-
29
- # puts Employer.first.inspect
30
-
31
- # a = Employer.create(name: 'alksgj')
32
-
33
- # # puts Employer.plugins.include?(:after_initialization)
34
- # puts Employer.plugins.include?(:debug_bar)
35
-
36
- # # puts Sequel::Model.plugins.include?(:debug_bar)