Created
April 13, 2014 19:30
-
-
Save Sixeight/10598766 to your computer and use it in GitHub Desktop.
run ruby sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{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