Module: RailsAmp::ViewHelpers::ActionView
- Defined in:
- lib/rails_amp/view_helpers/action_view.rb
Instance Method Summary collapse
- #amp_renderable? ⇒ Boolean
-
#rails_amp_amphtml_link_tag ⇒ Object
To add header code in default layout like application.html.erb.
- #rails_amp_canonical_url ⇒ Object
- #rails_amp_google_analytics_head ⇒ Object
- #rails_amp_google_analytics_page_tracking ⇒ Object
- #rails_amp_html_header ⇒ Object
Instance Method Details
#amp_renderable? ⇒ Boolean
68 69 70 |
# File 'lib/rails_amp/view_helpers/action_view.rb', line 68 def amp_renderable? RailsAmp.amp_renderable?(controller.controller_path, controller.action_name) end |
#rails_amp_amphtml_link_tag ⇒ Object
To add header code in default layout like application.html.erb.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rails_amp/view_helpers/action_view.rb', line 6 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(<link rel="amphtml" href="#{amp_uri.to_s}" />).html_safe end |
#rails_amp_canonical_url ⇒ Object
64 65 66 |
# File 'lib/rails_amp/view_helpers/action_view.rb', line 64 def rails_amp_canonical_url request.url.gsub(".#{RailsAmp.default_format.to_s}", '') end |
#rails_amp_google_analytics_head ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/rails_amp/view_helpers/action_view.rb', line 30 def rails_amp_google_analytics_head return '' if RailsAmp.analytics.blank? analytics_head =<<"EOS" <!-- Google Analytics for amp pages. --> <script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script> EOS analytics_head.html_safe end |
#rails_amp_google_analytics_page_tracking ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rails_amp/view_helpers/action_view.rb', line 40 def rails_amp_google_analytics_page_tracking return '' if RailsAmp.analytics.blank? analytics_code =<<"EOS" <!-- Google Analytics Page Tracking for amp pages. --> <amp-analytics type="googleanalytics" id="rails_amp_analytics"> <script type="application/json"> { "vars": { "account": "#{RailsAmp.analytics}" }, "triggers": { "trackPageview": { "on": "visible", "request": "pageview" } } } </script> </amp-analytics> EOS analytics_code.html_safe end |
#rails_amp_html_header ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/rails_amp/view_helpers/action_view.rb', line 21 def rails_amp_html_header header =<<"EOS" <!-- Snipet for amp library. --> <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript> <script async src="https://cdn.ampproject.org/v0.js"></script> EOS header.html_safe end |