From 945079fdf4e6227d372971aa383d07dd187ce935 Mon Sep 17 00:00:00 2001 From: Richard Date: Fri, 17 Jan 2014 11:50:26 +0100 Subject: [PATCH] set up specs. added orientation to config. --- app/models/taskboard_card_configuration.rb | 10 ++++++- ...ntation_to_taskboard_card_configuration.rb | 5 ++++ .../pdf_export/taskboard_card/card_element.rb | 6 ++++- spec/spec_helper.rb | 6 +++++ .../taskboard_card/document_generator_spec.rb | 27 +++++++++++++++++++ 5 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20140117091758_add_orientation_to_taskboard_card_configuration.rb create mode 100644 spec/spec_helper.rb create mode 100644 spec/taskboard_card/document_generator_spec.rb diff --git a/app/models/taskboard_card_configuration.rb b/app/models/taskboard_card_configuration.rb index ad9762b467..d11136beea 100644 --- a/app/models/taskboard_card_configuration.rb +++ b/app/models/taskboard_card_configuration.rb @@ -1,7 +1,15 @@ class TaskboardCardConfiguration < ActiveRecord::Base #Note: rows is YAML text which we'll parse into a hash - attr_accessible :identifier, :name, :rows, :per_page, :page_size + attr_accessible :identifier, :name, :rows, :per_page, :page_size, :orientation + + def landscape? + !portrait? + end + + def portrait? + orientation == "portrait" + end def rows_hash YAML::load(rows) diff --git a/db/migrate/20140117091758_add_orientation_to_taskboard_card_configuration.rb b/db/migrate/20140117091758_add_orientation_to_taskboard_card_configuration.rb new file mode 100644 index 0000000000..62a26e7858 --- /dev/null +++ b/db/migrate/20140117091758_add_orientation_to_taskboard_card_configuration.rb @@ -0,0 +1,5 @@ +class AddOrientationToTaskboardCardConfiguration < ActiveRecord::Migration + def change + add_column :taskboard_card_configurations, :orientation, :string + end +end diff --git a/lib/open_project/pdf_export/taskboard_card/card_element.rb b/lib/open_project/pdf_export/taskboard_card/card_element.rb index df8b4e1e0e..b78202b3d2 100644 --- a/lib/open_project/pdf_export/taskboard_card/card_element.rb +++ b/lib/open_project/pdf_export/taskboard_card/card_element.rb @@ -121,7 +121,11 @@ module OpenProject::PdfExport::TaskboardCard @rows_config["rows"].each_with_index do |(key, value), i| # min lines * font height (first col) # TODO: get the biggest one k, v = value["columns"].first - min_heights[i] = (@pdf.font.height_at(v["font_size"]) * v["minimum_lines"]).floor + min_lines = v["minimum_lines"] + min_lines ||= 1 + font_size = v["font_size"] + font_size ||= 10 + min_heights[i] = (@pdf.font.height_at(font_size) * min_lines).floor end min_heights end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000000..525042043f --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,6 @@ +# -- load spec_helper from OpenProject core +require "spec_helper" + +# load gem dependencies +require "prawn" +require "pdf/inspector" \ No newline at end of file diff --git a/spec/taskboard_card/document_generator_spec.rb b/spec/taskboard_card/document_generator_spec.rb new file mode 100644 index 0000000000..741ccdd6cd --- /dev/null +++ b/spec/taskboard_card/document_generator_spec.rb @@ -0,0 +1,27 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe OpenProject::PdfExport::TaskboardCard::DocumentGenerator do + # let(:pdf) { Prawn::Document.new(:margin => 0) } + let(:config) { TaskboardCardConfiguration.new({ + name: "Default", + identifier: "default", + per_page: 1, + page_size: "A4", + orientation: "landscape", + rows: "rows:\n row1:\n has_border: false\n columns:\n id:\n has_label: false\n font_size: 15\n row1:\n has_border: false\n columns:\n subject:\n has_label: false\n font_size: 15" + })} + let(:work_package) { WorkPackage.new({ + id: 1234, + subject: "Test work package", + description: "This is a test work package" + })} + + it 'shows work package subject' do + work_packages = [work_package] + generator = OpenProject::PdfExport::TaskboardCard::DocumentGenerator.new(config, work_packages) + + text = PDF::Inspector::Text.analyze(generator.render) + text.strings.join.should == 'Test work package' + end + +end \ No newline at end of file