rack-webprofiler 0.1.0.pre.beta2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +5 -13
  2. data/CHANGELOG.md +36 -12
  3. data/README.md +16 -12
  4. data/docs/DSL.md +152 -0
  5. data/docs/GettingStarted.md +51 -0
  6. data/docs/README.md +6 -0
  7. data/lib/rack/templates/assets/css/profiler.css +1 -1
  8. data/lib/rack/templates/assets/css/rwpt.css +1 -1
  9. data/lib/rack/templates/assets/sass/_variables.scss +21 -2
  10. data/lib/rack/templates/assets/sass/profiler.scss +73 -61
  11. data/lib/rack/templates/assets/sass/rwpt.scss +2 -2
  12. data/lib/rack/templates/panel/show.erb +4 -4
  13. data/lib/rack/templates/profiler.erb +4 -0
  14. data/lib/rack/web_profiler/collector.rb +197 -125
  15. data/lib/rack/web_profiler/collectors/rack_collector.rb +74 -0
  16. data/lib/rack/web_profiler/{collector/rack → collectors}/request_collector.rb +43 -60
  17. data/lib/rack/web_profiler/{collector → collectors}/ruby_collector.rb +4 -3
  18. data/lib/rack/web_profiler/{collector → collectors}/time_collector.rb +12 -6
  19. data/lib/rack/web_profiler/collectors.rb +21 -27
  20. data/lib/rack/web_profiler/config.rb +4 -9
  21. data/lib/rack/web_profiler/controller.rb +131 -126
  22. data/lib/rack/web_profiler/engine.rb +10 -14
  23. data/lib/rack/web_profiler/model.rb +74 -23
  24. data/lib/rack/web_profiler/request.rb +22 -7
  25. data/lib/rack/web_profiler/response.rb +27 -0
  26. data/lib/rack/web_profiler/rouge/html_formatter.rb +25 -0
  27. data/lib/rack/web_profiler/router.rb +11 -6
  28. data/lib/rack/web_profiler/version.rb +1 -1
  29. data/lib/rack/web_profiler/view.rb +255 -139
  30. data/lib/rack/web_profiler.rb +47 -4
  31. data/rack-webprofiler.gemspec +1 -3
  32. metadata +32 -32
  33. data/lib/rack/web_profiler/collector/debug_collector.rb +0 -31
  34. data/lib/rack/web_profiler/collector/erb_collector.rb +0 -0
  35. data/lib/rack/web_profiler/collector/performance_collector.rb +0 -1
  36. data/lib/rack/web_profiler/collector/rack/rack_collector.rb +0 -23
  37. data/lib/rack/web_profiler/collector/view.rb +0 -44
  38. data/lib/rack/web_profiler/model/collection_record.rb +0 -46
