Sexp rendering partials
1 2 <h1>Result</h1> 3 <% if not @sexp.class %> 4 <h1>OH SHIT</h1> 5 <% elsif @sexp.class == String %> 6 <%= h(@sexp) -%> 7 <% elsif @sexp.first.class 8 @sexp.each { |element| %> 9 <%= render(:partial => 'sexp', :object => element) -%> 10 <% } %> 11 <% elsif @sexp.first.class == String %> 12 <%= render(:partial => 'sexp', :object => @sexp) -%> 13 <% end %>
Sexp partial
1 2 <table class="key-value-pairs"> 3 <thead> 4 <tr> 5 <th>key</th> 6 <th>value</th> 7 </tr> 8 </thead> 9 <tbody> 10 <% sexp.each_with_index { 11 |element, index| %> 12 <% if element.class == Array 13 element.each { |sublist| %> 14 <%= render(:partial => 'sexp', :collection => sublist) -%> 15 <% } %> 16 <% elsif element.class == String && index.modulo(2).zero? 17 hash = Hash[element, sexp[index + 1]] %> 18 <%= render :partial => 'pair', :locals => { :pair => hash } -%> 19 <% end %> 20 <% } %> 21 </tbody> 22 </table>
1 2 <% pair.each_pair{ |key, value| %> 3 <tr> 4 <td><%= key %></td> 5 <td> 6 <% if key =~ /uri/ %> 7 <%= link_to value, :controller => "explorer", :action => "explore", :uri => value %> 8 <% else %> 9 <%= value %> 10 <% end %> 11 </td> 12 </tr> 13 <% } %>