Skip to content

Commit

Permalink
Add devious hack to work around hanami-view
Browse files Browse the repository at this point in the history
  • Loading branch information
timriley committed Sep 26, 2020
1 parent fa72585 commit f9d0291
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/hanami/view
revision: 1b18bfe2fb59879d9117720892d2f55db9f1c584
revision: c4fb06a6b419cc83f2bb7f8b3027b07f03d3f199
branch: master
specs:
hanami-view (2.0.0.alpha1)
Expand Down
23 changes: 14 additions & 9 deletions lib/site/view/context.rb
Expand Up @@ -15,21 +15,26 @@ class Context < Hanami::View::Context

def_delegators :settings, :site_title, :site_author, :site_url

attr_reader :current_path

def initialize(current_path: nil, **deps)
super(**deps)
def initialize(page_title: "", **deps)
super
end

@deps = deps
@current_path = current_path
@page_title = nil
def current_path
_options[:current_path]
end

def page_title(new_title = Undefined)
if new_title == Undefined
[@page_title, settings.site_title].compact.join(" | ")
[_options[:page_title], site_title]
.reject { |str| str.to_s.empty? }
.join(" | ")
else
@page_title = new_title
# This is a hack to work around the way context objects are created for each
# render environment. To make sure that a page_title set from inside a template
# is still available in the layout, we default the page_title to an empty string
# (see #initialize) and then _mutate it_ when a new title is set. Soooo bad but
# it'll do for now, until we come up with a better approach inside hanami-view.
_options[:page_title].replace new_title
end
end

Expand Down

0 comments on commit f9d0291

Please sign in to comment.