prawn-disable_word_break 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b8364a4f45b68738bbc7312b486e8ed741885232bd7a17c96ce71309186e30df
4
- data.tar.gz: e5394bb7d4f2a39365a8bca5a8cbdbf37027ef024e340a9aa6aed0bd69eca84f
3
+ metadata.gz: bba3067f6b8890dfb47cf0e4495b033ce771971a0800f0873ed2f1edaf872a0e
4
+ data.tar.gz: a6e5cf2ef7f57d66b4f3edd8ebb3ffa73b1078ba3a0dc429ea3f7327d0f68fe2
5
5
  SHA512:
6
- metadata.gz: 2427b82f590702adba462958e0cff8ea203d382100fea7d281a8efc4826b0a8ad169146a367674f9e0a91a5f288494937e4c94156830a3d3ac769d99fc17241e
7
- data.tar.gz: a3bb8bf3b97ecf0588b71d6690e6e04415bbe5f233771b3fb2a0c4a4fdd62066ade574e0949fc2ec68095c40928cdd2d421625dd4ac96f52b3d82bd48ec2ea70
6
+ metadata.gz: ca2b9e2759bbf4ae1b1cf2ee18e60434c444f60bdd4104a22659e414859738034958a1c3181d1cb0e244da4154501bf6bf55b2ab8da0bb198e625df3871c42de
7
+ data.tar.gz: 10ca0137d172f48cbab43e01992cce09d2d571a30bcb1554fc744cc7785b98e2cb004e524dd36648dcf4c76dde223cc3ab2f47533fcc093de0a28037e5ec709e
@@ -4,30 +4,37 @@ on: [push, pull_request]
4
4
 
5
5
  jobs:
6
6
  test:
7
- name: Test on ruby ${{ matrix.ruby_version }}
7
+ name: Test on ruby ${{ matrix.ruby_version }} and ${{ matrix.prawn_version }}
8
8
  runs-on: ubuntu-latest
9
9
  strategy:
10
10
  matrix:
11
11
  ruby_version:
12
- - 2.4.x
13
- - 2.5.x
14
- - 2.6.x
15
- - 2.7.x
12
+ - 2.6
13
+ - 2.7
14
+ - 3.0
15
+ prawn_version:
16
+ - 2.3
17
+ - 2.4
18
+ exclude:
19
+ - ruby_version: 3.0
20
+ prawn_version: 2.3
21
+
16
22
  steps:
17
23
  - uses: actions/checkout@v1
18
- - name: Set up diff-pdf
19
- run: |
20
- sudo apt-get update
21
- sudo apt-get install make automake g++ libpoppler-glib-dev poppler-utils libwxgtk3.0-dev
22
- git clone https://github.com/vslavik/diff-pdf.git -b v0.3 --depth 1 /tmp/diff-pdf-src
23
- cd /tmp/diff-pdf-src
24
- ./bootstrap && ./configure && make && sudo make install
24
+
25
+ - uses: hidakatsuya/setup-diff-pdf@v1
26
+ with:
27
+ diff-pdf-version: 0.5
28
+
25
29
  - name: Set up Ruby ${{ matrix.ruby_version }}
26
- uses: actions/setup-ruby@v1
30
+ uses: ruby/setup-ruby@v1
27
31
  with:
28
32
  ruby-version: ${{ matrix.ruby_version }}
29
- - name: Build and test with Rake
33
+
34
+ - name: Install dependencies
30
35
  run: |
31
36
  gem install bundler
32
- bundle install --jobs 4 --retry 3
33
- bundle exec rake test
37
+ bundle install --gemfile test/gemfiles/prawn-${{ matrix.prawn_version }}.gemfile --jobs 4 --retry 3
38
+
39
+ - name: Run tests
40
+ run: bundle exec rake test
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ ## Main (Unreleased)
2
+
3
+ ## 2.0.0
4
+
5
+ ### Breaking Changes
6
+
7
+ - Disable word break globally when required
8
+ - Removed `#disable_word_break` and `#word_break`
9
+ - Drop ruby 2.4, 2.5 support
10
+ - Drop prawn 2.2 support
data/Dockerfile CHANGED
@@ -6,7 +6,7 @@ RUN apt-get update -qq && apt-get install -y build-essential xvfb
6
6
  WORKDIR /tmp
7
7
  RUN apt-get install -y libpoppler-glib-dev poppler-utils libwxgtk3.0-dev && curl -L https://github.com/vslavik/diff-pdf/archive/master.tar.gz -o diff-pdf-master.tar.gz && tar zxf diff-pdf-master.tar.gz && cd diff-pdf-master && ./bootstrap && ./configure && make && make install
8
8
 
