Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit 76194a7

Browse files
committed
feat: load @project to GlobalBindings
...which will eventually replace @site
1 parent fd78fa8 commit 76194a7

File tree

5 files changed

+16
-4
lines changed

5 files changed

+16
-4
lines changed

lib/serum/project/loader.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ defmodule Serum.Project.Loader do
2525
base_url: proj.base_url
2626
})
2727

28+
GlobalBindings.put(:project, proj)
29+
2830
{:ok, %Project{proj | src: src, dest: dest}}
2931

3032
{:error, _} = error ->

lib/serum/template/helpers.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ defmodule Serum.Template.Helpers do
118118
end
119119
end
120120

121-
defp base!, do: quote(do: get_in(var!(assigns), [:site, :base_url]))
121+
defp base!, do: quote(do: var!(assigns)[:project].base_url)
122122

123123
defmacro include(_) do
124124
raise "the include/1 macro is expanded by the Serum template compiler " <>

test/serum/template/compiler_test.exs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ defmodule Serum.Template.CompilerTest do
22
use ExUnit.Case, async: true
33
require Serum.TestHelper
44
import Serum.TestHelper, only: :macros
5+
alias Serum.Project
56
alias Serum.Template.Compiler, as: TC
67
alias Serum.Template.Storage, as: TS
78

@@ -15,7 +16,12 @@ defmodule Serum.Template.CompilerTest do
1516
file = %Serum.File{src: fixture("templates/#{key}.html.eex")}
1617
{:ok, file} = Serum.File.read(file)
1718
{:ok, %{^key => template}} = TC.compile_files([file], type: :template)
18-
assigns = [site: %{base_url: "/test_site/"}]
19+
20+
assigns = [
21+
site: %{base_url: "/test_site/"},
22+
project: %Project{base_url: "/test_site/"}
23+
]
24+
1925
{output, _} = Code.eval_quoted(template.ast, assigns: assigns)
2026

2127
assert template.type === :template

test/serum/template/helpers_test.exs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
defmodule Serum.Template.HelpersTest do
22
use ExUnit.Case
33
require Serum.Template.Helpers
4+
alias Serum.Project
45
alias Serum.Template
56
alias Serum.Template.Helpers
67
alias Serum.Template.Storage, as: TS
78

8-
@assigns [site: %{base_url: "/base/url"}]
9+
@assigns [
10+
site: %{base_url: "/base/url"},
11+
project: %Project{base_url: "/base/url"}
12+
]
913

