set up specs. added orientation to config.

pull/6827/head
Richard 11 years ago
parent 4f7712555b
commit 945079fdf4
  1. 10
      app/models/taskboard_card_configuration.rb
  2. 5
      db/migrate/20140117091758_add_orientation_to_taskboard_card_configuration.rb
  3. 6
      lib/open_project/pdf_export/taskboard_card/card_element.rb
  4. 6
      spec/spec_helper.rb
  5. 27
      spec/taskboard_card/document_generator_spec.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)

@ -0,0 +1,5 @@
class AddOrientationToTaskboardCardConfiguration < ActiveRecord::Migration
def change
add_column :taskboard_card_configurations, :orientation, :string
end
end

@ -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

@ -0,0 +1,6 @@
# -- load spec_helper from OpenProject core
require "spec_helper"
# load gem dependencies
require "prawn"
require "pdf/inspector"

@ -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
Loading…
Cancel
Save