-
Notifications
You must be signed in to change notification settings - Fork 75
/
conversionmodel.go
53 lines (41 loc) · 1.31 KB
/
conversionmodel.go
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
// Copyright 2014 Andreas Koch. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package orchestrator
import (
"github.com/andreaskoch/allmark/common/route"
"github.com/andreaskoch/allmark/web/view/viewmodel"
"fmt"
)
type ConversionModelOrchestrator struct {
*Orchestrator
fileOrchestrator *FileOrchestrator
}
func (orchestrator *ConversionModelOrchestrator) GetConversionModel(baseURL string, route route.Route) (model viewmodel.ConversionModel, found bool) {
// get the root item
root := orchestrator.rootItem()
if root == nil {
return model, false
}
// get the requested item
item := orchestrator.getItem(route)
if item == nil {
orchestrator.logger.Info("There was no item for route %q.", route)
return model, false
}
// create the path provider
rootPathProvider := orchestrator.absolutePather(fmt.Sprintf("%s/", baseURL))
// convert content
convertedContent, err := orchestrator.converter.Convert(orchestrator.getItemByAlias, rootPathProvider, item)
if err != nil {
return model, false
}
// create a view model
model = viewmodel.ConversionModel{
Base: getBaseModel(root, item, orchestrator.config),
Content: convertedContent,
// files
Files: orchestrator.fileOrchestrator.GetFiles(route),
}
return model, true
}