Skip to content

Commit

Permalink
Eliminate some complexity since Build.data is always accessible
Browse files Browse the repository at this point in the history
  • Loading branch information
danott committed Jan 15, 2024
1 parent 37d5fee commit 8a28450
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 17 deletions.
8 changes: 1 addition & 7 deletions lib/build_data.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
class BuildData
attr_reader :targets
attr_reader :data_sets
attr_reader :current_page

def initialize(targets, data_sets, current_page = nil)
def initialize(targets, data_sets)
@targets = targets
@data_sets = data_sets
@current_page = current_page
end

def for_current_page(next_current_page)
self.class.new(targets, data_sets, next_current_page)
end

def all
Expand Down
6 changes: 1 addition & 5 deletions lib/html_target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ def initialize(content:, path:, data:)
end

def hydrate
hydrator =
MagicElementHydrator.new(
content: content,
data: Build.data.for_current_page(data)
)
hydrator = MagicElementHydrator.new(content: content, data: data)
self.class.new(content: hydrator.hydrate.content, path: path, data: data)
end

Expand Down
8 changes: 4 additions & 4 deletions lib/includable/post_footer.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module Includable
class PostFooter
attr_reader :data
attr_reader :html_target_data

def initialize(data:)
@data = data
def initialize(html_target_data)
@html_target_data = html_target_data
end

def to_s
ERB.new(template).result_with_hash(date: data.current_page.fetch("date"))
ERB.new(template).result_with_hash(date: html_target_data.fetch("date"))
end

def template
Expand Down
2 changes: 1 addition & 1 deletion lib/magic_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def content
<<~HTML
<eval-ruby>Includable::PAGE_DEFAULTS</eval-ruby>
#{original_content}
<eval-ruby>Includable::PostFooter.new(data: self.data)</eval-ruby>
<eval-ruby>Includable::PostFooter.new(data)</eval-ruby>
HTML
else
original_content
Expand Down

0 comments on commit 8a28450

Please sign in to comment.