Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Config #62

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions lib/script-view.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
grammarMap = require './grammars'
{View, BufferedProcess} = require 'atom'
HeaderView = require './header-view'

Expand Down Expand Up @@ -67,6 +66,8 @@ class ScriptView extends View
# Get language
lang = @getlang(editor)

langConfig = atom.config.get('script.grammars.' + lang)

err = null
# Determine if no language is selected
if lang == "Null Grammar" or lang == "Plain Text"
Expand All @@ -76,7 +77,7 @@ class ScriptView extends View

# Provide them a dialog to submit an issue on GH, prepopulated
# with their language of choice
else if ! (lang of grammarMap)
else if not langConfig?
err =
"Command not configured for " + lang + "!\n\n" +
"Add an <a href='https://github.com/rgbkrk/atom-script/issues/" +
Expand All @@ -87,8 +88,8 @@ class ScriptView extends View
@handleError(err)
return false

# Precondition: lang? and lang of grammarMap
info.command = grammarMap[lang]["command"]
# Precondition: lang? and langConfig?
info.command = langConfig['command']

filename = editor.getTitle()

Expand All @@ -105,25 +106,19 @@ class ScriptView extends View

# No selected text on a file that does exist, use filepath
if (not selectedText? or not selectedText) and filepath?
argType = "File Based"
flagsType = "Run Flags"
arg = filepath
else
argType = "Selection Based"
flagsType = "Selection Run Flags"
arg = selectedText

makeargs = grammarMap[lang][argType]

try
args = makeargs(arg)
info.args = args
catch error
err = argType + " Runner not available for " + lang + "\n\n" +
"If it should exist add an " +
"<a href='https://github.com/rgbkrk/atom-script/issues/" +
"new?title=Add%20support%20for%20" + lang + "'>issue on GitHub" +
"</a> or send your own Pull Request"
@handleError(err)
return false
args = langConfig[flagsType]

if not args?
args = []

# We assume file/code goes after all the other arguments
info.args = args.concat [arg]

# Update header
@headerView.title.text(lang + " - " + filename)
Expand Down
41 changes: 41 additions & 0 deletions lib/script.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,44 @@ module.exports =

serialize: ->
scriptViewState: @scriptView.serialize()

configDefaults:
grammars:
'CoffeeScript':
command: "coffee"
"Selection Run Flags": ['-e']
"Run Flags": []
'JavaScript':
command: "node"
"Selection Run Flags": ['-e']
"Run Flags": []
'Ruby':
command: "ruby"
"Selection Run Flags": ['-e']
"Run Flags": []
'Perl':
command: "perl"
"Selection Run Flags": ['-e']
"Run Flags": []
'PHP':
command: "php"
"Selection Run Flags": ['-r']
"Run Flags": []
'Python':
command: "python"
"Selection Run Flags": ['-c']
"Run Flags": []
'Shell Script (Bash)':
command: "bash"
"Selection Run Flags": ['-c']
"Run Flags": []
'Go':
command: "go"
"Run Flags": ['run']
'F#':
command: "fsharpi"
"Run Flags": ['--exec']
'newLISP':
command: "newlisp"
"Selection Run Flags": ['-e']
"Run Flags": []