2021-01-05 18:35:40 +05:30
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2021-01-05 18:35:40 +05:30
|
|
|
|
|
|
|
package templates
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
2023-04-12 15:46:45 +05:30
|
|
|
"code.gitea.io/gitea/modules/assetfs"
|
2021-01-05 18:35:40 +05:30
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
"code.gitea.io/gitea/modules/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Vars represents variables to be render in golang templates
|
|
|
|
type Vars map[string]interface{}
|
|
|
|
|
|
|
|
// Merge merges another vars to the current, another Vars will override the current
|
|
|
|
func (vars Vars) Merge(another map[string]interface{}) Vars {
|
|
|
|
for k, v := range another {
|
|
|
|
vars[k] = v
|
|
|
|
}
|
|
|
|
return vars
|
|
|
|
}
|
|
|
|
|
|
|
|
// BaseVars returns all basic vars
|
|
|
|
func BaseVars() Vars {
|
2022-01-20 23:16:10 +05:30
|
|
|
startTime := time.Now()
|
2021-01-05 18:35:40 +05:30
|
|
|
return map[string]interface{}{
|
|
|
|
"IsLandingPageHome": setting.LandingPageURL == setting.LandingPageHome,
|
|
|
|
"IsLandingPageExplore": setting.LandingPageURL == setting.LandingPageExplore,
|
|
|
|
"IsLandingPageOrganizations": setting.LandingPageURL == setting.LandingPageOrganizations,
|
|
|
|
|
2022-07-31 22:27:02 +05:30
|
|
|
"ShowRegistrationButton": setting.Service.ShowRegistrationButton,
|
|
|
|
"ShowMilestonesDashboardPage": setting.Service.ShowMilestonesDashboardPage,
|
|
|
|
"ShowFooterBranding": setting.ShowFooterBranding,
|
|
|
|
"ShowFooterVersion": setting.ShowFooterVersion,
|
|
|
|
"DisableDownloadSourceArchives": setting.Repository.DisableDownloadSourceArchives,
|
2021-01-05 18:35:40 +05:30
|
|
|
|
|
|
|
"EnableSwagger": setting.API.EnableSwagger,
|
|
|
|
"EnableOpenIDSignIn": setting.Service.EnableOpenIDSignIn,
|
|
|
|
"PageStartTime": startTime,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-12 15:46:45 +05:30
|
|
|
func AssetFS() *assetfs.LayeredFS {
|
|
|
|
return assetfs.Layered(CustomAssets(), BuiltinAssets())
|
2022-08-28 15:13:25 +05:30
|
|
|
}
|
|
|
|
|
2023-04-12 15:46:45 +05:30
|
|
|
func CustomAssets() *assetfs.Layer {
|
|
|
|
return assetfs.Local("custom", setting.CustomPath, "templates")
|
|
|
|
}
|
2021-01-05 18:35:40 +05:30
|
|
|
|
2023-04-12 15:46:45 +05:30
|
|
|
func ListWebTemplateAssetNames(assets *assetfs.LayeredFS) ([]string, error) {
|
|
|
|
files, err := assets.ListAllFiles(".", true)
|
2021-01-05 18:35:40 +05:30
|
|
|
if err != nil {
|
2023-04-12 15:46:45 +05:30
|
|
|
return nil, err
|
2021-01-05 18:35:40 +05:30
|
|
|
}
|
2023-04-12 15:46:45 +05:30
|
|
|
return util.SliceRemoveAllFunc(files, func(file string) bool {
|
|
|
|
return strings.HasPrefix(file, "mail/") || !strings.HasSuffix(file, ".tmpl")
|
|
|
|
}), nil
|
2021-01-05 18:35:40 +05:30
|
|
|
}
|
2021-01-26 21:06:53 +05:30
|
|
|
|
2023-04-12 15:46:45 +05:30
|
|
|
func ListMailTemplateAssetNames(assets *assetfs.LayeredFS) ([]string, error) {
|
|
|
|
files, err := assets.ListAllFiles(".", true)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2022-08-28 15:13:25 +05:30
|
|
|
}
|
2023-04-12 15:46:45 +05:30
|
|
|
return util.SliceRemoveAllFunc(files, func(file string) bool {
|
|
|
|
return !strings.HasPrefix(file, "mail/") || !strings.HasSuffix(file, ".tmpl")
|
|
|
|
}), nil
|
2021-01-26 21:06:53 +05:30
|
|
|
}
|