Skip to content

Latest commit

 

History

History
152 lines (103 loc) · 2.53 KB

DSL.md

File metadata and controls

152 lines (103 loc) · 2.53 KB

@title Collector DSL

Collector DSL

Presentation

{Rack::WebProfiler::Collector::DSL} {Rack::WebProfiler::Collector::DSL::ClassMethods}

Collector DSL methods

identifier

Technical identifier of the collector.

example

identifier "my_collector"

label

The label is shown in panel sidebar.

example

label "My Collector"

icon

Base64 encoded image for the icon collector.

example

icon <<-'ICON'
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8Xw8AAoMBgDTD2qgAAAAASUVORK5CYII=
ICON

position

Position of the collector in the toolbar.

example

position 2

collect

Place to collect data to store. It give you access to the {Rack::WebProfiler::Request} and the {Rack::WebProfiler::Response}. Inside you could store the datas you want. And you also could set a status. There is success, warning and error has available status.

example

collect do |request, response|
  store :url, request.url
  store :key, ["v1", "v2"]

  status :success if response.successful?
end

template

example

template "../path/to/template.erb"
# Or
template __FILE__, type: :DATA

is_enabled?

example

is_enabled? -> { defined? MyApp }

Collector template

h

highlight

partial

tab_content

panel_content

data(k)

Collector registration

It's really simple to register a Collector or an {Array} of collectors.

Rack::WebProfiler.register_collector MyCustomCollector
Rack::WebProfiler.register_collector [MyCustomCollector, MySecondCustomCollector]

You could also unregister a collector

Rack::WebProfiler.unregister_collector MyCustomCollector
Rack::WebProfiler.unregister_collector [MyCustomCollector, MySecondCustomCollector]

Example

class MyCustomCollector
  include Rack::WebProfiler::Collector::DSL

  icon <<-'ICON'
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8Xw8AAoMBgDTD2qgAAAAASUVORK5CYII=
ICON

  identifier "my_collector"
  label      "My Collector"
  position   2

  collect do |request, response|
    store :url, request.url
    store :key, ["v1", "v2"]

    status :success if response.successful?
  end

  template __FILE__, type: :DATA

  is_enabled? -> { defined? MyApp }
end

__END__
<% tab_content do %>
  <%=h data(:url) %>
<% end %>

<%# panel_content do %>
  <ul>
    <li><%=h data(:url) %></li>
    <li><%=h data(:key).inspect %></li>
  </ul>
<%# end %>