Skip to content

Commit

Permalink
again, more tests plus some fixes on website
Browse files Browse the repository at this point in the history
  • Loading branch information
gernotstarke committed Jan 4, 2025
1 parent eddf2e6 commit 75789cb
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ docs/_site
go-app/build
*.bkp
*.dtmp
go-app/coverage.html
41 changes: 27 additions & 14 deletions docs/_pages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ excerpt: "**For all those who like handouts with page numbers and running header
PDFminion adds page numbers and running-headers on pdf documents, helping to produce useful handouts.
<br>
It's open-source, runs on all major platforms and is free to use.
<br>
<br>
<p>Brought to you by</p>
<div class="logo">
<a href="https://arc42.org/" target="_blank" rel="noopener noreferrer nofollow">
<img src="assets/images/arc42-logo.png" alt="arc42">
</a>
</a>
</div>

</p>
Expand Down Expand Up @@ -69,7 +69,7 @@ excerpt: "**For all those who like handouts with page numbers and running header
<h5>Add Personal Touch</h5>
<p>Who said PDF documents couldn't have a personal touch? Thanx to <a href="https://www.sketchnotes.tech/">Lisa, @teapot418</a>.</p>
</div>

<div class="box box--primary box-third">
<img src="assets/images/functions/chapter-number.png" alt="chapter numbers" class="img-half">
<h5>Chapter Number</h5>
Expand Down Expand Up @@ -119,8 +119,8 @@ excerpt: "**For all those who like handouts with page numbers and running header
<section id="installation" markdown="1">

<h1>Installation</h1>
PDFminion runs on all major (desktop) operating systems.

PDFminion runs on all major (desktop) operating systems.
You can download an appropriate version and install it yourself, or you can use one of our installation options.

If you're nerdy enough, you can [fork the repo](https://github.com/arc42/pdfminion), and build your own executable version, either with `make` or `go build`.
Expand Down Expand Up @@ -174,7 +174,7 @@ To evenify a file means adding a blank page at the end of the file if the page-c
That means that the first page of every file in a group will always start on the front-page of paper,
even in case of double-sided printing.

Chapters in technical or scientific books traditionally start on odd (right-hand) pages to ensure consistency,
Chapters in technical or scientific books traditionally start on odd (right-hand) pages to ensure consistency,
readability, and prominence, aligning with classic book design practices.


Expand Down Expand Up @@ -219,9 +219,9 @@ If no command is given, all flags are evaluate, validated and PDF processing is
|-----------|-------------------|-------------------|--------------------|
| **Source Directory** | `--source <directory>` | `-s <directory>`| Specifies the input directory for PDF files. Default is `./_pdfs` Example: `pdfminion --source ./input`|
| **Target Directory** | `--target <directory>` | `-t <directory>` | Specifies the output directory for processed files. Default is `_target`. Creates the directory if it doesn’t exist. Example: `pdfminion --target ./out`|
| **Force Overwrite** | `--force` | `-f` | Allows overwriting existing files in the target directory. Example: `pdfminion --force` |
| **Force Overwrite** | `--force` | `-f` | Allows overwriting existing files in the target directory. Default: `false`. Example: `pdfminion --force` |
| **Config File** | `--config <filename>` | `-c <filename>` | Loads configuration from a file. It needs to be a yaml file. Example: `pdfminion --config settings.yaml` |
| **Verbose Mode** | `--verbose` | | Gives detailed processing output. Example: `pdfminion --verbose` |
| **Verbose Mode** | `--verbose` | | Gives detailed processing output. Default: `false`. Example: `pdfminion --verbose` |


<h2>Page Related Settings</h2>
Expand All @@ -240,7 +240,8 @@ Set the running head, the page- and chapter prefix etc.

Please note: Most of these processing defaults are language-specific: The German language, for example, uses "Seite" for "Page" and "Kapitel" for "Chapter".


