Last active
November 18, 2019 21:02
-
-
Save jrm/859feb52f6cbedeecbbc to your computer and use it in GitHub Desktop.
Dynamic Dashing Index
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
@darwin12 Did you make it work ? Please post your working code.
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
Yes - sorry. I was just illustrating the use of erb in the dashboard view rather then pre-generating html.
You can drop in a call to "each_slice(n)" to iterate another variable to use in the data-row attribute, e.g.
Note: above not tested, but you get the idea....