Skip to content

Instantly share code, notes, and snippets.

@Sixeight
Created April 13, 2014 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sixeight/10598766 to your computer and use it in GitHub Desktop.
Save Sixeight/10598766 to your computer and use it in GitHub Desktop.
run ruby sample
{BufferedProcess, View} = require 'atom'
class QuickrunView extends View
@content: ->
@div class: 'quickrun overlay from-top', =>
@div class: 'panel', =>
@div class: 'panel-heading', =>
@span outlet: 'heading', 'quickrun'
@div class: 'btn-toolbar pull-right', =>
@button class: 'btn close', 'X'
@div class: 'panel-body padded', outlet: 'message'
setResult: (result) ->
@on 'click', '.close', => @close()
atom.workspaceView.append(this)
atom.workspaceView.addClass('quickrun active')
@message.html View.render ->
@pre class: 'result', =>
@code result
close: ->
atom.workspaceView.removeClass('quickrun active')
@detach()
class Quickrun
constructor: ->
view: null
@view = new QuickrunView
atom.workspaceView.command "quickrun:ruby", => @run()
atom.workspaceView.command "quickrun:close", => @close()
run: ->
editor = atom.workspace.getActiveEditor()
grammar = editor.getGrammar()
if grammar.name is 'Ruby'
command = 'ruby'
args = ['-e', editor.getBuffer().getText()]
options =
env: process.env
stdout = (output) =>
@view.setResult(output)
stderr = (output) =>
@view.setResult(output)
new BufferedProcess({command, args, options, stdout, stderr})
close: ->
@view.close()
new Quickrun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment