!!! %html

%head
  %meta{charset: 'utf-8'}
  %title= title
  %link{rel: 'stylesheet', href: 'style.css'}
  - if style
    %style{type: 'text/css'}= style
  - if head_inject
    = head_inject
  - categories.each do |category|
    %link{href: "//dash_ref/Category/#{category.id.strip.gsub(/\//, '%2F')}/1"}
    - category.hasEntry(false)
    - category.entries.each_with_index do |entry, index|
      - if entry.name || entry.index_name
        - category.hasEntry(true)
        %link{href: "//dash_ref_#{category.id.strip.gsub(/\//, '%2F')}/Entry/#{(entry.name) ? entry.tags_stripped_name.strip.gsub(/\//, '%2F') : entry.index_name.strip.gsub(/\//, '%2F')}/0"}
      - elsif entry.command && entry.command.length > 0
        - category.hasEntry(true)
        %link{href: "//dash_ref_#{category.id.strip.gsub(/\//, '%2F')}/Command/#{entry.command.first.strip.gsub(/\//, '%2F')}/0"}
    - if !category.hasEntry
      %link{href: "//dash_ref/Entry/#{category.id.strip.gsub(/\//, '%2F')}/0"}

%body
  %header
    %h1= title

  %article
    %p~ introduction

    - categories.each do |category|
      %section.category{class: category.html_class}
        - if !category.hasEntry
          %a{name: "//dash_ref/Entry/#{category.id.strip.gsub(/\//, '%2F')}/0"}
        %h2{id:"//dash_ref/Category/#{category.id.strip.gsub(/\//, '%2F')}/1"}
          = category.id
        %div.scrollable
          %table
            - if category.header
              %tr
                - category.header.each do |header|
                  %th~ header

            - category.entries.each_with_index do |entry, index|
              %tr{id: ((entry.name || entry.index_name) ? "//dash_ref_#{category.id.strip.gsub(/\//, '%2F')}/Entry/#{(entry.name) ? entry.tags_stripped_name.strip.gsub(/\//, '%2F') : entry.index_name.strip.gsub(/\//, '%2F')}/0" : "//dash_ref_#{category.id.strip.gsub(/\//, '%2F')}/Command/#{entry.command.first.strip.gsub(/\//, '%2F')}/0" if (entry.name || entry.index_name || (entry.command && entry.command.length > 0)) )}
                - if entry.command
                  %td.command
                    - entry.command.each do |command|
                      %p
                        %code= CGI.escapeHTML(command)
                - if entry.td_command
                  - entry.td_command.each do |command|
                    %td.td_command
                      - if !command.empty?
                        %code= CGI.escapeHTML(command)
                - if entry.name || entry.notes || entry.html_notes
                  %td.description{:colspan => ("2" unless entry.command || entry.td_command || entry.td_notes)}
                    .name~ entry.name
                    .notes~ entry.notes
                    .notes~ entry.html_notes
                - if entry.td_notes
                  - entry.td_notes.each do |notes|
                    %td.td_notes
                      - if !notes.empty?
                        .td_notes~ notes
    - if notes
      %section.notes
        %h2 Notes
        ~ notes
  %footer
    - if source_url
      You can modify and improve this cheat sheet <a onclick="window.dash.openExternal_(this.href); return false;" href="#{source_url}">here</a>
    - else
      Generated with <a onclick="window.dash.openExternal_(this.href); return false;" href='https://github.com/Kapeli/cheatset#readme'>cheatset</a>