-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocument.go
More file actions
64 lines (50 loc) · 1.36 KB
/
document.go
File metadata and controls
64 lines (50 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"path/filepath"
"strings"
bitbucket "github.com/PremiereGlobal/mkdocs-generator/bitbucket"
)
// docType specifies a type of a single document
type docType int
// Possible values of docType
const (
markdownType docType = iota
imageType
)
// document contains information about a single document
type document struct {
// uid is the unique identifier for this document
// this is constructed as follows
// strings.ToLower(<project>/<repo>/<filepath>)
uid string
// docType describes the type of document (markdown, image, etc.)
docType docType
project string
repo string
filePath string
bbfile bitbucket.BBFile
}
// NewDocument generates a new document object from its components
func NewDocument(project string, repo string, filePath string, bbfile bitbucket.BBFile) *document {
document := document{
project: strings.ToUpper(project),
repo: repo,
filePath: filePath,
bbfile: bbfile,
}
document.uidGen()
return &document
}
func (d *document) getBBFile() bitbucket.BBFile {
return d.bbfile
}
func (d *document) uidGen() {
slug := filepath.Join(d.project, d.repo, d.filePath)
d.uid = strings.ToLower(slug)
}
func (d *document) scmRepoPath() string {
return filepath.Join("projects", d.project, "repos", d.repo)
}
func (d *document) scmFilePath() string {
return filepath.Join(d.scmRepoPath(), "raw", d.filePath)
}