module IconHelper

  def ion_icon(name, html_class = '')
    "<i class='ion ion-#{name} #{html_class}'></i>".html_safe
  end

  def edit_icon
    fa_icon 'pencil'
  end

  def show_icon
    fa_icon 'eye'
  end

  def delete_icon
    fa_icon 'trash-o'
  end

  def clone_icon
    fa_icon 'copy'
  end

  def start_icon
    fa_icon 'play-circle-o'
  end

  def create_icon
    fa_icon 'plus'
  end

  def schedule_icon
    fa_icon 'clock-o'
  end

  def pause_icon
    fa_icon 'pause'
  end

  def execution_icon
    fa_icon 'play-circle'
  end

  def definition_icon
    fa_icon 'file-text'
  end

  def schedule_icon
    fa_icon 'clock-o'
  end

  def vm_icon
    fa_icon 'desktop'
  end

  def dashboard_icon
    fa_icon 'dashboard'
  end

  def active_icon
    fa_icon 'cog spin'
  end

  def finished_icon
    fa_icon 'flag-checkered'
  end

  def expand_icon
    fa_icon 'plus'
  end

  def download_icon
    fa_icon 'download'
  end

  def search_icon
    fa_icon 'search'
  end

  def abort_icon
    fa_icon 'power-off'
  end

  def restart_icon
    fa_icon 'repeat'
  end
end
module IconHelper

  def ion_icon(name, html_class = '')
    "<i class='ion ion-#{name} #{html_class}'></i>".html_safe
  end

  FA_ICON_MAPPINGS = {
    abort: 'power-off',
    active: 'cog spin',
    clone: 'copy',
    create: 'plus',
    dashboard: 'dashboard',
    definition: 'file-text',
    delete: 'trash-o',
    download: 'download',
    edit: 'pencil',
    execution: 'play-circle',
    expand: 'plus',
    finished: 'flag-checkered',
    pause: 'pause',
    restart: 'repeat',
    schedule: 'clock-o',
    search: 'search',
    show: 'eye',
    start: 'play-circle-o',
    vm: 'desktop',
  }
  # Creates a method called *_icon for each icon mapping using font awsome icons
  # Example:
  # def abort_icon
  #   fa_icon 'power-off'
  # end
  FA_ICON_MAPPINGS.each do |key, value|
    define_method("#{key}_icon") do
      fa_icon value
    end
  end
end
Replace similar methods with meta-programming and hash-based icon mapping
Replace similar methods with meta-programming and hash-based icon mapping
