Module: VER::Methods::Preview
- Defined in:
- lib/ver/methods/preview.rb
Defined Under Namespace
Classes: Frame
Class Method Summary collapse
- .compile(buffer) ⇒ Object
- .compile_haml(buffer) ⇒ Object
- .compile_sass(buffer) ⇒ Object
-
.open_rxvt(buffer, command) ⇒ Object
Open a new urxvt term and manage it inside the layout of VER.
- .preview(buffer) ⇒ Object
- .preview_ruby(buffer) ⇒ Object
-
.spawn_rxvt(command) ⇒ Object
Open a new urxvt term in the background, this is not kept inside VER layout.
Class Method Details
.compile(buffer) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/ver/methods/preview.rb', line 26 def compile(buffer) return unless syntax = buffer.syntax method = "compile_#{syntax.name}".downcase if respond_to?(method) send(method, buffer) end end |
.compile_haml(buffer) ⇒ Object
36 37 |
# File 'lib/ver/methods/preview.rb', line 36 def compile_haml(buffer) end |
.compile_sass(buffer) ⇒ Object
39 40 |
# File 'lib/ver/methods/preview.rb', line 39 def compile_sass(buffer) end |
.open_rxvt(buffer, command) ⇒ Object
Open a new urxvt term and manage it inside the layout of VER. Please let me know if you notice weird behaviour around the focus
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ver/methods/preview.rb', line 60 def open_rxvt(buffer, command) layout = buffer.layout # No Tk::Tile::Frame as it doesn't support container frame = Frame.new(layout, container: true) layout.add_buffer(frame) frame.bind '<MapRequest>' do |event| # Quite the weird hack, but once the MapRequest was handled, we can # focus the frame again to actually focus the term. # The delay was chosen by trying it on my notebook, which may or may # not be enough for everybody, so i added a bit of margin for error. # Usually humans don't notice the delay, so we could increase it a bit # if need arises. Tk::After.ms 100 do buffer.focus frame.focus end end frame.bind '<Map>' do |event| cmd = "urxvt -embed #{frame.winfo_id} -e $SHELL -c '%s' &" % [command] # puts cmd `#{cmd}` end frame.bind '<Destroy>' do |event| Tk::After.idle do layout.close_buffer(frame) buffer.focus(:force) # need to use force, the term was outside tk end end end |
.preview(buffer) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/ver/methods/preview.rb', line 16 def preview(buffer) return unless syntax = buffer.syntax method = "preview_#{syntax.name}".downcase if respond_to?(method) send(method, buffer) end end |
.preview_ruby(buffer) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/ver/methods/preview.rb', line 42 def preview_ruby(buffer) buffer.save spawn_rxvt(<<-SHELL) ruby #{buffer.filename.shellescape} echo "\nPreview finished, press <Return> to return to VER" read exit SHELL end |
.spawn_rxvt(command) ⇒ Object
Open a new urxvt term in the background, this is not kept inside VER layout.
54 55 56 |
# File 'lib/ver/methods/preview.rb', line 54 def spawn_rxvt(command) system("urxvt -e $SHELL -c '%s' &" % [command]) end |