From b8fdcc2be2fcae1bfd3dd62b8bc2d4abe75e78d0 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Tue, 13 Aug 2024 07:35:12 +0700 Subject: all: rename struct "AttributeEntry" to "DocumentAttribute" This is to make the struct is clear that it represent the document attribute. --- attribute_entry.go | 33 --------------------------------- document.go | 4 ++-- document_attribute.go | 33 +++++++++++++++++++++++++++++++++ parser_test.go | 10 +++++----- 4 files changed, 40 insertions(+), 40 deletions(-) delete mode 100644 attribute_entry.go create mode 100644 document_attribute.go diff --git a/attribute_entry.go b/attribute_entry.go deleted file mode 100644 index 98db699..0000000 --- a/attribute_entry.go +++ /dev/null @@ -1,33 +0,0 @@ -// SPDX-FileCopyrightText: 2020 M. Shulhan -// SPDX-License-Identifier: GPL-3.0-or-later - -package asciidoctor - -import "strings" - -// AttributeEntry contains the mapping of global attribute keys in the headers -// with its value. -type AttributeEntry map[string]string - -func newAttributeEntry() AttributeEntry { - return AttributeEntry{ - MetaNameGenerator: `asciidoctor-go ` + Version, - metaNameLastUpdateLabel: `Last updated`, - metaNameLastUpdateValue: ``, - metaNameSectIDs: ``, - metaNameShowTitle: ``, - metaNameTableCaption: ``, - metaNameVersionLabel: ``, - } -} - -func (entry *AttributeEntry) apply(key, val string) { - switch { - case key[0] == '!': - delete(*entry, strings.TrimSpace(key[1:])) - case key[len(key)-1] == '!': - delete(*entry, strings.TrimSpace(key[:len(key)-1])) - default: - (*entry)[key] = val - } -} diff --git a/document.go b/document.go index 47d2c85..50be70f 100644 --- a/document.go +++ b/document.go @@ -31,7 +31,7 @@ type Document struct { preamble *element content *element - Attributes AttributeEntry + Attributes DocumentAttribute sectnums *sectionCounters // titleID is the reverse of anchors, it contains mapping of title and @@ -76,7 +76,7 @@ func newDocument() (doc *Document) { TOCLevel: defTOCLevel, tocClasses: attributeClass{}, tocTitle: defTOCTitle, - Attributes: newAttributeEntry(), + Attributes: newDocumentAttribute(), classes: attributeClass{}, anchors: make(map[string]*anchor), titleID: make(map[string]string), diff --git a/document_attribute.go b/document_attribute.go new file mode 100644 index 0000000..c7b2c83 --- /dev/null +++ b/document_attribute.go @@ -0,0 +1,33 @@ +// SPDX-FileCopyrightText: 2020 M. Shulhan +// SPDX-License-Identifier: GPL-3.0-or-later + +package asciidoctor + +import "strings" + +// DocumentAttribute contains the mapping of global attribute keys in the +// headers with its value. +type DocumentAttribute map[string]string + +func newDocumentAttribute() DocumentAttribute { + return DocumentAttribute{ + MetaNameGenerator: `asciidoctor-go ` + Version, + metaNameLastUpdateLabel: `Last updated`, + metaNameLastUpdateValue: ``, + metaNameSectIDs: ``, + metaNameShowTitle: ``, + metaNameTableCaption: ``, + metaNameVersionLabel: ``, + } +} + +func (entry *DocumentAttribute) apply(key, val string) { + switch { + case key[0] == '!': + delete(*entry, strings.TrimSpace(key[1:])) + case key[len(key)-1] == '!': + delete(*entry, strings.TrimSpace(key[:len(key)-1])) + default: + (*entry)[key] = val + } +} diff --git a/parser_test.go b/parser_test.go index ffa055f..21e20f6 100644 --- a/parser_test.go +++ b/parser_test.go @@ -19,7 +19,7 @@ func TestGenerateID(t *testing.T) { var cases = []testCase{{ desc: `Without idprefix and idseparator`, doc: &Document{ - Attributes: AttributeEntry{}, + Attributes: DocumentAttribute{}, }, inputExp: map[string]string{ `a b c`: `a_b_c`, @@ -28,7 +28,7 @@ func TestGenerateID(t *testing.T) { }, { desc: `With idprefix`, doc: &Document{ - Attributes: AttributeEntry{ + Attributes: DocumentAttribute{ metaNameIDPrefix: `123`, }, }, @@ -39,7 +39,7 @@ func TestGenerateID(t *testing.T) { }, { desc: `With empty idseparator`, doc: &Document{ - Attributes: AttributeEntry{ + Attributes: DocumentAttribute{ metaNameIDSeparator: ``, }, }, @@ -50,7 +50,7 @@ func TestGenerateID(t *testing.T) { }, { desc: `With idseparator`, doc: &Document{ - Attributes: AttributeEntry{ + Attributes: DocumentAttribute{ metaNameIDSeparator: `-`, }, }, @@ -61,7 +61,7 @@ func TestGenerateID(t *testing.T) { }, { desc: `With idprefix and idseparator`, doc: &Document{ - Attributes: AttributeEntry{ + Attributes: DocumentAttribute{ metaNameIDPrefix: `id_`, metaNameIDSeparator: `-`, }, -- cgit v1.3