-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed base to use javascript instead of coffeescript
- Loading branch information
Showing
16 changed files
with
233 additions
and
175 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 0.1.0 - First Release | ||
* Every feature added | ||
* Every bug fixed | ||
## 0.1.1 - Fixed Indenting, changed source language. | ||
* Fixed up indenting issues found with the first line. Should now properly indent | ||
* Converted package to use javascript instead of coffeescript. | ||
* Due to changes above, the hotkey is now namespaced with html-to-javascript instead of atom-html-to-javascript. | ||
|
||
## 0.1.0 - Initial Release | ||
* Added feature to convert HTML to JS with indenting. |
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"atom-workspace": { | ||
"ctrl-shift-j": "html-to-javascript:convert" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use babel'; | ||
|
||
export default class HtmlToJavascriptView { | ||
|
||
constructor(serializedState) { | ||
// Create root element | ||
this.element = document.createElement('div'); | ||
this.element.classList.add('html-to-javascript'); | ||
|
||
// Create message element | ||
const message = document.createElement('div'); | ||
message.textContent = 'The HtmlToJavascript package is Alive! It\'s ALIVE!'; | ||
message.classList.add('message'); | ||
this.element.appendChild(message); | ||
} | ||
|
||
// Returns an object that can be retrieved when package is activated | ||
serialize() {} | ||
|
||
// Tear down any state and detach | ||
destroy() { | ||
this.element.remove(); | ||
} | ||
|
||
getElement() { | ||
return this.element; | ||
} | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
'use babel'; | ||
|
||
import HtmlToJavascriptView from './html-to-javascript-view'; | ||
import { CompositeDisposable } from 'atom'; | ||
|
||
export default { | ||
|
||
htmlToJavascriptView: null, | ||
modalPanel: null, | ||
subscriptions: null, | ||
|
||
activate(state) { | ||
this.htmlToJavascriptView = new HtmlToJavascriptView(state.htmlToJavascriptViewState); | ||
this.modalPanel = atom.workspace.addModalPanel({ | ||
item: this.htmlToJavascriptView.getElement(), | ||
visible: false | ||
}); | ||
|
||
// Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable | ||
this.subscriptions = new CompositeDisposable(); | ||
|
||
// Register command that toggles this view | ||
this.subscriptions.add(atom.commands.add('atom-workspace', { | ||
'html-to-javascript:convert': () => this.convert() | ||
})); | ||
}, | ||
|
||
deactivate() { | ||
this.modalPanel.destroy(); | ||
this.subscriptions.dispose(); | ||
this.htmlToJavascriptView.destroy(); | ||
}, | ||
|
||
serialize() { | ||
return { | ||
htmlToJavascriptViewState: this.htmlToJavascriptView.serialize() | ||
}; | ||
}, | ||
|
||
convert() { | ||
var editor = atom.workspace.getActiveTextEditor(); | ||
if (editor){ | ||
var selection = editor.getSelectedText() | ||
if (!!!selection.trim()) return; | ||
|
||
// # Replace all ' in file with \' | ||
selection = selection.replace(/'/g , "\\'"); | ||
|
||
// # Edit selection: | ||
var lines = selection.split("\n"); | ||
|
||
|
||
|
||
var js_string = "''+\n"; | ||
// # Wrap beginning and end of lines with ' | ||
// # (for the beginning of a line, put it at the beginning of the first non space) | ||
// # (for the end of a line, trim the end putting '+ at the end of the line) | ||
for (var i = 0; i < lines.length; i++) { | ||
var line = lines[i]; | ||
|
||
num_leading_whitespace = line.search(/\S|$/); | ||
var string_leading = ''; | ||
if (num_leading_whitespace){ | ||
for (var i = 0; i < num_leading_whitespace; i++) { | ||
string_leading += "\t"; | ||
} | ||
} | ||
|
||
js_string += string_leading + "'" + line.trim() + "'+\n"; | ||
|
||
} | ||
|
||
editor.insertText(js_string.substring(0,js_string.length-2), { | ||
select: true | ||
}); //# Ignores the last 2 symbols "+\n" | ||
} | ||
|
||
} | ||
|
||
}; |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"context-menu": { | ||
"atom-text-editor": [ | ||
{ | ||
"label": "HTML -> JS", | ||
"command": "html-to-javascript:convert" | ||
} | ||
] | ||
}, | ||
"menu": [ | ||
{ | ||
"label": "Packages", | ||
"submenu": [ | ||
{ | ||
"label": "html-to-javascript", | ||
"submenu": [ | ||
{ | ||
"label": "Convert HTML -> JS", | ||
"command": "html-to-javascript:convert" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.