@@ -217,7 +217,8 @@ body {
217
217
  -webkit-user-select: none;
218
218
  user-select: none;
219
219
 
220
- &:hover {
220
+ &:hover,
221
+ &.active {
221
222
  background-color: $profiler_panel__sidebar_item_hover;
222
223
  }
223
224
  &.sidebar__item--blank {
@@ -263,7 +264,6 @@ body {
263
264
  width: 100%;
264
265
  min-height: calc(100% - 80px);
265
266
  padding: 20px;
266
- margin-bottom: 50px;
267
267
  }
268
268
  .wrapper__container {
269
269
  box-sizing: border-box;
@@ -7,13 +7,13 @@
7
7
  <% content_for :sidebar do %>
8
8
  <% @collectors.each do |_k, collector| %>
9
9
  <% if collector_has_panel?(collector, @collection) %>
10
- <div class="sidebar__item">
10
+ <div class="sidebar__item<%= collector == @collector ? " active" : nil %>">
11
11
  <div class="sidebar__item-inner">
12
- <a href="<%=h WebProfiler::Router.url_for_profiler(@collection.token, collector.name) %>">
12
+ <a href="<%=h WebProfiler::Router.url_for_profiler(@collection.token, collector.identifier) %>">
13
13
  <i class="icn">
14
14
  <% unless collector.icon.nil? %><img alt="" src="<%=h collector.icon %>" /><% end %>
15
15
  </i>
16
- <span><%=h collector.name.capitalize.gsub(/_/, ' ') %></span>
16
+ <span><%=h collector.label %></span>
17
17
  </a>
18
18
  </div>
19
19
  </div>
@@ -21,6 +21,6 @@
21
21
  <% end %>
22
22
  <% end %>
23
23
 
24
- <div class="rack-webprofiler_collectors_<%=h @collector.name.to_s %>">
24
+ <div class="rack-webprofiler_collectors_<%=h @collector.identifier.to_s %>">
25
25
  <%= collector_panel(@collector, @collection) %>
26
26
  </div>
@@ -9,6 +9,8 @@
9
9
  <div class="rack-webprofiler__item rack-webprofiler_collectors_<%=h name.to_s %>">
10
10
  <% if collector_has_panel?(collector, @collection) %>
11
11
  <a href="<%=h WebProfiler::Router.url_for_profiler(@collection.token, name) %>">
12
+ <% else %>
13
+ <span class="rack-webprofiler__item-content">
12
14
  <% end %>
13
15
  <% unless collector.icon.nil? %>
14
16
  <i class="icn"><img alt="" src="<%=h collector.icon %>" /></i>
@@ -19,6 +21,8 @@
19
21
  <span class="rack-webprofiler__item__status-color <%=h status.to_s %>"></span>
20
22
  <% if collector_has_panel?(collector, @collection) %>
21
23
  </a>
24
+ <% else %>
25
+ </span>
22
26
  <% end %>
23
27
  </div>
24
28
  <% end %>
@@ -1,155 +1,227 @@
1
1
  require "docile"
2
2
 
3
3
  module Rack
4
+ class WebProfiler
5
+ # Collector
6
+ class Collector
7
+ # DSL
8
+ module DSL
9
+ def self.included(base)
10
+ base.extend(ClassMethods)
11
+ base.class_eval do
12
+ @definition = Definition.new
13
+ @definition.position = 1
14
+ @definition.is_enabled = true
15
+ @definition.klass = self
16
+ end
17
+ end
4
18
 
5
- # Collector
6
- class WebProfiler::Collector
7
- autoload :RubyCollector, "rack/web_profiler/collector/ruby_collector"
8
- autoload :TimeCollector, "rack/web_profiler/collector/time_collector"
9
- autoload :View, "rack/web_profiler/collector/view"
19
+ module ClassMethods
20
+ attr_reader :definition
21
+
22
+ # Set the icon of the {Rack::WebProfiler::Collector}.
23
+ #
24
+ # @param icon [String, nil]
25
+ def icon(icon = nil); definition.icon = icon; end
26
+
27
+ # Set the identifier of the {Rack::WebProfiler::Collector}.
28
+ #
29
+ # @param identifier [String, nil]
30
+ def identifier(identifier = nil); definition.identifier = identifier; end
31
+
32
+ # Set the label of the {Rack::WebProfiler::Collector}.
33
+ #
34
+ # @param label [String, nil]
35
+ def label(label = nil); definition.label = label; end
36
+
37
+ #
38
+ def position(position = nil); definition.position = position.to_i; end
39
+
40
+ #
41
+ def collect(&block); definition.collect = block; end
42
+
43
+ # Set the template of the {Rack::WebProfiler::Collector}.
44
+ #
45
+ # @param template [String, nil]
46
+ # @option type [Symbol] :file or :DATA
47
+ def template(template = nil, type: :file)
48
+ template = get_data_contents(template) if type == :DATA
49
+ definition.template = template
50
+ end
10
51
 
11
- module Rack
12
- autoload :RackCollector, "rack/web_profiler/collector/rack/rack_collector"
13
- autoload :RequestCollector, "rack/web_profiler/collector/rack/request_collector"
14
- end
52
+ # Tell if the {Rack::WebProfiler::Collector} is enabled.
53
+ #
54
+ # @param is_enabled [Boolean, Block]
55
+ def is_enabled?(is_enabled = true)
56
+ definition.is_enabled = Proc.new if block_given?
57
+ definition.is_enabled = is_enabled
58
+ end
15
59
 
16
- # DSL
17
- module DSL
18
- def self.included(base)
19
- base.extend(ClassMethods)
20
- base.class_eval do
21
- @definition = Definition.new
22
- @definition.position = 1
23
- @definition.is_enabled = true
24
- @definition.klass = self
60
+ private
61
+
62
+ def get_data_contents(path)
63
+ data = ""
64
+ ::File.open(path, "rb") do |f|
65
+ begin
66
+ line = f.gets
67
+ end until line.nil? || /^__END__$/ === line
68
+ data << line while line = f.gets
69
+ end
70
+ data
71
+ end
25
72
  end
26
73
  end
27
74
 
28
- module ClassMethods
29
- attr_reader :definition
75
+ # Definition
76
+ #
77
+ # Collector definition.
78
+ class Definition
79
+ attr_accessor :icon, :identifier, :label, :position, :collect, :template, :is_enabled, :klass
80
+ attr_reader :data_storage
81
+
82
+ # Collect the data who the Collector need.
83
+ #
84
+ # @param request [Rack::WebProfiler::Request]
85
+ # @param response [Rack::Response]
86
+ #
87
+ # @return [Rack::WebProfiler::Collector::DSL::DataStorage]
88
+ def collect!(request, response)
89
+ @data_storage = Docile.dsl_eval(DataStorage.new, request, response, &collect)
90
+ end
30
91
 
31
- def icon(icon = nil); definition.icon = icon; end
32
- def collector_name(name = nil); definition.name = name; end
33
- def position(position = nil); definition.position = position.to_i; end
34
- def collect(&block); definition.collect = block; end
92
+ # Is the collector enabled.
93
+ #
94
+ # @return [Boolean]
95
+ def is_enabled?
96
+ return !!@is_enabled.call if @is_enabled.is_a?(Proc)
97
+ !!@is_enabled
98
+ end
99
+ end
35
100
 
36
- def template(template = nil, type: :file)
37
- template = get_data_contents(template) if type == :DATA
38
- definition.template = template
101
+ # DataStorage
102
+ #
103
+ # Used to store datas who Collector needs.
104
+ #
105
+ # @todo do DataStorage compatible with Marshal
106
+ class DataStorage
107
+ attr_reader :datas
108
+
109
+ def initialize
110
+ @datas = Hash.new
111
+ @status = nil
112
+ @show_tab = true
113
+ @show_panel = true
39
114
  end
40
115
 
41
- def is_enabled?(is_enabled = true)
42
- definition.is_enabled = Proc.new if block_given?
43
- definition.is_enabled = is_enabled
116
+ # Store a value.
117
+ #
118
+ # @param k [String, Symbol]
119
+ # @param v
120
+ def store(k, v)
121
+ # @todo check data format (must be compatible with Marshal)
122
+ @datas[k.to_sym] = v
44
123
  end
45
124
 
46
- private
125
+ # Status.
126
+ #
127
+ # @param v [Symbol, nil]
128
+ #
129
+ # @return [Symbol, nil]
130
+ def status(v = nil)
131
+ # @todo check status?
132
+ # raise Exception, "" unless [:success, :warning, :danger].include?(v)
133
+ @status = v.to_sym unless v.nil?
134
+ @status
135
+ end
47
136
 
48
- def get_data_contents(path)
49
- data = ""
50
- ::File.open(path, "rb") do |f|
51
- begin
52
- line = f.gets
53
- end until line.nil? || /^__END__$/ === line
54
- data << line while line = f.gets
55
- end
56
- data
137
+ #
138
+ #
139
+ # @param b [Boolean, nil]
140
+ #
141
+ # @return [Boolean]
142
+ def show_panel(b = nil)
143
+ @show_panel = !!b unless b.nil?
144
+ @show_panel
57
145
  end
58
- end
59
- end
60
146
 
61
- # Definition
62
- #
63
- # Collector definition.
64
- class Definition
65
- attr_accessor :icon, :name, :position, :collect, :template, :is_enabled, :klass
66
- attr_reader :data_storage
147
+ #
148
+ #
149
+ # @param b [Boolean, nil]
150
+ #
151
+ # @return [Boolean]
152
+ def show_tab(b = nil)
153
+ @show_tab = !!b unless b.nil?
154
+ @show_tab
155
+ end
67
156
 
68
- # Collect the data who the Collector need.
69
- #
70
- # @param request [Rack::WebProfiler::Request]
71
- # @param response [Rack::Response]
72
- #
73
- # @return [Rack::WebProfiler::Collector::DSL::DataStorage]
74
- def collect!(request, response)
75
- @data_storage = Docile.dsl_eval(DataStorage.new, request, response, &collect)
157
+ # Transform DataStorage to an Hash
158
+ #
159
+ # @return [Hash<Symbol, Object>]
160
+ def to_h
161
+ {
162
+ datas: @datas,
163
+ status: @status,
164
+ show_panel: @show_panel,
165
+ show_tab: @show_tab,
166
+ }
167
+ end
76
168
  end
77
169
 
78
- # Is the collector enabled.
79
- #
80
- # @return [Boolean]
81
- def is_enabled?
82
- return !!@is_enabled.call if @is_enabled.is_a?(Proc)
83
- !!@is_enabled
84
- end
85
- end
170
+ # View
171
+ class View < WebProfiler::View
172
+ #
173
+ def context
174
+ @context ||= Context.new
175
+ end
86
176
 
87
- # DataStorage
88
- #
89
- # Used to store datas who Collector needs.
90
- #
91
- # @todo do DataStorage compatible with Marshal
92
- class DataStorage
93
- attr_reader :datas
94
-
95
- def initialize
96
- @datas = Hash.new
97
- @status = nil
98
- @show_tab = true
99
- @show_panel = true
100
- end
177
+ # Read a template. Returns file content if template is a file path.
178
+ #
179
+ # @param template [String] template file path or content
180
+ #
181
+ # @return [String]
182
+ def read_template(template)
183
+ unless template.empty?
184
+ return ::File.read(template) if ::File.exist?(template)
185
+ end
186
+ template
187
+ end
101
188
 
102
- # Store a value.
103
- #
104
- # @param k [String, Symbol]
105
- # @param v
106
- def store(k, v)
107
- # @todo check data format (must be compatible with Marshal)
108
- @datas[k.to_sym] = v
109
- end
189
+ # Helpers
190
+ module Helpers
191
+ # @todo comment
192
+ def tab_content
193
+ if block_given?
194
+ @tab_content ||= capture(&Proc.new)
195
+ elsif !@tab_content.nil?
196
+ @tab_content
197
+ end
198
+ end
110
199
 
111
- # Status.
112
- #
113
- # @param v [Symbol, nil]
114
- #
115
- # @return [Symbol, nil]
116
- def status(v = nil)
117
- # @todo check status?
118
- # raise Exception, "" unless [:success, :warning, :error].include?(v)
119
- @status = v.to_sym unless v.nil?
120
- @status
121
- end
200
+ # @todo comment
201
+ def panel_content
202
+ if block_given?
203
+ @panel_content ||= capture(&Proc.new)
204
+ elsif !@panel_content.nil?
205
+ @panel_content
206
+ end
207
+ end
122
208
 
123
- #
124
- #
125
- # @param b [Boolean, nil]
126
- #
127
- # @return [Boolean]
128
- def show_panel(b = nil)
129
- @show_panel = !!b unless b.nil?
130
- @show_panel
131
- end
209
+ # @todo comment
210
+ def data(k, default = nil)
211
+ return nil if @collection.nil?
132
212
 
133
- #
134
- #
135
- # @param b [Boolean, nil]
136
- #
137
- # @return [Boolean]
138
- def show_tab(b = nil)
139
- @show_tab = !!b unless b.nil?
140
- @show_tab
141
- end
213
+ datas = @collection.datas[@collector.identifier.to_sym][:datas]
214
+ return datas[k] if datas.has_key?(k)
142
215
 
143
- # Transform DataStorage to an Hash
144
- #
145
- # @return [Hash<Symbol, Object>]
146
- def to_h
147
- {
148
- datas: @datas,
149
- status: @status,
150
- show_panel: @show_panel,
151
- show_tab: @show_tab,
152
- }
216
+ default
217
+ end
218
+ end
219
+
220
+ # @todo comment
221
+ class Context
222
+ include WebProfiler::View::Helpers::Common
223
+ include Helpers
224
+ end
153
225
  end
154
226
  end
155
227
  end
@@ -0,0 +1,74 @@
1
+ module Rack
2
+ class WebProfiler::Collectors::RackCollector
3
+ include Rack::WebProfiler::Collector::DSL
4
+
5
+ icon <<-'ICON'
6
+ data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+PHN2ZyB3aWR0aD0iMjJweCIgaGVpZ2h0PSIyMnB4IiB2aWV3Qm94PSIwIDAgMjIgMjIiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+ICAgICAgICA8dGl0bGU+R3JvdXA8L3RpdGxlPiAgICA8ZGVzYz5DcmVhdGVkIHdpdGggU2tldGNoLjwvZGVzYz4gIC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3B5IiBwb2ludHM9IjIwIDUgMTQgOSAwIDQiPjwvcG9seWxpbmU+ICAgICAgICAgICAgICAgIDxwb2x5bGluZSBpZD0iUmVjdGFuZ2xlLTI3OC1Db3B5LTIiIHBvaW50cz0iMjAgMTUgMTQgMTkgMCAxNCI+PC9wb2x5bGluZT4gICAgICAgICAgICAgICAgPHBvbHlsaW5lIGlkPSJSZWN0YW5nbGUtMjc4LUNvcHktNCIgcG9pbnRzPSIyMCAxMSAxNCAxNSAwIDEwIj48L3BvbHlsaW5lPiAgICAgICAgICAgICAgICA8cG9seWxpbmUgaWQ9IlJlY3RhbmdsZS0yNzgtQ29weS01IiBwb2ludHM9IjIwIDEwIDE0IDE0IDAgOSI+PC9wb2x5bGluZT4gICAgICAgICAgICAgICAgPHBvbHlsaW5lIGlkPSJSZWN0YW5nbGUtMjc4LUNvcHktMyIgcG9pbnRzPSIyMCA2IDE0IDEwIDAgNSI+PC9wb2x5bGluZT4gICAgICAgICAgICA8L2c+ICAgICAgICA8L2c+ICAgIDwvZz48L3N2Zz4=
7
+ ICON
8
+
9
+ identifier "rack"
10
+ label "Rack"
11
+ position 1
12
+
13
+ collect do |request, _response|
14
+ store :rack_version, Rack.release
15
+ store :rack_env, hash_stringify_values(request.env)
16
+ end
17
+
18
+ template __FILE__, type: :DATA
19
+
20
+ class << self
21
+ def hash_stringify_values(hash)
22
+ return {} unless hash.kind_of?(Hash)
23
+ hash.collect do |k,v|
24
+ v = v.inspect unless v.kind_of?(String)
25
+ [k, v]
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ __END__
33
+ <% tab_content do %>
34
+ <%=h data(:rack_version) %>
35
+ <% end %>
36
+
37
+ <% panel_content do %>
38
+ <div class="block">
39
+ <h3>Rack informations</h3>
40
+
41
+ <table>
42
+ <tbody>
43
+ <tr>
44
+ <th>Version</th>
45
+ <td><%=h data(:rack_version) %></td>
46
+ </tr>
47
+ </tbody>
48
+ </table>
49
+ </div>
50
+
51
+ <div class="block">
52
+ <h3>Env</h3>
53
+ <% if data(:rack_env) && !data(:rack_env).empty? %>
54
+ <table>
55
+ <thead>
56
+ <tr>
57
+ <th>Key</th>
58
+ <th>Value</th>
59
+ </tr>
60
+ <thead>
61
+ <tbody>
62
+ <% data(:rack_env).sort.each do |k, v| %>
63
+ <tr>
64
+ <th><%=h k %></th>
65
+ <td class="code"><%=h v %></td>
66
+ </tr>
67
+ <% end %>
68
+ </tbody>
69
+ </table>
70
+ <% else %>
71
+ <p><span class="text__no-value">No rack env datas</span></p>
72
+ <% end %>
73
+ </div>
74
+ <% end %>
@@ -1,66 +1,52 @@
1
1
  module Rack
2
- class WebProfiler::Collector::Rack::RequestCollector
2
+ class WebProfiler::Collectors::RequestCollector
3
3
  include Rack::WebProfiler::Collector::DSL
4
4
 
5
5
  icon <<-'ICON'
6
6
  data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+PHN2ZyB3aWR0aD0iMjBweCIgaGVpZ2h0PSIyMHB4IiB2aWV3Qm94PSIwIDAgMjAgMjAiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+ICAgICAgICA8dGl0bGU+T3ZhbCA3IENvcHkgMjwvdGl0bGU+ICAgIDxkZXNjPkNyZWF0ZWQgd2l0aCBTa2V0Y2guPC9kZXNjPiAgICA8ZGVmcz48L2RlZnM+ICAgIDxnIGlkPSJQYWdlLTEiIHN0cm9rZT0ibm9uZSIgc3Ryb2tlLXdpZHRoPSIxIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPiAgICAgICAgPGcgaWQ9IkRlc2t0b3AtMiIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTEwLjAwMDAwMCwgLTEzMC4wMDAwMDApIiBmaW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4IDEzLjAzNTQwMTMsMjAuMTc2MTQ3MyBMOS45ODE3NTc1OSwxOS44MDEyMDY5IEwxMC4yMjQzMTg2LDE3LjgyNTcwNTkgTDEzLjI3MTc5NzIsMTguMTk5ODg5MyBDMTMuMzkyNTEwNiwxNy43NDcyMTMgMTMuNTU3MDQxNiwxNy4zMTI2MTUgMTMuNzYwNTI4LDE2LjkwMDk5MzUgTDExLjIzMzU5NzgsMTUuMTMxNjE3OSBMMTIuMzc1MjA4LDEzLjUwMTIyOTYgTDE0Ljg4NjQwMTgsMTUuMjU5NTg2NCBDMTUuMTk5NDA5NywxNC45MTg5MDYzIDE1LjU0NTU0OCwxNC42MDk1NjU1IDE1LjkxOTY1OTMsMTQuMzM2NzU5NiBMMTQuNDc2MDk4NSwxMS42MjE4MTY1IEwxNi4yMzM0NjE0LDEwLjY4NzQxIEwxNy42NzkxOTEyLDEzLjQwNjQzMjIgWiBNMjAsMjMuMDMyNzYxMiBDMjEuNjQ4ODQ4OSwyMy4wMzI3NjEyIDIyLjk4NTUwNSwyMS42ODYyMzA2IDIyLjk4NTUwNSwyMC4wMjUyMDA5IEMyMi45ODU1MDUsMTguMzY0MTcxMyAyMS42NDg4NDg5LDE3LjAxNzY0MDYgMjAsMTcuMDE3NjQwNiBDMTguMzUxMTUxMSwxNy4wMTc2NDA2IDE3LjAxNDQ5NSwxOC4zNjQxNzEzIDE3LjAxNDQ5NSwyMC4wMjUyMDA5IEMxNy4wMTQ0OTUsMjEuNjg2MjMwNiAxOC4zNTExNTExLDIzLjAzMjc2MTIgMjAsMjMuMDMyNzYxMiBaIiBpZD0iT3ZhbC03LUNvcHktMiI+PC9wYXRoPiAgICAgICAgICAgIDwvZz4gICAgICAgIDwvZz4gICAgPC9nPjwvc3ZnPg==
7
7
  ICON
8
8
 
9
- collector_name "rack_request"
10
- # collector_key "rack_request"
11
- # collector_name "Request"
12
- position 2
9
+ identifier "rack.request"
10
+ label "Request"
11
+ position 2
13
12
 
14
13
  collect do |request, response|
15
- store :request_headers, get_request_headers(request)
16
- store :request_path, request.path
17
- store :request_method, request.request_method
18
- store :request_cookies, request.cookies
19
- store :request_get, request.GET
20
- store :request_post, get_request_post(request)
21
- store :request_session, hash_to_s(request.session)
22
- store :request_cookies, request.cookies
23
- store :request_body, get_request_body(request)
24
-
25
- store :rack_env, hash_to_s(request.env)
14
+ store :request_headers, request.http_headers
15
+ store :request_fullpath, request.fullpath
16
+ store :request_method, request.request_method
17
+ store :request_cookies, request.cookies
18
+ store :request_get, request.GET
19
+ store :request_post, request_post(request)
20
+ store :request_session, hash_stringify_values(request.session)
21
+ store :request_cookies, request.cookies
22
+ store :request_body, request.body_string
23
+ store :request_mediatype, request.media_type
24
+ store :request_raw, request.raw
26
25
 
27
26
  store :response_status, response.status
28
27
  store :response_headers, response.headers
28
+ store :response_raw, response.raw
29
29
 
30
30
  if response.successful?
31
31
  status :success
32
32
  elsif response.redirection?
33
33
  status :warning
34
34
  else
35
- status :error
35
+ status :danger
36
36
  end
37
37
  end
38
38
 
39
39
  template __FILE__, type: :DATA
40
40
 
41
41
  class << self
42
- # Get request headers.
43
- #
44
- # @return [Hash]
45
- def get_request_headers(request)
46
- request.env.select {|k,v| k.start_with? 'HTTP_'}
47
- .collect {|k,v| [k.sub(/^HTTP_/, ''), v]}
48
- .collect {|k,v| [k.split('_').collect(&:capitalize).join('-'), v]}
49
- end
50
-
51
- def get_request_post(request)
42
+ def request_post(request)
52
43
  request.POST if request.POST && !request.POST.empty?
53
44
  rescue Exception
54
45
  nil
55
46
  end
56
47
 
57
- def get_request_body(request)
58
- return nil if request.body.nil? || request.get?
59
- body = request.body.dup
60
- body.read
61
- end
62
-
63
- def hash_to_s(hash)
48
+ def hash_stringify_values(hash)
49
+ return {} unless hash.kind_of?(Hash)
64
50
  hash.collect {|k,v| [k, v.to_s]}
65
51
  end
66
52
  end
@@ -70,6 +56,17 @@ end
70
56
  __END__
71
57
  <% tab_content do %>
72
58
  <%=h data(:response_status) %>
59
+
60
+ <div class="details">
61
+ <div class="wrapper">
62
+ <dl>
63
+ <dt>Status</dt>
64
+ <dd><%=h data(:response_status) %> - <%=h Rack::Utils::HTTP_STATUS_CODES[data(:response_status).to_i] %></dd>
65
+ <dt>Path</dt>
66
+ <dd><%=h data(:request_method) %> <%=h data(:request_fullpath) %></dd>
67
+ </dl>
68
+ </div>
69
+ </div>
73
70
  <% end %>
74
71
 
75
72
  <% panel_content do %>
@@ -147,12 +144,22 @@ __END__
147
144
 
148
145
  <div class="block">
149
146
  <h3>Request content</h3>
150
- <% unless data(:request_body).nil? %>
151
- <%=highlight code: data(:request_body) %>
147
+ <% unless data(:request_body).empty? %>
148
+ <%=highlight mimetype: data(:request_mediatype), code: data(:request_body) %>
152
149
  <% else %>
153
150
  <p><span class="text__no-value">No request content</span></p>
154
151
  <% end %>
155
152
  </div>
153
+ </div>
154
+
155
+ <div class="block">
156
+ <h3>Request raw</h3>
157
+ <% unless data(:request_raw).nil? %>
158
+ <%=highlight language: :http, code: data(:request_raw) %>
159
+ <% else %>
160
+ <p><span class="text__no-value">No request raw</span></p>
161
+ <% end %>
162
+ </div>
156
163
 
157
164
  <div class="block">
158
165
  <h3>Response headers</h3>
@@ -225,28 +232,4 @@ __END__
225
232
  <p><span class="text__no-value">No cookies data</span></p>
226
233
  <% end %>
227
234
  </div>
228
-
229
- <div class="block">
230
- <h3>Env</h3>
231
- <% if data(:rack_env) && !data(:rack_env).empty? %>
232
- <table>
233
- <thead>
234
- <tr>
235
- <th>Key</th>
236
- <th>Value</th>
237
- </tr>
238
- <thead>
239
- <tbody>
240
- <% data(:rack_env).sort.each do |k, v| %>
241
- <tr>
242
- <th><%=h k %></th>
243
- <td class="code"><%=h v %></td>
244
- </tr>
245
- <% end %>
246
- </tbody>
247
- </table>
248
- <% else %>
249
- <p><span class="text__no-value">No rack env datas</span></p>
250
- <% end %>
251
- </div>
252
235
  <% end %>
@@ -1,13 +1,14 @@
1
1
  module Rack
2
- class WebProfiler::Collector::RubyCollector
2
+ class WebProfiler::Collectors::RubyCollector
3
3
  include Rack::WebProfiler::Collector::DSL
4
4
 
5
5
  icon <<-'ICON'
6
6
  data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+PHN2ZyB3aWR0aD0iMjBweCIgaGVpZ2h0PSIyMHB4IiB2aWV3Qm94PSIwIDAgMjAgMjAiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+ICAgICAgICA8dGl0bGU+VHJpYW5nbGUgMTwvdGl0bGU+ICAgIDxkZXNjPkNyZWF0ZWQgd2l0aCBTa2V0Y2guPC9kZXNjPiAgICA8ZGVmcz48L2RlZnM+ICAgIDxnIGlkPSJQYWdlLTEiIHN0cm9rZT0ibm9uZSIgc3Ryb2tlLXdpZHRoPSIxIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPiAgICAgICAgPGcgaWQ9IkRlc2t0b3AtMiIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTcxLjAwMDAwMCwgLTEwLjAwMDAwMCkiIGZpbGw9IiM1ODU0NzMiPiAgICAgICAgICAgIDxwYXRoIGQ9Ik04MSwzMCBMNzEsMTUgTDkxLDE1IEw4MSwzMCBaIE05MSwxNCBMNzEsMTQgTDc1LDEwIEw4NywxMCBMOTEsMTQgWiIgaWQ9IlRyaWFuZ2xlLTEiPjwvcGF0aD4gICAgICAgIDwvZz4gICAgPC9nPjwvc3ZnPg==
7
7
  ICON
8
8
 
9
- collector_name "ruby"
10
- position 0
9
+ identifier "ruby"
10
+ label "Ruby"
11
+ position 0
11
12
 
12
13
  collect do |_request, _response|
13
14
  store :ruby_version, RUBY_VERSION