File: TextReport.rb

package info (click to toggle)
tj3 3.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,048 kB
  • sloc: ruby: 36,481; javascript: 1,113; sh: 19; makefile: 17
file content (100 lines) | stat: -rw-r--r-- 2,783 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env ruby -w
# encoding: UTF-8
#
# = TextReport.rb -- The TaskJuggler III Project Management Software
#
# Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014
#               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 'taskjuggler/reports/ReportBase'

class TaskJuggler

  # This is the most basic type of report. It only contains 5 RichText elements.
  # It's got a header and footer and a central text with margin elements left
  # and right.
  class TextReport < ReportBase

    attr_accessor :header, :left, :center, :right, :footer

    def initialize(report)
      super

      @lWidth = @cWidth = @rWidth = 0
      @lPadding = @cPadding = @rPadding = 0
    end

    def generateIntermediateFormat
      super

      # A width of 0 means, the columns flexible.
      if a('center')
        if a('left') && a('right')
          @lWidth = @rWidth = 20
          @cWidth = 60
          @lPadding = @cPadding = 2
        elsif a('left') && !a('right')
          @lWidth = 25
          @cWidth = 75
          @lPadding = 2
        elsif !a('left') && a('right')
          @cWidth = 75
          @rWidth = 25
          @cPadding = 2
        else
          @cWidth = 100
        end
      else
        if a('left') && a('right')
          @lWidth = @rWidth = 50
          @lPadding = 2
        elsif a('left') && !a('right')
          @lWidth = 100
        elsif !a('left') && a('right')
          @rWidth = 100
        end
      end
    end

    def to_html
      html = []
      html << rt_to_html('header')
      if a('left') || a('center') || a('right')
        html << (table = XMLElement.new('table', 'class' => 'tj_text_page',
                                                 'cellspacing' => '0'))
        table << (row = XMLElement.new('tr', 'class' => 'tj_text_row'))
        %w( left center right).each do |i|
          width = instance_variable_get('@' + i[0].chr + 'Width')
          padding = instance_variable_get('@' + i[0].chr + 'Padding')
          if a(i)
            row << (col = XMLElement.new('td', 'class' => "tj_column_#{i}"))
            style = ''
            style += "width:#{width}%; " if width > 0
            style += "padding-right:#{padding}%; " if padding > 0
            col['style'] = style
            col << rt_to_html(i)
          end
        end

      end
      html << rt_to_html('footer')

      html
    end

    def to_csv
      @report.warning('text_report_no_csv',
                      "textreport '#{@report.fullId}' cannot be converted " +
                      "into CSV format")
      nil
    end

  end

end