diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..15dce72 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,66 @@ +name: CI + +on: + push: + pull_request: + schedule: + - cron: "6 20 * * 6" + +jobs: + code-style: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.1.0 + - name: Gems cache + uses: actions/cache@v2 + with: + path: ~/gems + key: gems-3.1.0-${{ hashFiles('*.gemspec', 'Gemfile') }}-${{ github.sha }} + restore-keys: | + gems-3.1.0-${{ hashFiles('*.gemspec', 'Gemfile') }}- + gems-3.1.0- + - name: Install dependencies + run: | + gem install bundler + bundle config path ~/gems + bundle install --jobs 4 --retry 3 + - name: Check code style + run: bundle exec rake rubocop + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby: + - "2.6.0" + - "2.6" + - "2.7.0" + - "2.7" + - "3.0.0" + - "3.0" + - jruby-9.3 + steps: + - uses: actions/checkout@v1 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + - name: Gems cache + uses: actions/cache@v2 + with: + path: ~/gems + key: gems-${{ matrix.ruby }}-${{ hashFiles('*.gemspec', 'Gemfile') }}-${{ github.sha }} + restore-keys: | + gems-${{ matrix.ruby }}-${{ hashFiles('*.gemspec', 'Gemfile') }}- + gems-${{ matrix.ruby }}- + - name: Install dependencies + run: | + gem install bundler + bundle config path ~/gems + bundle install --jobs 4 --retry 3 + - name: Run tests + run: bundle exec rake spec diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..94cdf4c --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,5 @@ +inherit_from: .rubocop_todo.yml + +inherit_gem: + prawn-dev: rubocop.yml + diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..09e219e --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,1003 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2022-02-08 19:46:35 UTC using RuboCop version 1.25.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include. +# Include: **/*.gemspec +Gemspec/OrderedDependencies: + Exclude: + - 'prawn-table.gemspec' + +# Offense count: 53 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: with_first_argument, with_fixed_indentation +Layout/ArgumentAlignment: + Enabled: false + +# Offense count: 11 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: with_first_element, with_fixed_indentation +Layout/ArrayAlignment: + Exclude: + - 'lib/prawn/table/cell/text.rb' + - 'spec/table_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleAlignWith. +# SupportedStylesAlignWith: either, start_of_block, start_of_line +Layout/BlockAlignment: + Exclude: + - 'spec/table_spec.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +Layout/BlockEndNewline: + Exclude: + - 'lib/prawn/table.rb' + - 'lib/prawn/table/cells.rb' + - 'spec/table_spec.rb' + +# Offense count: 20 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentOneStep, IndentationWidth. +# SupportedStyles: case, end +Layout/CaseIndentation: + Exclude: + - 'lib/prawn/table/cell.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: leading, trailing +Layout/DotPosition: + Exclude: + - 'lib/prawn/table/cell/text.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +Layout/EmptyLineAfterGuardClause: + Exclude: + - 'lib/prawn/table.rb' + - 'lib/prawn/table/cells.rb' + - 'lib/prawn/table/column_width_calculator.rb' + +# Offense count: 20 +# Cop supports --auto-correct. +Layout/EmptyLineAfterMagicComment: + Enabled: false + +# Offense count: 11 +# Cop supports --auto-correct. +Layout/EmptyLines: + Exclude: + - 'Rakefile' + - 'lib/prawn/table.rb' + - 'spec/cell_spec.rb' + - 'spec/table_spec.rb' + +# Offense count: 18 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, no_empty_lines +Layout/EmptyLinesAroundBlockBody: + Exclude: + - 'manual/contents.rb' + - 'manual/table/cell_borders_and_bg.rb' + - 'manual/table/table.rb' + - 'spec/cell_spec.rb' + - 'spec/table_spec.rb' + +# Offense count: 20 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only +Layout/EmptyLinesAroundClassBody: + Exclude: + - 'lib/prawn/table.rb' + - 'lib/prawn/table/cell.rb' + - 'lib/prawn/table/cell/image.rb' + - 'lib/prawn/table/cell/in_table.rb' + - 'lib/prawn/table/cell/span_dummy.rb' + - 'lib/prawn/table/cell/subtable.rb' + - 'lib/prawn/table/cell/text.rb' + - 'lib/prawn/table/cells.rb' + - 'lib/prawn/table/column_width_calculator.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines +Layout/EmptyLinesAroundModuleBody: + Exclude: + - 'lib/prawn/table/cell/in_table.rb' + - 'spec/cell_spec.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleAlignWith, Severity. +# SupportedStylesAlignWith: keyword, variable, start_of_line +Layout/EndAlignment: + Exclude: + - 'lib/prawn/table/cell.rb' + +# Offense count: 46 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment. +Layout/ExtraSpacing: + Exclude: + - 'lib/prawn/table.rb' + - 'lib/prawn/table/cell.rb' + - 'lib/prawn/table/cells.rb' + - 'lib/prawn/table/column_width_calculator.rb' + - 'manual/table/basic_block.rb' + - 'manual/table/before_rendering_page.rb' + - 'manual/table/cell_border_lines.rb' + - 'manual/table/image_cells.rb' + - 'prawn-table.gemspec' + - 'spec/table_spec.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: special_inside_parentheses, consistent, align_brackets +Layout/FirstArrayElementIndentation: + Exclude: + - 'spec/table/span_dummy_spec.rb' + - 'spec/table_spec.rb' + +# Offense count: 52 +# Cop supports --auto-correct. +Layout/FirstArrayElementLineBreak: + Enabled: false + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: special_inside_parentheses, consistent, align_braces +Layout/FirstHashElementIndentation: + Exclude: + - 'spec/table_spec.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +Layout/FirstHashElementLineBreak: + Exclude: + - 'manual/table/cell_borders_and_bg.rb' + - 'manual/table/cell_text.rb' + - 'manual/table/image_cells.rb' + - 'spec/table_spec.rb' + +# Offense count: 81 +# Cop supports --auto-correct. +Layout/FirstMethodArgumentLineBreak: + Enabled: false + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. +# SupportedHashRocketStyles: key, separator, table +# SupportedColonStyles: key, separator, table +# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit +Layout/HashAlignment: + Exclude: + - 'lib/prawn/table/cell.rb' + - 'manual/table/image_cells.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: normal, indented_internal_methods +Layout/IndentationConsistency: + Exclude: + - 'lib/prawn/table/cell.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: Width, IgnoredPatterns. +Layout/IndentationWidth: + Exclude: + - 'manual/table/cell_borders_and_bg.rb' + - 'spec/table_spec.rb' + +# Offense count: 49 +# Cop supports --auto-correct. +# Configuration parameters: AllowDoxygenCommentStyle, AllowGemfileRubyComment. +Layout/LeadingCommentSpace: + Exclude: + - 'lib/prawn/table/column_width_calculator.rb' + - 'spec/cell_spec.rb' + - 'spec/table_spec.rb' + +# Offense count: 8 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: symmetrical, new_line, same_line +Layout/MultilineArrayBraceLayout: + Exclude: + - 'manual/table/cell_border_lines.rb' + - 'manual/table/cell_borders_and_bg.rb' + - 'manual/table/cell_dimensions.rb' + - 'manual/table/cell_text.rb' + - 'manual/table/filtering.rb' + - 'spec/table_spec.rb' + +# Offense count: 29 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedTypes: block, case, class, if, kwbegin, module +# SupportedStyles: same_line, new_line +Layout/MultilineAssignmentLayout: + Exclude: + - 'lib/prawn/table.rb' + - 'lib/prawn/table/cell.rb' + - 'lib/prawn/table/cells.rb' + - 'manual/table/filtering.rb' + - 'spec/table_spec.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +Layout/MultilineHashKeyLineBreaks: + Exclude: + - 'manual/table/cell_text.rb' + - 'manual/table/image_cells.rb' + - 'spec/table_spec.rb' + +# Offense count: 21 +# Cop supports --auto-correct. +Layout/MultilineMethodArgumentLineBreaks: + Exclude: + - 'lib/prawn/table/cell.rb' + - 'lib/prawn/table/cell/text.rb' + - 'manual/contents.rb' + - 'manual/table/cell_border_lines.rb' + - 'manual/table/cell_text.rb' + - 'manual/table/image_cells.rb' + - 'spec/cell_spec.rb' + - 'spec/table/span_dummy_spec.rb' + - 'spec/table_spec.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: symmetrical, new_line, same_line +Layout/MultilineMethodCallBraceLayout: + Exclude: + - 'lib/prawn/table/cell/image.rb' + - 'manual/table/table.rb' + - 'spec/table_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: aligned, indented, indented_relative_to_receiver +Layout/MultilineMethodCallIndentation: + Exclude: + - 'lib/prawn/table/column_width_calculator.rb' + +# Offense count: 25 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: aligned, indented +Layout/MultilineOperationIndentation: + Exclude: + - 'lib/prawn/table.rb' + - 'lib/prawn/table/cell.rb' + - 'prawn-table.gemspec' + - 'spec/cell_spec.rb' + - 'spec/table_spec.rb' + +# Offense count: 64 +# Cop supports --auto-correct. +Layout/SpaceAfterComma: + Exclude: + - 'lib/prawn/table/cells.rb' + - 'prawn-table.gemspec' + - 'spec/table/span_dummy_spec.rb' + - 'spec/table_spec.rb' + +# Offense count: 18 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: space, no_space +Layout/SpaceAroundEqualsInParameterDefault: + Exclude: + - 'lib/prawn/table.rb' + - 'lib/prawn/table/cell.rb' + - 'lib/prawn/table/cell/image.rb' + - 'lib/prawn/table/cell/subtable.rb' + - 'lib/prawn/table/cell/text.rb' + - 'lib/prawn/table/cells.rb' + - 'spec/cell_spec.rb' + - 'spec/spec_helper.rb' + +# Offense count: 81 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator. +# SupportedStylesForExponentOperator: space, no_space +Layout/SpaceAroundOperators: + Exclude: + - 'lib/prawn/table.rb' + - 'lib/prawn/table/cell.rb' + - 'lib/prawn/table/cell/text.rb' + - 'lib/prawn/table/column_width_calculator.rb' + - 'manual/table/cell_border_lines.rb' + - 'prawn-table.gemspec' + - 'spec/table_spec.rb' + +# Offense count: 25 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. +# SupportedStyles: space, no_space +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceBeforeBlockBraces: + Exclude: + - 'lib/prawn/table/column_width_calculator.rb' + - 'spec/cell_spec.rb' + - 'spec/table_spec.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +Layout/SpaceBeforeComma: + Exclude: + - 'spec/table_spec.rb' + +# Offense count: 59 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets. +# SupportedStyles: space, no_space, compact +# SupportedStylesForEmptyBrackets: space, no_space +Layout/SpaceInsideArrayLiteralBrackets: + Exclude: + - 'manual/table/basic_block.rb' + - 'manual/table/cell_border_lines.rb' + - 'manual/table/cell_borders_and_bg.rb' + - 'manual/table/cell_dimensions.rb' + - 'manual/table/cell_text.rb' + - 'manual/table/column_widths.rb' + - 'manual/table/content_and_subtables.rb' + - 'manual/table/creation.rb' + - 'manual/table/filtering.rb' + - 'spec/table_spec.rb' + +# Offense count: 33 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. +# SupportedStyles: space, no_space +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceInsideBlockBraces: + Exclude: + - 'lib/prawn/table.rb' + - 'lib/prawn/table/column_width_calculator.rb' + - 'spec/cell_spec.rb' + - 'spec/spec_helper.rb' + - 'spec/table_spec.rb' + +# Offense count: 170 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. +# SupportedStyles: space, no_space, compact +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceInsideHashLiteralBraces: + Exclude: + - 'lib/prawn/table/cell.rb' + - 'manual/table/cell_borders_and_bg.rb' + - 'manual/table/cell_dimensions.rb' + - 'manual/table/column_widths.rb' + - 'manual/table/content_and_subtables.rb' + - 'manual/table/image_cells.rb' + - 'manual/table/span.rb' + - 'spec/cell_spec.rb' + - 'spec/table/span_dummy_spec.rb' + - 'spec/table_spec.rb' + +# Offense count: 20 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: space, compact, no_space +Layout/SpaceInsideParens: + Exclude: + - 'Rakefile' + - 'manual/table/table.rb' + - 'spec/table_spec.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +Layout/SpaceInsidePercentLiteralDelimiters: + Exclude: + - 'spec/table_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/SpaceInsideRangeLiteral: + Exclude: + - 'lib/prawn/table/cells.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets. +# SupportedStyles: space, no_space +# SupportedStylesForEmptyBrackets: space, no_space +Layout/SpaceInsideReferenceBrackets: + Exclude: + - 'prawn-table.gemspec' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: final_newline, final_blank_line +Layout/TrailingEmptyLines: + Exclude: + - 'spec/extensions/file_fixture_helper.rb' + - 'spec/spec_helper.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: AllowInHeredoc. +Layout/TrailingWhitespace: + Exclude: + - 'lib/prawn/table.rb' + +# Offense count: 1 +# Configuration parameters: AllowSafeAssignment. +Lint/AssignmentInCondition: + Exclude: + - 'lib/prawn/table/cell/text.rb' + +# Offense count: 1 +Lint/LiteralAsCondition: + Exclude: + - 'lib/prawn/table.rb' + +# Offense count: 1 +# Cop supports --auto-correct-all. +Lint/NonDeterministicRequireOrder: + Exclude: + - 'spec/spec_helper.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Lint/ParenthesesAsGroupedExpression: + Exclude: + - 'spec/table_spec.rb' + +# Offense count: 1 +Lint/UnreachableCode: + Exclude: + - 'lib/prawn/table/cell.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. +Lint/UnusedBlockArgument: + Exclude: + - 'lib/prawn/table/column_width_calculator.rb' + - 'spec/cell_spec.rb' + +# Offense count: 8 +Lint/UselessAssignment: + Exclude: + - 'spec/table_spec.rb' + +# Offense count: 5 +# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. +# IgnoredMethods: refine +Metrics/BlockLength: + Max: 40 + +# Offense count: 2 +Naming/ConstantName: + Exclude: + - 'lib/prawn/table/cell.rb' + - 'lib/prawn/table/cell/text.rb' + +# Offense count: 2 +# Configuration parameters: EnforcedStyleForLeadingUnderscores. +# SupportedStylesForLeadingUnderscores: disallowed, required, optional +Naming/MemoizedInstanceVariableName: + Exclude: + - 'lib/prawn/table.rb' + - 'lib/prawn/table/cell.rb' + +# Offense count: 13 +# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. +# AllowedNames: at, by, db, id, in, io, ip, of, on, os, pp, to +Naming/MethodParameterName: + Exclude: + - 'lib/prawn/table/cell.rb' + - 'lib/prawn/table/cell/image.rb' + - 'lib/prawn/table/cell/span_dummy.rb' + +# Offense count: 1 +# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros. +# NamePrefix: is_, has_, have_ +# ForbiddenPrefixes: is_, has_, have_ +# AllowedMethods: is_a? +# MethodDefinitionMacros: define_method, define_singleton_method +Naming/PredicateName: + Exclude: + - 'spec/**/*' + - 'lib/prawn/table/column_width_calculator.rb' + +# Offense count: 4 +# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers. +# SupportedStyles: snake_case, normalcase, non_integer +# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339 +Naming/VariableNumber: + Exclude: + - 'manual/table/content_and_subtables.rb' + - 'spec/table_spec.rb' + +# Offense count: 1 +# Configuration parameters: MinSize. +Performance/CollectionLiteralInLoop: + Exclude: + - 'lib/prawn/table/cell.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: SafeMultiline. +Performance/EndWith: + Exclude: + - 'lib/prawn/table/cells.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Performance/RedundantBlockCall: + Exclude: + - 'lib/prawn/table/cell.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Performance/RegexpMatch: + Exclude: + - 'lib/prawn/table/cells.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Performance/StringInclude: + Exclude: + - 'spec/table_spec.rb' + +# Offense count: 11 +# Cop supports --auto-correct. +# Configuration parameters: OnlySumOrWithInitialValue. +Performance/Sum: + Exclude: + - 'lib/prawn/table.rb' + - 'lib/prawn/table/cell.rb' + - 'lib/prawn/table/cells.rb' + - 'lib/prawn/table/column_width_calculator.rb' + - 'spec/table_spec.rb' + +# Offense count: 2 +RSpec/AnyInstance: + Exclude: + - 'spec/cell_spec.rb' + +# Offense count: 3 +# Configuration parameters: Prefixes. +# Prefixes: when, with, without +RSpec/ContextWording: + Exclude: + - 'spec/table_spec.rb' + +# Offense count: 2 +# Configuration parameters: IgnoredMetadata. +RSpec/DescribeClass: + Exclude: + - '**/spec/features/**/*' + - '**/spec/requests/**/*' + - '**/spec/routing/**/*' + - '**/spec/system/**/*' + - '**/spec/views/**/*' + - 'spec/cell_spec.rb' + - 'spec/table_spec.rb' + +# Offense count: 131 +# Cop supports --auto-correct. +# Configuration parameters: CustomTransform, IgnoredWords. +RSpec/ExampleWording: + Exclude: + - 'spec/cell_spec.rb' + - 'spec/table_spec.rb' + +# Offense count: 14 +# Cop supports --auto-correct. +# Configuration parameters: . +# SupportedStyles: implicit, each, example +RSpec/HookArgument: + EnforcedStyle: each + +# Offense count: 340 +# Configuration parameters: AssignmentOnly. +RSpec/InstanceVariable: + Exclude: + - 'spec/cell_spec.rb' + - 'spec/table/span_dummy_spec.rb' + - 'spec/table_spec.rb' + +# Offense count: 71 +# Configuration parameters: EnforcedStyle. +# SupportedStyles: allow, expect +RSpec/MessageExpectation: + Exclude: + - 'spec/cell_spec.rb' + - 'spec/table_spec.rb' + +# Offense count: 73 +# Configuration parameters: . +# SupportedStyles: have_received, receive +RSpec/MessageSpies: + EnforcedStyle: receive + +# Offense count: 2 +RSpec/MultipleDescribes: + Exclude: + - 'spec/cell_spec.rb' + - 'spec/table_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: not_to, to_not +RSpec/NotToNot: + Exclude: + - 'spec/spec_helper.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: prefer_alias, prefer_alias_method +Style/Alias: + Exclude: + - 'lib/prawn/table/cell.rb' + - 'lib/prawn/table/cells.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, conditionals +Style/AndOr: + Exclude: + - 'lib/prawn/table/column_width_calculator.rb' + +# Offense count: 25 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners, BracesRequiredMethods. +# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces +# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object +# FunctionalMethods: let, let!, subject, watch +# IgnoredMethods: lambda, proc, it +Style/BlockDelimiters: + Exclude: + - 'lib/prawn/table.rb' + - 'lib/prawn/table/cells.rb' + - 'lib/prawn/table/column_width_calculator.rb' + - 'spec/cell_spec.rb' + - 'spec/table_spec.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: AllowOnConstant. +Style/CaseEquality: + Exclude: + - 'lib/prawn/table.rb' + - 'lib/prawn/table/cell.rb' + - 'lib/prawn/table/cells.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: nested, compact +Style/ClassAndModuleChildren: + Exclude: + - 'spec/spec_helper.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: is_a?, kind_of? +Style/ClassCheck: + Exclude: + - 'lib/prawn/table/cell.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: IgnoredMethods. +# IgnoredMethods: ==, equal?, eql? +Style/ClassEqualityComparison: + Exclude: + - 'lib/prawn/table/column_width_calculator.rb' + +# Offense count: 15 +# Cop supports --auto-correct-all. +# Configuration parameters: PreferredMethods, MethodsAcceptingSymbol. +# MethodsAcceptingSymbol: inject, reduce +Style/CollectionMethods: + Exclude: + - 'lib/prawn/table.rb' + - 'lib/prawn/table/cell.rb' + - 'lib/prawn/table/cells.rb' + - 'lib/prawn/table/column_width_calculator.rb' + - 'spec/table_spec.rb' + +# Offense count: 2 +Style/CombinableLoops: + Exclude: + - 'lib/prawn/table/cell.rb' + - 'lib/prawn/table/column_width_calculator.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions. +# SupportedStyles: assign_to_condition, assign_inside_condition +Style/ConditionalAssignment: + Exclude: + - 'lib/prawn/table.rb' + - 'spec/table_spec.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +Style/Dir: + Exclude: + - 'prawn-table.gemspec' + - 'spec/cell_spec.rb' + - 'spec/table/span_dummy_spec.rb' + - 'spec/table_spec.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/EachWithObject: + Exclude: + - 'lib/prawn/table.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +Style/EmptyCaseCondition: + Exclude: + - 'lib/prawn/table/cell.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/EmptyLiteral: + Exclude: + - 'spec/table_spec.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: compact, expanded +Style/EmptyMethod: + Exclude: + - 'lib/prawn/table/cell/span_dummy.rb' + +# Offense count: 34 +# Cop supports --auto-correct. +Style/Encoding: + Enabled: false + +# Offense count: 38 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, always_true, never +Style/FrozenStringLiteralComment: + Enabled: false + +# Offense count: 468 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. +# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys +# SupportedShorthandSyntax: always, never, either +Style/HashSyntax: + Enabled: false + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowIfModifier. +Style/IfInsideElse: + Exclude: + - 'lib/prawn/table/column_width_calculator.rb' + +# Offense count: 1 +Style/ImplicitRuntimeError: + Exclude: + - 'lib/prawn/table/cells.rb' + +# Offense count: 28 +# Cop supports --auto-correct. +Style/LineEndConcatenation: + Exclude: + - 'lib/prawn/table.rb' + - 'lib/prawn/table/cell.rb' + - 'spec/cell_spec.rb' + - 'spec/table_spec.rb' + +# Offense count: 1 +Style/MissingRespondToMissing: + Exclude: + - 'lib/prawn/table/cells.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/MultilineTernaryOperator: + Exclude: + - 'lib/prawn/table/cells.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: literals, strict +Style/MutableConstant: + Exclude: + - 'lib/prawn/table/cell/text.rb' + +# Offense count: 8 +# Cop supports --auto-correct-all. +# Configuration parameters: EnforcedStyle, IgnoredMethods. +# SupportedStyles: predicate, comparison +Style/NumericPredicate: + Exclude: + - 'spec/**/*' + - 'lib/prawn/table.rb' + - 'lib/prawn/table/cells.rb' + - 'lib/prawn/table/column_width_calculator.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +Style/ParallelAssignment: + Exclude: + - 'lib/prawn/table.rb' + - 'lib/prawn/table/cells.rb' + - 'spec/table_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: PreferredDelimiters. +Style/PercentLiteralDelimiters: + Exclude: + - 'prawn-table.gemspec' + +# Offense count: 3 +# Cop supports --auto-correct. +Style/RedundantInterpolation: + Exclude: + - 'spec/table_spec.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: AllowMultipleReturnValues. +Style/RedundantReturn: + Exclude: + - 'lib/prawn/table.rb' + - 'lib/prawn/table/column_width_calculator.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/RedundantSelf: + Exclude: + - 'lib/prawn/table/cells.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: return, return_nil +Style/ReturnNil: + Exclude: + - 'lib/prawn/table/cells.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods. +# AllowedMethods: present?, blank?, presence, try, try! +Style/SafeNavigation: + Exclude: + - 'lib/prawn/table/cell.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: AllowAsExpressionSeparator. +Style/Semicolon: + Exclude: + - 'lib/prawn/table.rb' + - 'spec/table_spec.rb' + +# Offense count: 27 +Style/Send: + Exclude: + - 'lib/prawn/table.rb' + - 'lib/prawn/table/cell.rb' + - 'lib/prawn/table/cells.rb' + - 'lib/prawn/table/column_width_calculator.rb' + - 'spec/table_spec.rb' + +# Offense count: 2 +# Cop supports --auto-correct-all. +Style/SlicingWithRange: + Exclude: + - 'spec/table_spec.rb' + +# Offense count: 3 +# Cop supports --auto-correct-all. +# Configuration parameters: Mode. +Style/StringConcatenation: + Exclude: + - 'lib/prawn/table.rb' + - 'spec/spec_helper.rb' + +# Offense count: 923 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. +# SupportedStyles: single_quotes, double_quotes +Style/StringLiterals: + Enabled: false + +# Offense count: 8 +# Cop supports --auto-correct. +# Configuration parameters: . +# SupportedStyles: percent, brackets +Style/SymbolArray: + EnforcedStyle: percent + MinSize: 13 + +# Offense count: 20 +# Cop supports --auto-correct-all. +# Configuration parameters: AllowMethodsWithArguments, IgnoredMethods. +# IgnoredMethods: respond_to, define_method +Style/SymbolProc: + Exclude: + - 'spec/cell_spec.rb' + - 'spec/table_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, AllowSafeAssignment. +# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex +Style/TernaryParentheses: + Exclude: + - 'spec/table_spec.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInArrayLiteral: + Exclude: + - 'spec/table_spec.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInHashLiteral: + Exclude: + - 'spec/table_spec.rb' + +# Offense count: 54 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, MinSize, WordRegex. +# SupportedStyles: percent, brackets +Style/WordArray: + Exclude: + - 'Rakefile' + - 'manual/table/before_rendering_page.rb' + - 'manual/table/cell_text.rb' + - 'manual/table/creation.rb' + - 'manual/table/row_colors.rb' + - 'manual/table/span.rb' + - 'spec/table_spec.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Layout/LineLength: + Max: 198 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index cff7229..0000000 --- a/.travis.yml +++ /dev/null @@ -1,20 +0,0 @@ -language: ruby -before_install: - - gem install bundler - - bundle --version -rvm: - - 2.0.0-p0 - - 2.0.0-p648 - - 2.1.0-p0 - - 2.1.8 - - 2.2.0-p0 - - 2.2.4 - - 2.3.0 - - rbx-2 - - jruby-9.0.4.0 -matrix: - include: - - rvm: jruby-1.7.22 - env: JRUBY_OPTS=--2.0 - allow_failures: - - rvm: rbx-2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d59195..33f2472 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## Master +* Bugfix: Use a cell's custom style over table styles. (PR [#143](https://github.com/prawnpdf/prawn-table/pull/143), issue [#56](https://github.com/prawnpdf/prawn-table/issues/56)) * Bugfix: Use the cell's specified font to calculate the cell width. (Jesse Doyle, PR [#60](https://github.com/prawnpdf/prawn-table/pull/60), issue [#42](https://github.com/prawnpdf/prawn-table/issues/42)) ## 0.2.3 diff --git a/README.md b/README.md index 732ca7e..24c187b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Prawn::Table [![Gem Version](https://badge.fury.io/rb/prawn-table.png)](http://badge.fury.io/rb/prawn-table) -[![Build Status](https://secure.travis-ci.org/prawnpdf/prawn-table.png)](http://travis-ci.org/prawnpdf/prawn-table) +![Build Status](https://github.com/prawnpdf/prawn-table/actions/workflows/ci.yml/badge.svg) [![Code Climate](https://codeclimate.com/github/prawnpdf/prawn-table.png)](https://codeclimate.com/github/prawnpdf/prawn-table) ![Maintained: PRs accepted](https://img.shields.io/badge/maintained-PRs_accepted-orange.png) diff --git a/Rakefile b/Rakefile index a7d2008..8d66fd0 100644 --- a/Rakefile +++ b/Rakefile @@ -1,14 +1,11 @@ -#encoding: utf-8 +# frozen_string_literal: true -require "bundler" -Bundler.setup +GEMSPEC = File.expand_path('prawn-table.gemspec', __dir__) +require 'prawn/dev/tasks' -require 'rake' -require 'rspec/core/rake_task' require 'yard' -require 'rubygems/package_task' -task :default => [:spec] +task default: %i[spec rubocop] desc "Run all rspec files" RSpec::Core::RakeTask.new("spec") do |c| diff --git a/lib/prawn/table.rb b/lib/prawn/table.rb index 264bf7a..718fe69 100644 --- a/lib/prawn/table.rb +++ b/lib/prawn/table.rb @@ -26,6 +26,10 @@ module Errors # This error is raised when an empty or nil table is rendered # EmptyTable = Class.new(StandardError) + + # Raised when unrecognized content is provided for a table cell. + # + UnrecognizedTableContent = Class.new(StandardError) unless defined?(::Prawn::Errors::UnrecognizedTableContent) end # Next-generation table drawing for Prawn. @@ -43,8 +47,7 @@ module Errors # Prawn::Table:: # Creates a subtable (a table within a cell). You can use # Prawn::Document#make_table to create a table for use as a subtable - # without immediately drawing it. See examples/table/bill.rb for a - # somewhat complex use of subtables. + # without immediately drawing it. # Array:: # Creates a simple subtable. Create a Table object using make_table (see # above) if you need more control over the subtable's styling. @@ -99,7 +102,7 @@ module Errors # end # class Table - module Interface + module Interface # @group Experimental API # Set up and draw a table on this document. A block can be given, which will @@ -135,10 +138,13 @@ def make_table(data, options={}, &block) # above for details on available options. # def initialize(data, document, options={}, &block) + table_opts = options.dup @pdf = document - @cells = make_cells(data) + @cells = make_cells(data, table_opts.delete(:cell_style) || {}) @header = false - options.each { |k, v| send("#{k}=", v) } + table_opts.each do |k, v| + send("#{k}=", v) if respond_to?("#{k}=") + end if block block.arity < 1 ? instance_eval(&block) : block[self] @@ -291,7 +297,7 @@ def draw cells_this_page = [] @cells.each do |cell| - if start_new_page?(cell, offset, ref_bounds) + if start_new_page?(cell, offset, ref_bounds) # draw cells on the current page and then start a new one # this will also add a header to the new page if a header is set # reset array of cells for the new page @@ -381,7 +387,7 @@ def row_heights end protected - + # sets the background color (if necessary) for the given cell def set_background_color(cell, started_new_page_at_row) if defined?(@row_colors) && @row_colors && (!@header || cell.row > 0) @@ -429,9 +435,9 @@ def ink_and_draw_cells(cells_this_page, draw_cells = true) def ink_and_draw_cells_and_start_new_page(cells_this_page, cell) # don't draw only a header draw_cells = (@header_row.nil? || cells_this_page.size > @header_row.size) - + ink_and_draw_cells(cells_this_page, draw_cells) - + # start a new page or column @pdf.bounds.move_past_bottom @@ -509,7 +515,7 @@ def header_rows # Prawn::Table::Cell, and sets up their in-table properties so that they # know their own position in the table. # - def make_cells(data) + def make_cells(data, cell_style = {}) assert_proper_table_data(data) cells = Cells.new @@ -523,7 +529,11 @@ def make_cells(data) column_number += 1 until cells[row_number, column_number].nil? # Build the cell and store it in the Cells collection. - cell = Cell.make(@pdf, cell_data) + cell = if cell_data.is_a?(Hash) + Cell.make(@pdf, cell_style.merge(cell_data)) + else + Cell.make(@pdf, cell_data, cell_style) + end cells[row_number, column_number] = cell # Add dummy cells for the rest of the cells in the span group. This @@ -576,7 +586,7 @@ def add_header(row_number, cells_this_page) number_of_header_rows.times do |h| additional_header_height = add_one_header_row(cells_this_page, x_offset, y_coord-header_height, row_number-1, h) header_height += additional_header_height - end + end end header_height end @@ -593,7 +603,7 @@ def add_one_header_row(page_of_cells, x_offset, y, row, row_of_header=nil) rows_to_operate_on = @header_row.rows(row_of_header) if row_of_header rows_to_operate_on.each do |cell| cell.row = row - cell.dummy_cells.each {|c| + cell.dummy_cells.each {|c| if cell.rowspan > 1 # be sure to account for cells that span multiple rows # in this case you need multiple row numbers diff --git a/lib/prawn/table/cell.rb b/lib/prawn/table/cell.rb index 83b940f..3dbbc84 100644 --- a/lib/prawn/table/cell.rb +++ b/lib/prawn/table/cell.rb @@ -161,20 +161,16 @@ def max_width # def self.make(pdf, content, options={}) at = options.delete(:at) || [0, pdf.cursor] - content = content.to_s if content.nil? || content.kind_of?(Numeric) || - content.kind_of?(Date) + + return Cell::Image.new(pdf, at, content) if content.is_a?(Hash) && content[:image] if content.is_a?(Hash) - if content[:image] - return Cell::Image.new(pdf, at, content) - end options.update(content) content = options[:content] - else - options[:content] = content end - options[:content] = content = "" if content.nil? + content = content.to_s if stringify_content?(content) + options[:content] = content case content when Prawn::Table::Cell @@ -191,6 +187,15 @@ def self.make(pdf, content, options={}) end end + def self.stringify_content?(content) + return true if content.nil? + return true if content.kind_of?(Numeric) + return true if content.kind_of?(Date) + return true if content.kind_of?(Time) + + false + end + # A small amount added to the bounding box width to cover over floating- # point errors when round-tripping from content_width to width and back. # This does not change cell positioning; it only slightly expands each @@ -219,7 +224,7 @@ def initialize(pdf, point, options={}) @rowspan = 1 @dummy_cells = [] - options.each { |k, v| send("#{k}=", v) } + style(options) @initializer_run = true end diff --git a/manual/images/prawn.png b/manual/images/prawn.png new file mode 100644 index 0000000..4b36946 Binary files /dev/null and b/manual/images/prawn.png differ diff --git a/manual/images/stef.jpg b/manual/images/stef.jpg new file mode 100644 index 0000000..039dd89 Binary files /dev/null and b/manual/images/stef.jpg differ diff --git a/manual/table/cell_dimensions.rb b/manual/table/cell_dimensions.rb index cd47d78..e6bc6f3 100644 --- a/manual/table/cell_dimensions.rb +++ b/manual/table/cell_dimensions.rb @@ -25,6 +25,12 @@ move_down 20 end - text "Padding can also be set with an array: [0, 0, 0, 30]" - table(data, :cell_style => {:padding => [0, 0, 0, 30]}) + text "Padding can also be set with an array by specifying values for all sides: [0, 0, 0, 30]" + table(data, :cell_style => {:padding => [0, 0, 0, 30]}) # top, right, bottom, left + + text "Padding can also be set by specifying only vertical and horizontal values: [0,30]" + table(data, :cell_style => {:padding => [0, 30]}) # vertical, horizontal + + text "Padding can also be set by specifying top, horizontal and bottom values: [0,30,10]" + table(data, :cell_style => {:padding => [0, 30, 10]}) # top, horizontal, bottom end diff --git a/manual/table/content_and_subtables.rb b/manual/table/content_and_subtables.rb index ac7b233..8e99dad 100644 --- a/manual/table/content_and_subtables.rb +++ b/manual/table/content_and_subtables.rb @@ -29,7 +29,7 @@ my_table = make_table([ ["..."], ["subtable from another table"], ["..."] ]) - image_path = "#{Prawn::DATADIR}/images/stef.jpg" + image_path = File.expand_path("../images/stef.jpg", __dir__) table([ ["just a regular row", "", "", "blah blah blah"], [cell_1, cell_2, "", ""], diff --git a/manual/table/image_cells.rb b/manual/table/image_cells.rb index 474a423..1464041 100644 --- a/manual/table/image_cells.rb +++ b/manual/table/image_cells.rb @@ -17,7 +17,7 @@ filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::ManualBuilder::Example.generate(filename) do - image = "#{Prawn::DATADIR}/images/prawn.png" + image = File.expand_path("../images/prawn.png", __dir__) table [ ["Standard image cell", {:image => image}], diff --git a/manual/table/style.rb b/manual/table/style.rb index 22c8f56..9b523eb 100644 --- a/manual/table/style.rb +++ b/manual/table/style.rb @@ -7,6 +7,11 @@ # also accepts a block that will be called for each cell and can be used for # some complex styling. # +# Individual cell styles can also be applied when defining the data for the +# table using a hash syntax for the cell. This style will take precedence over +# any table level cell styles. See the "cell_text" section for a list of +# options. + require File.expand_path(File.join(File.dirname(__FILE__), %w[.. example_helper])) @@ -19,4 +24,10 @@ c.background_color = ((c.row + c.column) % 2).zero? ? '000000' : 'ffffff' end end + move_down 20 + + table( + [%w[A B], ['C', { content: 'D', text_color: 'ff0000' }]], + cell_style: { text_color: '0000ff' } + ) end diff --git a/prawn-table.gemspec b/prawn-table.gemspec index ad721c5..31b2057 100644 --- a/prawn-table.gemspec +++ b/prawn-table.gemspec @@ -10,21 +10,22 @@ Gem::Specification.new do |spec| ["prawn-table.gemspec", "Gemfile", "COPYING", "LICENSE", "GPLv2", "GPLv3"] spec.require_path = "lib" - spec.required_ruby_version = '>= 1.9.3' - spec.required_rubygems_version = ">= 1.3.6" + spec.required_ruby_version = '>= 2.6' + spec.required_rubygems_version = ">= 2.0.0" spec.test_files = Dir[ "spec/*_spec.rb" ] spec.authors = ["Gregory Brown","Brad Ediger","Daniel Nelson","Jonathan Greenberg","James Healy", "Hartwig Brandl"] spec.email = ["gregory.t.brown@gmail.com","brad@bradediger.com","dnelson@bluejade.com","greenberg@entryway.net","jimmy@deefa.com", "mail@hartwigbrandl.at"] - spec.rubyforge_project = "prawn" spec.licenses = %w(PRAWN GPL-2.0 GPL-3.0) spec.add_dependency('prawn', '>= 1.3.0', '< 3.0.0') + spec.add_development_dependency('pdf-inspector', '~> 1.1.0') spec.add_development_dependency('yard') spec.add_development_dependency('rspec', '~> 3.0') spec.add_development_dependency('rake') spec.add_development_dependency('simplecov') + spec.add_development_dependency('prawn-dev', '~> 0.3.0') spec.add_development_dependency('prawn-manual_builder', ">= 0.2.0") spec.add_development_dependency('pdf-reader', '~>1.2') diff --git a/spec/cell_spec.rb b/spec/cell_spec.rb index 4cbecff..9a5a0fa 100644 --- a/spec/cell_spec.rb +++ b/spec/cell_spec.rb @@ -36,13 +36,21 @@ def cell(options={}) end it "should convert nil, Numeric, and Date values to strings" do - [nil, 123, 123.45, Date.today].each do |value| + [nil, 123, 123.45, Date.today, Time.new].each do |value| c = @pdf.cell(:content => value) expect(c).to be_a_kind_of Prawn::Table::Cell::Text expect(c.content).to eq value.to_s end end + it "should convert nil, Numeric, and Date values to strings when value is extracted from options" do + [nil, 123, 123.45, Date.today, Time.new].each do |value| + c = Prawn::Table::Cell.make(@pdf, {}, { :content => value }) + expect(c).to be_a_kind_of Prawn::Table::Cell::Text + expect(c.content).to eq value.to_s + end + end + it "should allow inline styling with a hash argument" do # used for table([[{:text => "...", :font_style => :bold, ...}, ...]]) c = Prawn::Table::Cell.make(@pdf, @@ -399,7 +407,7 @@ def cell(options={}) expect(@pdf).to receive(:stroke_color=).with("ff00ff") c = @pdf.cell(:content => "text", - :border_color => %w[ff0000 00ff00 0000ff ff00ff]) + :border_color => %w[ff0000 00ff00 0000ff ff00ff]) expect(c.border_colors).to eq %w[ff0000 00ff00 0000ff ff00ff] end @@ -426,7 +434,7 @@ def cell(options={}) expect(@pdf).to receive(:line_width=).with(5) c = @pdf.cell(:content => "text", - :border_width => [2, 3, 4, 5]) + :border_width => [2, 3, 4, 5]) expect(c.border_widths).to eq [2, 3, 4, 5] end @@ -447,7 +455,7 @@ def cell(options={}) it "should set border lines with :border_lines" do c = @pdf.cell(:content => "text", - :border_lines => [:solid, :dotted, :dashed, :solid]) + :border_lines => [:solid, :dotted, :dashed, :solid]) expect(c.border_lines).to eq [:solid, :dotted, :dashed, :solid] end end @@ -592,7 +600,7 @@ def cell(options={}) describe "with default options" do before(:each) do @cell = Prawn::Table::Cell.make(@pdf, - :image => "#{Prawn::DATADIR}/images/prawn.png") + { :image => file_fixture("prawn.png").to_s }) end it "should create a Cell::Image" do @@ -608,7 +616,7 @@ def cell(options={}) describe "hash syntax" do before(:each) do @table = @pdf.make_table([[{ - :image => "#{Prawn::DATADIR}/images/prawn.png", + :image => file_fixture("prawn.png").to_s, :scale => 2, :fit => [100, 200], :image_width => 123, diff --git a/spec/extensions/file_fixture_helper.rb b/spec/extensions/file_fixture_helper.rb new file mode 100644 index 0000000..6d0c320 --- /dev/null +++ b/spec/extensions/file_fixture_helper.rb @@ -0,0 +1,15 @@ +require 'pathname' + +module FileFixtureHelper + FIXTURES_PATH = Pathname.new(File.expand_path("../fixtures", __dir__)).freeze + FILE_FIXTURES_PATH = FIXTURES_PATH.join("files").freeze + + def file_fixture(relative_path) + pathname = FILE_FIXTURES_PATH.join(relative_path) + + raise ArgumentError, "File '#{pathname}' not found" unless pathname.file? + + pathname + end +end + diff --git a/spec/fixtures/files/prawn.png b/spec/fixtures/files/prawn.png new file mode 100644 index 0000000..4b36946 Binary files /dev/null and b/spec/fixtures/files/prawn.png differ diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8b2c1c2..155df8e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -26,6 +26,7 @@ RSpec.configure do |config| config.include EncodingHelpers + config.include FileFixtureHelper end def create_pdf(klass=Prawn::Document) diff --git a/spec/table_spec.rb b/spec/table_spec.rb index c293454..cd5beac 100644 --- a/spec/table_spec.rb +++ b/spec/table_spec.rb @@ -943,13 +943,15 @@ " block" do stylable = double - expect(stylable).to receive(:style).with(:foo => :bar).once.and_yield + expect(stylable).to receive(:style).with({:foo => :bar}).once.and_yield block = double expect(block).to receive(:kick).once Prawn::Document.new do - table([["x"]]) { style(stylable, :foo => :bar) { block.kick } } + table([["x"]]) do + style(stylable, {:foo => :bar}) { block.kick } + end end end @@ -980,8 +982,9 @@ it "should ignore headers" do data = [["header"], ["foo"], ["bar"], ["baz"]] pdf = Prawn::Document.new - t = pdf.table(data, :header => true, - :row_colors => ['cccccc', 'ffffff']) do + t = pdf.table(data, + { :header => true, + :row_colors => ['cccccc', 'ffffff']}) do row(0).background_color = '333333' end @@ -991,8 +994,9 @@ it "stripes rows consistently from page to page, skipping header rows" do data = [["header"]] + [["foo"]] * 70 pdf = Prawn::Document.new - t = pdf.make_table(data, :header => true, - :row_colors => ['cccccc', 'ffffff']) do + t = pdf.make_table(data, + { :header => true, + :row_colors => ['cccccc', 'ffffff']}) do cells.padding = 0 cells.size = 9 row(0).size = 11 @@ -1609,4 +1613,14 @@ pdf.render expect(pdf.page_count).to eq 1 end + + it 'illustrates issue #56 cell style should not be overwritten by table style', issue: 56 do + t = @pdf.table([['col1', 'col2'], + ['val1', { content: 'val2', align: :left }]], + cell_style: { align: :center }) + expect(t.cells[0, 0].align).to eq :center + expect(t.cells[0, 1].align).to eq :center + expect(t.cells[1, 0].align).to eq :center + expect(t.cells[1, 1].align).to eq :left + end end