| 1 |
// Copyright 2019 The Hugo Authors. All rights reserved. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 7 |
// |
| 8 |
// Unless required by applicable law or agreed to in writing, software |
| 9 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 |
// See the License for the specific language governing permissions and |
| 12 |
// limitations under the License. |
| 13 |
|
| 14 |
package hugolib |
| 15 |
|
| 16 |
import ( |
| 17 |
"testing" |
| 18 |
) |
| 19 |
|
| 20 |
func TestData(t *testing.T) { |
| 21 |
t.Run("with theme", func(t *testing.T) { |
| 22 |
t.Parallel() |
| 23 |
|
| 24 |
files := ` |
| 25 |
-- hugo.toml -- |
| 26 |
baseURL = "https://example.com" |
| 27 |
disableKinds = ["taxonomy", "term", "RSS", "sitemap", "robotsTXT", "page", "section"] |
| 28 |
theme = "mytheme" |
| 29 |
-- data/a.toml -- |
| 30 |
v1 = "a_v1" |
| 31 |
-- data/b.yaml -- |
| 32 |
v1: b_v1 |
| 33 |
-- data/c/d.yaml -- |
| 34 |
v1: c_d_v1 |
| 35 |
-- themes/mytheme/data/a.toml -- |
| 36 |
v1 = "a_v1_theme" |
| 37 |
-- themes/mytheme/data/d.toml -- |
| 38 |
v1 = "d_v1_theme" |
| 39 |
-- layouts/home.html -- |
| 40 |
a: {{ hugo.Data.a.v1 }}| |
| 41 |
b: {{ hugo.Data.b.v1 }}| |
| 42 |
cd: {{ hugo.Data.c.d.v1 }}| |
| 43 |
d: {{ hugo.Data.d.v1 }}| |
| 44 |
` |
| 45 |
b := Test(t, files) |
| 46 |
|
| 47 |
b.AssertFileContent("public/index.html", "a: a_v1|\nb: b_v1|\ncd: c_d_v1|\nd: d_v1_theme|") |
| 48 |
}) |
| 49 |
} |
| 50 |
|
| 51 |
func TestDataMixedCaseFolders(t *testing.T) { |
| 52 |
t.Parallel() |
| 53 |
|
| 54 |
files := ` |
| 55 |
-- hugo.toml -- |
| 56 |
baseURL = "https://example.com" |
| 57 |
-- data/MyFolder/MyData.toml -- |
| 58 |
v1 = "my_v1" |
| 59 |
-- layouts/home.html -- |
| 60 |
{{ hugo.Data }} |
| 61 |
v1: {{ hugo.Data.MyFolder.MyData.v1 }}| |
| 62 |
` |
| 63 |
b := Test(t, files) |
| 64 |
|
| 65 |
b.AssertFileContent("public/index.html", "v1: my_v1|") |
| 66 |
} |
| 67 |
|
| 68 |
// Issue #12133 |
| 69 |
func TestDataNoAssets(t *testing.T) { |
| 70 |
t.Parallel() |
| 71 |
|
| 72 |
files := ` |
| 73 |
-- hugo.toml -- |
| 74 |
disableKinds = ['page','rss','section','sitemap','taxonomy','term'] |
| 75 |
-- assets/data/foo.toml -- |
| 76 |
content = "I am assets/data/foo.toml" |
| 77 |
-- layouts/home.html -- |
| 78 |
|{{ hugo.Data.foo.content }}| |
| 79 |
` |
| 80 |
|
| 81 |
b := Test(t, files) |
| 82 |
|
| 83 |
b.AssertFileContent("public/index.html", "||") |
| 84 |
} |