Sha256: 079dd7d9fb4480091863bf1768c5a555d4cc9c2347a9026e8648cb4d9c7957cd

Contents?: true

Size: 1.51 KB

Versions: 28

Compression:

Stored size: 1.51 KB

Contents

#!/usr/bin/env ruby -w
# encoding: UTF-8
#
# = ActivityLink.rb -- PostRunner - Manage the data from your Garmin sport devices.
#
# Copyright (c) 2014, 2015 by Chris Schlaeger <cs@taskjuggler.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#

require 'postrunner/HTMLBuilder'

module PostRunner

  # Generates the name of an Activity with a link to the ActivityReport.
  # Optionally, an icon can be shown for Activities that contain a current
  # personal record.
  class ActivityLink

    def initialize(activity, show_record_icon = false)
      @activity = activity
      @show_record_icon = show_record_icon
    end

    # Add the ActivityLink as HTML Elements to the document.
    # @param doc [HTMLBuilder] XML Document
    def to_html(doc)
      doc.unique(:activitylink_style) { doc.style(style) }

      doc.a(@activity.name, { :class => 'activity_link',
                              :href => @activity.html_file_name(false) })
      if @show_record_icon && @activity.has_records?
        doc.img(nil, { :src => 'icons/record-small.png',
                       :style => 'vertical-align:middle' })
      end
    end

    # Convert the ActivityLink into a plain text form. Return the first 20
    # characters of the Activity name.
    def to_s
      @activity.name[0..19]
    end

    private

    def style
      <<EOT
.activity_link {
  padding: 0px 3px 0px 3px;
}
EOT
    end

  end

end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
postrunner-1.2.0 lib/postrunner/ActivityLink.rb
postrunner-1.1.1 lib/postrunner/ActivityLink.rb
postrunner-1.1.0 lib/postrunner/ActivityLink.rb
postrunner-1.0.5 lib/postrunner/ActivityLink.rb
postrunner-1.0.4 lib/postrunner/ActivityLink.rb
postrunner-1.0.2 lib/postrunner/ActivityLink.rb
postrunner-1.0.1 lib/postrunner/ActivityLink.rb
postrunner-1.0.0 lib/postrunner/ActivityLink.rb
postrunner-0.12.0 lib/postrunner/ActivityLink.rb
postrunner-0.11.0 lib/postrunner/ActivityLink.rb
postrunner-0.10.1 lib/postrunner/ActivityLink.rb
postrunner-0.10.0 lib/postrunner/ActivityLink.rb
postrunner-0.9.0 lib/postrunner/ActivityLink.rb
postrunner-0.8.1 lib/postrunner/ActivityLink.rb
postrunner-0.8.0 lib/postrunner/ActivityLink.rb
postrunner-0.7.5 lib/postrunner/ActivityLink.rb
postrunner-0.7.4 lib/postrunner/ActivityLink.rb
postrunner-0.7.3 lib/postrunner/ActivityLink.rb
postrunner-0.7.2 lib/postrunner/ActivityLink.rb
postrunner-0.7.1 lib/postrunner/ActivityLink.rb