Skip to content

Commit

Permalink
Move from magic comments to magic elements
Browse files Browse the repository at this point in the history
  • Loading branch information
danott committed Jan 15, 2024
1 parent e5018ac commit 5540e49
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/includable/page_defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def initialize(string:, data:)

def render
<<~HTML
<!--IncludeInHeader::Text
<include-in-header>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="The personal website of Dan Ott.">
Expand All @@ -18,7 +18,7 @@ def render
<link rel="alternate" type="application/rss+xml" href="/feed.xml" title="Dan Ott's RSS Feed">
<script src="/javascripts/script.js"></script>
-->
</include-in-header>
HTML
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/magic_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ def initialize(path, original_content)

def content
if path.match(%r{site/\d\d\d\d/})
[
"<!--Include::PageDefaults-->",
original_content,
"<!--Include::PostFooter-->"
].join("\n\n")
<<~HTML
<eval-ruby>Includable::PageDefaults.new(string: nil, data: nil).render</eval-ruby>
#{original_content}
<eval-ruby>Includable::PostFooter.new(string: nil, data: self.data).render</eval-ruby>
HTML
else
original_content
end
Expand Down
4 changes: 3 additions & 1 deletion site/debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

This is my page for debugging my build

<!--Include::DataDump-->
<eval-ruby>
Includable::DataDump.new(string: nil, data: Build.data).render
</eval-ruby>
5 changes: 2 additions & 3 deletions site/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!--Include::PageDefaults-->
<eval-ruby>Includable::PageDefaults.new(string: nil, data: nil).render</eval-ruby>

# 👨‍💻 danott.website

Expand All @@ -9,7 +9,6 @@ That's why I am hosting it at `danott.website`.
You can subscribe to [Dan Ott's Website RSS Feed](/feed.xml).
Here's a list of posts I've written in reverse chronological order.

<!--Include::Index-->
<eval-ruby>
Includable::Index.new(string: nil, data: Build.data)
Includable::Index.new(string: nil, data: Build.data).render
</eval-ruby>
6 changes: 4 additions & 2 deletions site/six-words.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!--Include::PageDefaults-->
<eval-ruby>Includable::PageDefaults.new(string: nil, data: nil).render</eval-ruby>

# Six Words

Expand All @@ -9,4 +9,6 @@ This habit offered consistency and constraints.
I've decided to try it again.
I'll share when I feel compelled.

<!--Include::SixWords-->
<eval-ruby>
Includable::SixWords.new(string: nil, data: Build.data).render
</eval-ruby>
2 changes: 1 addition & 1 deletion test/magic_file_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ def test_path_with_magic
refute_equal content, magic_content
assert_operator magic_content,
:starts_with?,
"<!--Include::PageDefaults-->\n\n"
"<eval-ruby>Includable::PageDefaults.new(string: nil, data: nil).render</eval-ruby>"
end
end

0 comments on commit 5540e49

Please sign in to comment.