module RailsAmp
module ViewHelpers
module ActionView
# To add header code in default layout like application.html.erb.
def rails_amp_amphtml_link_tag
return '' unless RailsAmp.target?(controller.controller_path, controller.action_name)
amp_uri = URI.parse(request.url)
if request.path == root_path
amp_path = "#{controller.controller_path}/#{controller.action_name}.#{RailsAmp.default_format}"
else
amp_path = ".#{RailsAmp.default_format}"
end
amp_uri.path = amp_uri.path + amp_path
amp_uri.query = ERB::Util.h(amp_uri.query) if amp_uri.query.present?
%Q().html_safe
end
def rails_amp_html_header
header =<<"EOS"
EOS
header.html_safe
end
def rails_amp_google_analytics_head
return '' if RailsAmp.analytics.blank?
analytics_head =<<"EOS"
EOS
analytics_head.html_safe
end
def rails_amp_google_analytics_page_tracking
return '' if RailsAmp.analytics.blank?
analytics_code =<<"EOS"
EOS
analytics_code.html_safe
end
def rails_amp_canonical_url
request.url.gsub(".#{RailsAmp.default_format.to_s}", '')
end
def amp_renderable?
RailsAmp.amp_renderable?(controller.controller_path, controller.action_name)
end
::ActionView::Base.send :include, self
end
end
end