Skip to content

Instantly share code, notes, and snippets.

@santiago-salas-v
Created May 3, 2016 00:21
Show Gist options
  • Save santiago-salas-v/08ed91a873f3463789e02518f2b39fd3 to your computer and use it in GitHub Desktop.
Save santiago-salas-v/08ed91a873f3463789e02518f2b39fd3 to your computer and use it in GitHub Desktop.
Make4htView = require './make4ht-view'
{CompositeDisposable} = require 'atom'
fs = require 'fs'
path = require 'path'
process = require 'process'
spawn = require('child_process').spawn
module.exports = Make4ht =
make4htView: null
modalPanel: null
subscriptions: null
activate: (state) ->
@make4htView = new Make4htView(state.make4htViewState)
@modalPanel = atom.workspace.addModalPanel(item: @make4htView.getElement(), visible: false)
# Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
@subscriptions = new CompositeDisposable
# Register command that toggles this view
@subscriptions.add atom.commands.add 'atom-workspace', 'make4ht:toggle': =>
@toggle()
@subscriptions.add atom.commands.add 'atom-workspace', 'make4ht:run': =>
@run()
deactivate: ->
@modalPanel.destroy()
@subscriptions.dispose()
@make4htView.destroy()
serialize: ->
make4htViewState: @make4htView.serialize()
toggle: ->
console.log 'Make4ht was toggled!'
if @modalPanel.isVisible()
@modalPanel.hide()
else
@modalPanel.show()
run: ->
console.log 'running make4ht'
cwd = process.cwd()
fname = atom.workspace.getActiveTextEditor().getPath()
parsed_fname = path.parse(fname)
filedir = parsed_fname.dir
filebase = parsed_fname.base
fileext = parsed_fname.ext
makefile =
(x for x in fs.readdirSync(filedir) when path.extname(x) == '.mk4')
options = ['']
if makefile.length > 0
options +=
['-e', "\"" + path.resolve(filedir, makefile[0]) + "\""].join(' ')
if fileext == '.tex'
args = ["#{filebase}",'-e', makefile[0] ]
console.log 'dir:' + filedir
console.log 'makefile:' + makefile
console.log 'args: ' + args.join(' ')
process.chdir(filedir)
make4ht_process =
spawn 'make4ht', args
make4ht_process.stdout.on 'data', (data) ->
console.log("stdout: #{data}")
make4ht_process.stderr.on 'data', (data) ->
console.log("stderr: #{data}")
process.chdir(cwd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment