aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/middleware/templates/routes/_route_wrapper.html.erb
blob: 9bf5c96c954e7c6ebecd3ed4d088584c2941de5e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<style type='text/css'>
  #route_table td {padding: 0 30px;}
  #route_table    {margin:  0 auto 0;}
</style>

<table id='route_table' class='route_table'>
  <thead>
    <tr>
      <th>Helper<br />
        <%= link_to "Path", "#", 'data-route-helper' => '_path',
                    title: "Returns a relative path (without the http or domain)" %> /
        <%= link_to "Url", "#", 'data-route-helper' => '_url',
                    title: "Returns an absolute url (with the http and domain)" %>
      </th>
      <th>HTTP Verb</th>
      <th>Path</th>
      <th>Controller#Action</th>
    </tr>
  </thead>
  <tbody>
    <%= yield %>
  </tbody>
</table>

<script type='text/javascript'>
  function each(elems, func) {
    if (!elems instanceof Array) var elems = [elems];
    for(var i = elems.length; i--; ) {
      func(elems[i]);
    };
  }

  function setValOn(elems, val) {
    each(elems, function(elem) {
      elem.innerHTML = val;
    })
  }

 function onClick(elems, func) {
    each(elems, function(elem) {
      elem.onclick = func;
    })
  }

  // Enables functionality to toggle between `_path` and `_url` helper suffixes
  function setupRouteToggleHelperLinks() {
    var toggleLinks = document.querySelectorAll('#route_table [data-route-helper]');
    onClick(toggleLinks, function(){
      var helperTxt   = this.getAttribute("data-route-helper");
      var helperElems = document.querySelectorAll('[data-route-name] span.helper');
      setValOn(helperElems, helperTxt);
    })
  }

  setupRouteToggleHelperLinks();
</script>