1014
setup_all do
1115
good = EEx.compile_string("Hello, <%= @args[:name] %>!")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
%{all_pages: [%{group: "test", label: "test-md", order: 1, title: "Test Markdown Page", type: :page, url: "/test-site/home/dalgona/repo/Serum/priv/fixtures/pages/good-md.html"}, %{group: "test", label: "test-html", order: 2, title: "Test HTML Page", type: :page, url: "/test-site/home/dalgona/repo/Serum/priv/fixtures/pages/good-html.html"}, %{group: nil, label: "Test Page", order: nil, title: "Test Page", type: :page, url: "/test-site/home/dalgona/repo/Serum/priv/fixtures/pages/good-minimal-header.html"}], all_posts: [%{date: "2019-01-01", preview: "Hello, world! The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The qu…", raw_date: {{2019, 1, 1}, {12, 34, 56}}, tags: [%{__struct__: Serum.Tag, list_url: "/test-site/tags/tag1", name: "tag1"}, %{__struct__: Serum.Tag, list_url: "/test-site/tags/tag2", name: "tag2"}], title: "Test Post", type: :post, url: "/test-site/home/dalgona/repo/Serum/priv/fixtures/posts/good-post.html"}, %{date: "2019-01-01", preview: "Hello, world! The quick brown fox jumps over the lazy dog.", raw_date: {{2019, 1, 1}, {0, 0, 0}}, tags: [], title: "Test Post", type: :post, url: "/test-site/home/dalgona/repo/Serum/priv/fixtures/posts/good-minimal-header.html"}, %{date: "2019-01-01", preview: "Hello, world! The quick brown fox jumps over the lazy dog.", raw_date: {{2019, 1, 1}, {0, 0, 0}}, tags: [%{__struct__: Serum.Tag, list_url: "/test-site/tags/tag3", name: "tag3"}, %{__struct__: Serum.Tag, list_url: "/test-site/tags/tag4", name: "tag4"}], title: "Test Post", type: :post, url: "/test-site/home/dalgona/repo/Serum/priv/fixtures/posts/good-alternative-date.html"}], all_tags: [{%{__struct__: Serum.Tag, list_url: "/test-site/tags/tag1", name: "tag1"}, 1}, {%{__struct__: Serum.Tag, list_url: "/test-site/tags/tag2", name: "tag2"}, 1}, {%{__struct__: Serum.Tag, list_url: "/test-site/tags/tag3", name: "tag3"}, 1}, {%{__struct__: Serum.Tag, list_url: "/test-site/tags/tag4", name: "tag4"}, 1}], site: %{author: "John Doe", author_email: "[email protected]", base_url: "/test-site/", description: "This is the test website.", name: "Test Webite", server_root: "https://www.example.com"}}
1+
%{all_pages: [%{group: "test", label: "test-md", order: 1, title: "Test Markdown Page", type: :page, url: "/test-site/home/dalgona/repo/Serum/priv/fixtures/pages/good-md.html"}, %{group: "test", label: "test-html", order: 2, title: "Test HTML Page", type: :page, url: "/test-site/home/dalgona/repo/Serum/priv/fixtures/pages/good-html.html"}, %{group: nil, label: "Test Page", order: nil, title: "Test Page", type: :page, url: "/test-site/home/dalgona/repo/Serum/priv/fixtures/pages/good-minimal-header.html"}], all_posts: [%{date: "2019-01-01", preview: "Hello, world! The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The qu…", raw_date: {{2019, 1, 1}, {12, 34, 56}}, tags: [%{__struct__: Serum.Tag, list_url: "/test-site/tags/tag1", name: "tag1"}, %{__struct__: Serum.Tag, list_url: "/test-site/tags/tag2", name: "tag2"}], title: "Test Post", type: :post, url: "/test-site/home/dalgona/repo/Serum/priv/fixtures/posts/good-post.html"}, %{date: "2019-01-01", preview: "Hello, world! The quick brown fox jumps over the lazy dog.", raw_date: {{2019, 1, 1}, {0, 0, 0}}, tags: [], title: "Test Post", type: :post, url: "/test-site/home/dalgona/repo/Serum/priv/fixtures/posts/good-minimal-header.html"}, %{date: "2019-01-01", preview: "Hello, world! The quick brown fox jumps over the lazy dog.", raw_date: {{2019, 1, 1}, {0, 0, 0}}, tags: [%{__struct__: Serum.Tag, list_url: "/test-site/tags/tag3", name: "tag3"}, %{__struct__: Serum.Tag, list_url: "/test-site/tags/tag4", name: "tag4"}], title: "Test Post", type: :post, url: "/test-site/home/dalgona/repo/Serum/priv/fixtures/posts/good-alternative-date.html"}], all_tags: [{%{__struct__: Serum.Tag, list_url: "/test-site/tags/tag1", name: "tag1"}, 1}, {%{__struct__: Serum.Tag, list_url: "/test-site/tags/tag2", name: "tag2"}, 1}, {%{__struct__: Serum.Tag, list_url: "/test-site/tags/tag3", name: "tag3"}, 1}, {%{__struct__: Serum.Tag, list_url: "/test-site/tags/tag4", name: "tag4"}, 1}], site: %{author: "John Doe", author_email: "[email protected]", base_url: "/test-site/", description: "This is the test website.", name: "Test Webite", server_root: "https://www.example.com"}, project: %Serum.Project{author: "John Doe", author_email: "[email protected]", base_url: "/test-site/", site_description: "This is the test website.", site_name: "Test Webite", server_root: "https://www.example.com"}}

0 commit comments

Comments
 (0)