If you set a language (e.g German, DE), then the defaults of that language will be used.
You can still override some (or all) of these settings, though (see [example 6](#examples)).


<h2>Multi-Language Support</h2>
Expand Down Expand Up @@ -292,9 +293,9 @@ After all files have been processed, PDFminion can perform some post-processing.
>`$ pdfminion --force --source ./input --target ./output`
>
> **Example 3**: Show all default settings for current language setting
> **Example 3**: Show all current configuration items
>
>`$ pdfminion defaults`
>`$ pdfminion settings`
>
<hr>
Expand All @@ -304,11 +305,23 @@ After all files have been processed, PDFminion can perform some post-processing.
>
<hr>
> **Example 5**: List available languages for the `--language` flag
>
>`$ pdfminion ll`
>`$ pdfminion list-languages`
>
<hr>
> **Example 6**: Set a language with the `--language` flag and override one of the defaults
>
>`$ pdfminion --language=EN --page-prefix=pg.`
>
<hr>
> **Example 41**: Gives credit to the maintainers of the open-source libraries used by PDFminion, e.g. [pdfcpu](https://pdfcpu.io/) and a few others..
```shell
$ pdfminion --thanx
>
>`$ pdfminion thanx`
>
PDFminion was created on the shoulder of giants...
```
Expand Down
21 changes: 18 additions & 3 deletions go-app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ INSTALL_DIR=/usr/local/bin
.PHONY: default all clean test compile-all run install uninstall release mac \
compile-windows-amd64 compile-linux-amd64 compile-darwin-amd64 compile-darwin-arm64 \
package-windows-amd64 package-linux-amd64 package-darwin-amd64 package-darwin-arm64 \
docker-test-linux lint
docker-test-linux lint count install-gotestsum cover


# Directory targets
Expand Down Expand Up @@ -142,8 +142,23 @@ release: package-windows-amd64 package-linux-amd64 package-darwin-amd64 package-
@echo "All platform builds completed!"
@ls -l $(DIST_DIR)

test:
$(GOTEST) -v ./...

# Add new targets (near the test target):
install-gotestsum:
go install gotest.tools/gotestsum@latest

test: install-gotestsum
gotestsum --format=testdox ./...

count:
cloc --exclude-dir=vendor,dist,build .

# Target to calculate coverage for all packages
cover:
@echo "Calculating test coverage for all packages..."
@go test -coverprofile=coverage.out ./...
@echo "Package coverage summary:"
@go tool cover -func=coverage.out | tail -n1 | sed 's/\s\+/ /g' | sed 's/%%/%/'

# Test binaries in containers
docker-test-linux: compile-linux-amd64
Expand Down
9 changes: 4 additions & 5 deletions go-app/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import (
)

var (
defaultConfig *domain.MinionConfig
homeDirFileConfig *domain.MinionConfig
localDirFileConfig *domain.MinionConfig
flagConfig *domain.MinionConfig
minionConfig *domain.MinionConfig
// homeDirFileConfig *domain.MinionConfig
// localDirFileConfig *domain.MinionConfig
// flagConfig *domain.MinionConfig
minionConfig *domain.MinionConfig
)

// LoadConfig collects configuration from all sources and merges them
Expand Down
2 changes: 1 addition & 1 deletion go-app/internal/domain/language.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (
BlankPageText: "Diese Seite bleibt absichtlich leer",
},
language.English: {
RunningHeader: "",
RunningHeader: DefaultRunningHeader,
ChapterPrefix: DefaultChapterPrefix,
PageCountPrefix: "of",
PageNumber: DefaultPageNrPrefix,
Expand Down
12 changes: 8 additions & 4 deletions go-app/internal/domain/minionTypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ const (
DefaultSeparator = " - "
DefaultPageCountPrefix = "of"
DefaultBlankPageText = "Intentionally left blank"
DefaultForce = false
DefaultEvenify = true
DefaultMerge = false
DefaultMergeFileName = "merged.pdf"
DefaultPersonalTouch = false
)

// MinionConfig holds the configuration for the PDFMinion application
Expand Down Expand Up @@ -78,9 +82,9 @@ func NewDefaultConfig(systemLanguage language.Tag) *MinionConfig {
Verbose: false,
SourceDir: DefaultSourceDir,
TargetDir: DefaultTargetDir,
Force: false,
Evenify: true,
Merge: false,
Force: DefaultForce,
Evenify: DefaultEvenify,
Merge: DefaultMerge,
MergeFileName: DefaultMergeFileName,

ConfigFileName: MinionConfigFileName,
Expand All @@ -93,7 +97,7 @@ func NewDefaultConfig(systemLanguage language.Tag) *MinionConfig {
BlankPageText: texts.BlankPageText,
Separator: DefaultSeparator,

PersonalTouch: false,
PersonalTouch: DefaultPersonalTouch,
SetFields: make(map[string]bool),
}
}
Expand Down
19 changes: 15 additions & 4 deletions go-app/internal/domain/minionTypes_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package domain

import (
"fmt"
"github.com/stretchr/testify/assert"
"golang.org/x/text/language"
"testing"
Expand Down Expand Up @@ -132,9 +131,7 @@ func TestDefaultConfigMergeWithFlagGermanAndOverrideBlankPageText(t *testing.T)

// can merge without error
assert.NoError(t, base.MergeWith(germanWithOverride), "MergeWith should not return an error")

fmt.Printf(base.BlankPageText)


// the overridden values should be set to the new values
assert.Equal(t, newBlankPageText, base.BlankPageText)

Expand Down Expand Up @@ -228,6 +225,20 @@ func TestDefaultCanOverrideBlankPageText(t *testing.T) {
assert.Equal(t, newBlankPageText, defaultConfig.BlankPageText)
}

func TestDefaultCanOverrideSeparator(t *testing.T) {
const newSeparator = "/"
defaultConfig := NewDefaultConfig(language.English)
assert.Equal(t, DefaultSeparator, defaultConfig.Separator)
assert.NotEqual(t, DefaultSeparator, newSeparator)

other := &MinionConfig{
Separator: newSeparator,
}

assert.NoError(t, defaultConfig.MergeWith(other), "MergeWith should not return an error")
assert.Equal(t, newSeparator, defaultConfig.Separator)
}

func TestMinionConfig_MergeWithMinimal(t *testing.T) {
minimalBaseConfig := &MinionConfig{SourceDir: "/original/source"}
other := &MinionConfig{
Expand Down

0 comments on commit 75789cb

Please sign in to comment.