Class: Locomotive::Steam::Middlewares::PageEditing
- Inherits:
-
Object
- Object
- Locomotive::Steam::Middlewares::PageEditing
- Defined in:
- lib/locomotive/steam/middlewares/page_editing.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, opts = {}) ⇒ PageEditing
constructor
A new instance of PageEditing.
Constructor Details
#initialize(app, opts = {}) ⇒ PageEditing
Returns a new instance of PageEditing.
9 10 11 |
# File 'lib/locomotive/steam/middlewares/page_editing.rb', line 9 def initialize(app, opts = {}) @app = app end |
Instance Method Details
#call(env) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/locomotive/steam/middlewares/page_editing.rb', line 13 def call(env) disable_live_editing_if_not_html(env) status, headers, response = @app.call(env) site, mounted_on, page, locale, live_editing = env['steam.site'], env['steam.mounted_on'], env['steam.page'], env['steam.locale'].to_s, env['steam.live_editing'] if editable?(page, response, live_editing) html = %( <meta name="locomotive-locale" content="#{locale}" /> <meta name="locomotive-editable-elements-path" content="#{editable_elements_path(site, page, locale, env)}" /> <meta name="locomotive-page-id" content="#{page._id}" /> <meta name="locomotive-mounted-on" content="#{mounted_on}" /> <link href='https://fonts.googleapis.com/css?family=Noto+Sans' rel='stylesheet' type='text/css'> <!-- [Locomotive] fix absolute links to inner pages in preview mode--> <script> window.document.addEventListener('click', function (event) { var qs = document.querySelectorAll('a'); if (qs) { var el = event.target, index = -1; while (el && ((index = Array.prototype.indexOf.call(qs, el)) === -1)) { el = el.parentElement; } if (index > -1) { var url = el.getAttribute('href'); if (url[0] == '/' && url.indexOf('#{mounted_on}') == -1 && url.indexOf('/sites/') == -1) { el.setAttribute('href', '#{mounted_on}' + url); } } } }); </script> ) response.first.gsub!('</head>', %(#{html}</head>)) end [status, headers, response] end |