roda-debug_bar 0.2.1 → 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 +4 -4
- data/lib/roda/debug_bar/html_formatter.rb +120 -0
- data/lib/roda/debug_bar/views/debug_bar/request.erb +44 -13
- data/lib/roda/debug_bar/views/debug_bar.erb +9 -0
- data/lib/roda/plugins/debug_bar.rb +1 -2
- data/lib/version.rb +1 -1
- data/public/out.css +11 -11
- metadata +4 -4
- data/lib/sequel/main.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15184bb57f4138f00506b033ca263fec092caf7449065e03b336d4ca8546e0db
|
4
|
+
data.tar.gz: a5502c77d34dfe0b90f76d1852c9b75667461125cb7420f5e354ffe2c21f8470
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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}: </dt>"
|
58
|
+
# html += "<span class='#{PUNCTUATION}'>=> </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
|
@@ -1,28 +1,59 @@
|
|
1
1
|
<%
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
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
|
-
#
|
14
|
-
|
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
|
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-
|
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
|
<!--
|
@@ -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
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:
|
241
|
+
font-family: Menlo, Monaco, Consolas, "Liberation Mono", Courier New, monospace;
|
242
242
|
/* 1 */
|
243
243
|
font-feature-settings: normal;
|
244
244
|
/* 2 */
|
@@ -644,10 +644,6 @@ video:where(.debug-bar,.debug-bar *):where(:not(.no-tailwind,.no-tailwind *)) {
|
|
644
644
|
width: 1rem;
|
645
645
|
}
|
646
646
|
|
647
|
-
.w-64 {
|
648
|
-
width: 16rem;
|
649
|
-
}
|
650
|
-
|
651
647
|
.w-8\/12 {
|
652
648
|
width: 66.666667%;
|
653
649
|
}
|
@@ -660,6 +656,10 @@ video:where(.debug-bar,.debug-bar *):where(:not(.no-tailwind,.no-tailwind *)) {
|
|
660
656
|
width: 100%;
|
661
657
|
}
|
662
658
|
|
659
|
+
.min-w-64 {
|
660
|
+
min-width: 16rem;
|
661
|
+
}
|
662
|
+
|
663
663
|
.flex-1 {
|
664
664
|
flex: 1 1 0%;
|
665
665
|
}
|
@@ -808,6 +808,11 @@ video:where(.debug-bar,.debug-bar *):where(:not(.no-tailwind,.no-tailwind *)) {
|
|
808
808
|
padding-right: 1rem;
|
809
809
|
}
|
810
810
|
|
811
|
+
.py-1 {
|
812
|
+
padding-top: 0.25rem;
|
813
|
+
padding-bottom: 0.25rem;
|
814
|
+
}
|
815
|
+
|
811
816
|
.py-2 {
|
812
817
|
padding-top: 0.5rem;
|
813
818
|
padding-bottom: 0.5rem;
|
@@ -843,7 +848,7 @@ video:where(.debug-bar,.debug-bar *):where(:not(.no-tailwind,.no-tailwind *)) {
|
|
843
848
|
}
|
844
849
|
|
845
850
|
.font-mono {
|
846
|
-
font-family:
|
851
|
+
font-family: Menlo, Monaco, Consolas, "Liberation Mono", Courier New, monospace;
|
847
852
|
}
|
848
853
|
|
849
854
|
.text-sm {
|
@@ -899,11 +904,6 @@ video:where(.debug-bar,.debug-bar *):where(:not(.no-tailwind,.no-tailwind *)) {
|
|
899
904
|
color: rgb(255 255 255 / var(--tw-text-opacity, 1));
|
900
905
|
}
|
901
906
|
|
902
|
-
.text-yellow-600 {
|
903
|
-
--tw-text-opacity: 1;
|
904
|
-
color: rgb(202 138 4 / var(--tw-text-opacity, 1));
|
905
|
-
}
|
906
|
-
|
907
907
|
.text-yellow-900 {
|
908
908
|
--tw-text-opacity: 1;
|
909
909
|
color: rgb(113 63 18 / var(--tw-text-opacity, 1));
|
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.
|
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-
|
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.
|
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)
|