Skip to content

Instantly share code, notes, and snippets.

@jrm
Last active November 18, 2019 21:02
Show Gist options
  • Save jrm/859feb52f6cbedeecbbc to your computer and use it in GitHub Desktop.
Save jrm/859feb52f6cbedeecbbc to your computer and use it in GitHub Desktop.
Dynamic Dashing Index
<script type='text/javascript'>
$(function() {
$('li').live('click', function(e){
window.location = $(this).find('.widget').data('url');
});
});
</script>
<% content_for :title do %>Summary<% end %>
<div class='gridster'>
<ul>
<% Dir.glob("./dashboards/*").reject {|f| f.match 'layout|summary' }.each_with_index do |d,i| %>
<% name = d.match(/\.\/dashboards\/(.*)\.erb/)[1] %>
<li data-row='1' data-col="<%= i+1 %>" data-sizex='1' data-sizey='1'>
<div data-view='Text' data-title="<%= name.upcase %>" data-url="/<%= name %>"></div>
</li>
<% end %>
</ul>
</div>
@davidc
Copy link

davidc commented Jun 19, 2015

There were a couple of minor syntax errors, here is a working version of the above with multiple columns. I also made it split dashboard names on "-" or "_" and convert them to title case.

<script type='text/javascript'>
$(function() {
  $('li').live('click', function(e){
    window.location = $(this).find('.widget').data('url');
  });
});
</script>

<% content_for :title do %>Summary<% end %>
<div class='gridster'>
  <ul>
    <% Dir.glob("./dashboards/*").reject {|f| f.match 'layout|summary|.*~' }.each_slice(3).each_wit\
h_index do |row, r| %>
      <% row.each_with_index do |d,i| %>
        <% name = d.match(/\.\/dashboards\/(.*)\.erb/)[1] %>
        <li data-row='<%= r+1 %>' data-col="<%= i+1 %>" data-sizex='1' data-sizey='1'>
          <div data-view='Text' data-title="<%= name.split(/[-_ ]/).map(&:capitalize).join(' ') %>" dat\
a-url="/<%= name %>"></div>
        </li>
      <% end %>
    <% end %>
  </ul>
</div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment