Apologies if I will be not entirely clear, but I’m not entirely familiar with all the Ruby terminology that I’m trying to stretch.
I’ve been trying to build a simple MiddlemanExtension to output the HTML page title irrespective of where this has been stored, but giving some kind of logical precedence.
Below an abstract:
class SeoSupport < Middleman::Extension
def initialize(app, options_hash={}, &block)
super
end
helpers do
private
def page_title
@title || current_page.data.title || I18n.t(:blogPageDefaultTitle) rescue ""
end
# Printing methods with the corresponding HTML tag
def print_page_title
unless page_title.blank?
concat '<title>' << h(page_title.gsub("\n","")) << '</title>' << "\n"
end
end
end
end
::Middleman::Extensions.register(:seo_support, SeoSupport)
The problem lays down on the private Access Control decorator. As far as I understand, the private just above the page_title function should not allow the method to be called by an external receiver (which in my case is a template).
However, by the time the extension is registered, if within a template I recall either the print_page_title
or page_title
, the output is print regardless.
Surely it’s me being a newbie in Ruby, so is there somebody that could help me figuring out what I’m doing incorrectly?
Thanks