From 793fe204e57dd6dc4ea10dafef77a85645b643f2 Mon Sep 17 00:00:00 2001 From: MichaelHatherly Date: Tue, 7 Jan 2025 17:20:17 +0000 Subject: [PATCH] Allow module-qualified `@cm_component` definitions --- CHANGELOG.md | 8 ++++++++ src/cmfile.jl | 6 +++--- test/references/markdown/markdown-ext.txt | 2 ++ test/runtests.jl | 14 ++++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 test/references/markdown/markdown-ext.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 306f5ae..4c2d0d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +## [v2.2.1] - 2025-01-07 + +### Fixed + +- Allow `module`-qualified `@cm_component` definitions [#34] + ## [v2.2.0] - 2024-12-09 ### Added @@ -99,6 +105,7 @@ Initial release. [v2.0.1]: https://github.com/MichaelHatherly/HypertextTemplates.jl/releases/tag/v2.0.1 [v2.1.0]: https://github.com/MichaelHatherly/HypertextTemplates.jl/releases/tag/v2.1.0 [v2.2.0]: https://github.com/MichaelHatherly/HypertextTemplates.jl/releases/tag/v2.2.0 +[v2.2.1]: https://github.com/MichaelHatherly/HypertextTemplates.jl/releases/tag/v2.2.1 [#8]: https://github.com/MichaelHatherly/HypertextTemplates.jl/issues/8 [#10]: https://github.com/MichaelHatherly/HypertextTemplates.jl/issues/10 [#11]: https://github.com/MichaelHatherly/HypertextTemplates.jl/issues/11 @@ -117,3 +124,4 @@ Initial release. [#28]: https://github.com/MichaelHatherly/HypertextTemplates.jl/issues/28 [#29]: https://github.com/MichaelHatherly/HypertextTemplates.jl/issues/29 [#30]: https://github.com/MichaelHatherly/HypertextTemplates.jl/issues/30 +[#34]: https://github.com/MichaelHatherly/HypertextTemplates.jl/issues/34 diff --git a/src/cmfile.jl b/src/cmfile.jl index 5e56322..a20d900 100644 --- a/src/cmfile.jl +++ b/src/cmfile.jl @@ -31,7 +31,7 @@ macro cm_component(expr) $(CMFile)( joinpath($(dir), $(esc(path))), $(__module__), - $(QuoteNode(Symbol(name))), + $(QuoteNode(name)), $(QuoteNode(parameters)), ), ) @@ -50,7 +50,7 @@ macro cm_component(expr) $(CMFile)( joinpath($(dir), $(path)), $(__module__), - $(QuoteNode(Symbol(name))), + $(QuoteNode(name)), $(QuoteNode(parameters)), ), ) @@ -65,7 +65,7 @@ end struct CMFile file::String mod::Module - name::Symbol + name::Union{Expr,Symbol} parameters::Vector end diff --git a/test/references/markdown/markdown-ext.txt b/test/references/markdown/markdown-ext.txt new file mode 100644 index 0000000..9dee30c --- /dev/null +++ b/test/references/markdown/markdown-ext.txt @@ -0,0 +1,2 @@ +

Header

+

Interpolated value: 1.

\ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index d6aacfe..e6aa07f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -7,6 +7,15 @@ import HypertextTemplates.Elements: @time using ReferenceTests using Test +module ExternalDefs + +using HypertextTemplates + +function markdown_component_ext end +@deftag macro markdown_component_ext end + +end + # Turns off source locations in the rendered HTML such that the reference # testing does not need to account for that variablity. function render_test(f, file) @@ -68,6 +77,8 @@ end @cm_component markdown_component(; x) = joinpath(@__DIR__, "markdown.md") @deftag macro markdown_component end +@cm_component ExternalDefs.markdown_component_ext(; x) = joinpath(@__DIR__, "markdown.md") + @component function streaming(; n::Integer) @div {class = "streamed"} begin @ul begin @@ -209,6 +220,9 @@ end render_test("references/markdown/markdown.txt") do io @render io @markdown_component {x = 1} end + render_test("references/markdown/markdown-ext.txt") do io + @render io ExternalDefs.@markdown_component_ext {x = 1} + end end @testset "Render Root" begin function render_function()