9
- RUN mkdir /prawn-disable_word_break
9
+ RUN mkdir /src
10
10
 
11
- WORKDIR /prawn-disable_word_break
12
- VOLUME /prawn-disable_word_break
11
+ WORKDIR /src
12
+ VOLUME /src
data/Gemfile CHANGED
@@ -1,7 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
-
5
- gem 'rake', '>= 0'
6
- gem 'test-unit', '>= 3.3.5'
7
- gem 'test-unit-rr', '>= 1.0.5'
data/README.md CHANGED
@@ -1,10 +1,11 @@
1
1
  # Prawn::DisableWordBreak
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/prawn-disable_word_break.svg)](https://badge.fury.io/rb/prawn-disable_word_break)
3
4
  [![Test](https://github.com/hidakatsuya/prawn-disable_word_break/workflows/Test/badge.svg?branch=master)](https://github.com/hidakatsuya/prawn-disable_word_break/actions)
4
5
 
5
- Prawn::DisableWordBreak is an extension that adds a method to disable word-breaking by character such as space and hyphen to [Prawn](https://github.com/prawnpdf/prawn).
6
+ Prawn::DisableWordBreak is an extension that disables word-breaking by character such as space and hyphen to [Prawn](https://github.com/prawnpdf/prawn).
6
7
 
7
- ![](doc/comparison-of-word-breaking.png)
8
+ ![](https://raw.githubusercontent.com/hidakatsuya/prawn-disable_word_break/master/doc/comparison-of-word-breaking.png)
8
9
 
9
10
  See [feature test](test/features/text_line_wrapping_test.rb) for details.
10
11
 
@@ -13,7 +14,7 @@ See [feature test](test/features/text_line_wrapping_test.rb) for details.
13
14
  Add this line to your application's Gemfile:
14
15
 
15
16
  ```ruby
16
- gem 'prawn-disable_word_break'
17
+ gem 'prawn-disable_word_break', require: false
17
18
  ```
18
19
 
19
20
  And then execute:
@@ -28,37 +29,17 @@ Or install it yourself as:
28
29
 
29
30
  ```ruby
30
31
  require 'prawn/disable_word_break'
31
-
32
- Prawn::Document.generate 'foo.pdf' do
33
- disable_word_break do
34
- # word-breaking is disabled here
35
- text_box 'text without word-breaking', at: [100, 100], width: 50, height: 50
36
- end
37
-
38
- word_break(true) do
39
- # word-breaking is disabled here
40
- formatted_box [{ text: 'text without word-breaking' }], at: [100, 100], width: 50, height: 50
41
- end
42
-
43
- word_break(false) do
44
- # word-breaking is disabled here
45
- text_box 'text without word-breaking', at: [100, 100], width: 50, height: 50
46
- end
47
-
48
- # word-breaking is enabled here
49
- formatted_box [{ text: 'text with word-breaking' }], at: [100, 100], width: 50, height: 50
50
- end
51
32
  ```
52
33
 
53
34
  ## Supported Versions
54
35
 
55
36
  ### Ruby
56
37
 
57
- 2.6, 2.7
38
+ 2.6, 2.7, 3.0
58
39
 
59
40
  ### Prawn
60
41
 
61
- 2.2+
42
+ 2.3+
62
43
 
63
44
  ## Development
64
45
 
@@ -66,25 +47,16 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
66
47
 
67
48
  ### Testing
68
49
 
69
- This project has two test types, each of which can be run with the following command:
70
-
71
- $ bundle exec rake test:units
72
- $ bundle exec rake test:features
73
-
74
- Or, both tests can be run below:
75
-
76
50
  $ bundle exec rake test
77
51
 
78
- To run `test:features`, you need [diff-pdf](https://github.com/vslavik/diff-pdf). You can run by installing it or using a Docker container for testing.
79
-
80
- Here's how to run `test:features` in the Docker container:
52
+ To run the test, you need [diff-pdf](https://github.com/vslavik/diff-pdf). You can run by installing it or using a Docker container for testing.
81
53
 
82
- $ docker build -t prawn-disable_word_break-dev .
83
- $ docker run -v $PWD:/prawn-disable_word_break:cached -it prawn-disable_word_break-dev bash
54
+ $ docker build -t prawn-disable_word_break:latest .
55
+ $ docker run -v $PWD:/src:cached -it prawn-disable_word_break bash
84
56
 
85
- > /prawn-disable_word_break#
86
- > /prawn-disable_word_break# bundle install
87
- > /prawn-disable_word_break# bundle exec rake test:features
57
+ > /src#
58
+ > /src# bundle install
59
+ > /src# bundle exec rake test
88
60
 
89
61
  ## Contributing
90
62
 
data/Rakefile CHANGED
@@ -1,16 +1,10 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'rake/testtask'
3
3
 
4
- Rake::TestTask.new('test:units') do |t|
5
- t.libs << 'test'
6
- t.libs << 'lib'
7
- t.test_files = FileList['test/units/**/*_test.rb']
8
- end
9
-
10
4
  Rake::TestTask.new('test:features') do |t|
11
5
  t.libs << 'test'
12
6
  t.libs << 'lib'
13
7
  t.test_files = FileList['test/features/**/*_test.rb']
14
8
  end
15
9
 
16
- task test: %i( test:units test:features )
10
+ task test: %i( test:features )
@@ -1,12 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'prawn'
2
4
 
3
5
  require_relative 'disable_word_break/version'
4
- require_relative 'disable_word_break/disabler'
5
- require_relative 'disable_word_break/formatted_box'
6
+ require_relative 'disable_word_break/wrap'
6
7
 
7
- Prawn::DisableWordBreak::Disabler.tap { |mod|
8
- Prawn::Document.include mod unless Prawn::Document.include?(mod)
9
- }
10
- Prawn::DisableWordBreak::FormattedBox.tap { |mod|
11
- Prawn::Text::Formatted::Box.prepend mod unless Prawn::Text::Formatted::Box.include?(mod)
12
- }
8
+ Prawn::Text::Box.extensions << Prawn::DisableWordBreak::Wrap
9
+ Prawn::Text::Formatted::Box.extensions << Prawn::DisableWordBreak::Wrap
@@ -5,28 +5,11 @@ module Prawn
5
5
  class LineWrap < Text::Formatted::LineWrap
6
6
  private
7
7
 
8
- attr_reader :word_break_disabled
9
-
10
- # Override
11
- def initialize_line(options)
12
- super
13
- @word_break_disabled = @document.word_break_disabled?
14
- end
15
-
16
8
  # Override
17
9
  def add_fragment_to_line(fragment)
18
- if fragment == ''
19
- true
20
- elsif fragment == "\n"
21
- @newline_encountered = true
22
- false
23
- else
24
- if word_break_disabled
25
- insert_fragment_without_word_break(fragment)
26
- else
27
- insert_fragment_with_word_break(fragment)
28
- end
29
- end
10
+ return super(fragment) if fragment == '' || fragment == "\n"
11
+
12
+ insert_fragment_without_word_break(fragment)
30
13
  end
31
14
 
32
15
  def insert_fragment_without_word_break(fragment)
@@ -45,36 +28,6 @@ module Prawn
45
28
  end
46
29
  end
47
30
 
48
- def insert_fragment_with_word_break(fragment)
49
- tokenize(fragment).each do |segment|
50
- segment_width = if segment == zero_width_space(segment.encoding)
51
- 0
52
- else
53
- @document.width_of(segment, kerning: @kerning)
54
- end
55
-
56
- if @accumulated_width + segment_width <= @width
57
- @accumulated_width += segment_width
58
- shy = soft_hyphen(segment.encoding)
59
- if segment[-1] == shy
60
- sh_width = @document.width_of(shy, kerning: @kerning)
61
- @accumulated_width -= sh_width
62
- end
63
- @fragment_output += segment
64
- else
65
- if @accumulated_width.zero? && @line_contains_more_than_one_word
66
- @line_contains_more_than_one_word = false
67
- end
68
- end_of_the_line_reached(segment)
69
- fragment_finished(fragment)
70
- return false
71
- end
72
- end
73
-
74
- fragment_finished(fragment)
75
- true
76
- end
77
-
78
31
  def delete_invisible_chars(fragment)
79
32
  encoding = fragment.encoding
80
33
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Prawn
4
4
  module DisableWordBreak
5
- VERSION = '1.0.0'
5
+ VERSION = '2.0.0'
6
6
  end
7
7
  end
@@ -4,10 +4,11 @@ require_relative 'line_wrap'
4
4
 
5
5
  module Prawn
6
6
  module DisableWordBreak
7
- module FormattedBox
8
- def initialize(*)
9
- super
7
+ module Wrap
8
+ # override
9
+ def wrap(*)
10
10
  @line_wrap = DisableWordBreak::LineWrap.new
11
+ super
11
12
  end
12
13
  end
13
14
  end
@@ -6,16 +6,20 @@ Gem::Specification.new do |spec|
6
6
  spec.authors = ['Katsuya Hidaka']
7
7
  spec.email = ['hidakatsuya@gmail.com']
8
8
 
9
- spec.summary = 'Adds a method to disable word-breaking by character such as space and hyphen'
10
- spec.description = 'Prawn::DisableWordBreak is an extension for Prawn that adds a method to disable word-breaking by character such as space and hyphen to Prawn'
9
+ spec.summary = 'Disables word-breaking by character such as space and hyphen'
10
+ spec.description = 'Prawn::DisableWordBreak is an extension for Prawn that disables word-breaking by character such as space and hyphen.'
11
11
  spec.homepage = 'https://github.com/hidakatsuya/prawn-disable_word_break'
12
12
  spec.license = 'MIT'
13
- spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
14
14
 
15
15
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
16
16
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^test/}) }
17
17
  end
18
18
  spec.require_paths = ['lib']
19
19
 
20
- spec.add_dependency 'prawn', '~> 2.2'
20
+ spec.add_dependency 'prawn', '~> 2.3'
21
+ spec.add_development_dependency 'rake', '>= 0'
22
+ spec.add_development_dependency 'test-unit', '>= 3.3.5'
23
+ spec.add_development_dependency 'test-unit-rr', '>= 1.0.5'
24
+ spec.add_development_dependency 'pdf_matcher-testing', '>= 1.0.0'
21
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawn-disable_word_break
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katsuya Hidaka
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-11 00:00:00.000000000 Z
11
+ date: 2021-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn
@@ -16,25 +16,81 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.2'
19
+ version: '2.3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.2'
27
- description: Prawn::DisableWordBreak is an extension for Prawn that adds a method
28
- to disable word-breaking by character such as space and hyphen to Prawn
26
+ version: '2.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 3.3.5
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 3.3.5
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit-rr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.5
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 1.0.5
69
+ - !ruby/object:Gem::Dependency
70
+ name: pdf_matcher-testing
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.0.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.0.0
83
+ description: Prawn::DisableWordBreak is an extension for Prawn that disables word-breaking
84
+ by character such as space and hyphen.
29
85
  email:
30
86
  - hidakatsuya@gmail.com
31
87
  executables: []
32
88
  extensions: []
33
89
  extra_rdoc_files: []
34
90
  files:
35
- - ".github/FUNDING.yml"
36
91
  - ".github/workflows/test.yml"
37
92
  - ".gitignore"
93
+ - CHANGELOG.md
38
94
  - CODE_OF_CONDUCT.md
39
95
  - Dockerfile
40
96
  - Gemfile
@@ -43,16 +99,15 @@ files:
43
99
  - Rakefile
44
100
  - doc/comparison-of-word-breaking.png
45
101
  - lib/prawn/disable_word_break.rb
46
- - lib/prawn/disable_word_break/disabler.rb
47
- - lib/prawn/disable_word_break/formatted_box.rb
48
102
  - lib/prawn/disable_word_break/line_wrap.rb
49
103
  - lib/prawn/disable_word_break/version.rb
104
+ - lib/prawn/disable_word_break/wrap.rb
50
105
  - prawn-disable_word_break.gemspec
51
106
  homepage: https://github.com/hidakatsuya/prawn-disable_word_break
52
107
  licenses:
53
108
  - MIT
54
109
  metadata: {}
55
- post_install_message:
110
+ post_install_message:
56
111
  rdoc_options: []
57
112
  require_paths:
58
113
  - lib
@@ -60,15 +115,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
60
115
  requirements:
61
116
  - - ">="
62
117
  - !ruby/object:Gem::Version
63
- version: 2.4.0
118
+ version: 2.6.0
64
119
  required_rubygems_version: !ruby/object:Gem::Requirement
65
120
  requirements:
66
121
  - - ">="
67
122
  - !ruby/object:Gem::Version
68
123
  version: '0'
69
124
  requirements: []
70
- rubygems_version: 3.1.2
71
- signing_key:
125
+ rubygems_version: 3.2.15
126
+ signing_key:
72
127
  specification_version: 4
73
- summary: Adds a method to disable word-breaking by character such as space and hyphen
128
+ summary: Disables word-breaking by character such as space and hyphen
74
129
  test_files: []
data/.github/FUNDING.yml DELETED
@@ -1,3 +0,0 @@
1
- # These are supported funding model platforms
2
-
3
- github: [hidakatsuya]
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Prawn
4
- module DisableWordBreak
5
- module Disabler
6
- def word_break(disable, &block)
7
- if disable
8
- disable_word_break(&block)
9
- else
10
- block.call
11
- end
12
- end
13
-
14
- def disable_word_break
15
- @word_break_disabled = true
16
- yield
17
- ensure
18
- @word_break_disabled = false
19
- end
20
-
21
- def word_break_disabled?
22
- defined?(@word_break_disabled) ? @word_break_disabled : false
23
- end
24
- end
25
- end
26
- end