Class: Locomotive::Middlewares::InlineEditor
- Inherits:
-
Object
- Object
- Locomotive::Middlewares::InlineEditor
- Defined in:
- lib/locomotive/middlewares/inline_editor.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, opts = {}) ⇒ InlineEditor
constructor
A new instance of InlineEditor.
- #modify(response) ⇒ Object
Constructor Details
#initialize(app, opts = {}) ⇒ InlineEditor
Returns a new instance of InlineEditor.
5 6 7 |
# File 'lib/locomotive/middlewares/inline_editor.rb', line 5 def initialize(app, opts = {}) @app = app end |
Instance Method Details
#call(env) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/locomotive/middlewares/inline_editor.rb', line 9 def call(env) status, headers, response = @app.call(env) response = modify(response) unless headers['Editable'].blank? [status, headers, response] end |
#modify(response) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/locomotive/middlewares/inline_editor.rb', line 17 def modify(response) [].tap do |parts| response.each do |part| parts << part.to_s.gsub('</body>', %( <a href="#{File.join(response.request.path, '/_admin')}" onmouseout="this.style.backgroundPosition='0px 0px'" onmouseover="this.style.backgroundPosition='0px -45px'" onmousedown="this.style.backgroundPosition='0px -90px'" onmouseup="this.style.backgroundPosition='0px 0px'" style="display: block;z-index: 1031;position: fixed;top: 10px; right: 10px;width: 48px; height: 45px;text-indent:-9999px;text-decoration:none;background: transparent url\('/assets/locomotive/icons/start.png'\) no-repeat 0 0;"> Admin</a> </body> )) end end end |