Skip to content

Commit c90c2f6

Browse files
committed
Changed base to use javascript instead of coffeescript
1 parent b98f71b commit c90c2f6

16 files changed

+233
-175
lines changed

CHANGELOG.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
## 0.1.0 - First Release
2-
* Every feature added
3-
* Every bug fixed
1+
## 0.1.1 - Fixed Indenting, changed source language.
2+
* Fixed up indenting issues found with the first line. Should now properly indent
3+
* Converted package to use javascript instead of coffeescript.
4+
* Due to changes above, the hotkey is now namespaced with html-to-javascript instead of atom-html-to-javascript.
5+
6+
## 0.1.0 - Initial Release
7+
* Added feature to convert HTML to JS with indenting.

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# html-to-javascript package
1+
# html-to-javascript
22

33
This converts text string to a javascript variable or javascript ready code.
44
This package is intended to be used for the conversion of HTML code in to a javascript variable for later use.
@@ -30,4 +30,3 @@ You should be able to change this in the keymap file of atom, using the command
3030
- Detect what state it is in and toggle between the two. (rather than just having a key to convert forward, and one backwards)
3131
- Remove unneeded package generator generated code.
3232
- There will be a hotkey for HTML-to-Javascript and one for Javascript-to-HTML.
33-

keymaps/atom-html-to-javascript.cson

Lines changed: 0 additions & 11 deletions
This file was deleted.

keymaps/html-to-javascript.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"atom-workspace": {
3+
"ctrl-shift-j": "html-to-javascript:convert"
4+
}
5+
}

lib/atom-html-to-javascript-view.coffee

Lines changed: 0 additions & 22 deletions
This file was deleted.

lib/atom-html-to-javascript.coffee

Lines changed: 0 additions & 45 deletions
This file was deleted.

lib/html-to-javascript-view.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use babel';
2+
3+
export default class HtmlToJavascriptView {
4+
5+
constructor(serializedState) {
6+
// Create root element
7+
this.element = document.createElement('div');
8+
this.element.classList.add('html-to-javascript');
9+
10+
// Create message element
11+
const message = document.createElement('div');
12+
message.textContent = 'The HtmlToJavascript package is Alive! It\'s ALIVE!';
13+
message.classList.add('message');
14+
this.element.appendChild(message);
15+
}
16+
17+
// Returns an object that can be retrieved when package is activated
18+
serialize() {}
19+
20+
// Tear down any state and detach
21+
destroy() {
22+
this.element.remove();
23+
}
24+
25+
getElement() {
26+
return this.element;
27+
}
28+
29+
}

lib/html-to-javascript.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
'use babel';
2+
3+
import HtmlToJavascriptView from './html-to-javascript-view';
4+
import { CompositeDisposable } from 'atom';
5+
6+
export default {
7+
8+
htmlToJavascriptView: null,
9+
modalPanel: null,
10+
subscriptions: null,
11+
12+
activate(state) {
13+
this.htmlToJavascriptView = new HtmlToJavascriptView(state.htmlToJavascriptViewState);
14+
this.modalPanel = atom.workspace.addModalPanel({
15+
item: this.htmlToJavascriptView.getElement(),
16+
visible: false
17+
});
18+
19+
// Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
20+
this.subscriptions = new CompositeDisposable();
21+
22+
// Register command that toggles this view
23+
this.subscriptions.add(atom.commands.add('atom-workspace', {
24+
'html-to-javascript:convert': () => this.convert()
25+
}));
26+
},
27+
28+
deactivate() {
29+
this.modalPanel.destroy();
30+
this.subscriptions.dispose();
31+
this.htmlToJavascriptView.destroy();
32+
},
33+
34+
serialize() {
35+
return {
36+
htmlToJavascriptViewState: this.htmlToJavascriptView.serialize()
37+
};
38+
},
39+
40+
convert() {
41+
var editor = atom.workspace.getActiveTextEditor();
42+
if (editor){
43+
var selection = editor.getSelectedText()
44+
if (!!!selection.trim()) return;
45+
46+
// # Replace all ' in file with \'
47+
selection = selection.replace(/'/g , "\\'");
48+
49+
// # Edit selection:
50+
var lines = selection.split("\n");
51+
52+
53+
54+
var js_string = "''+\n";
55+
// # Wrap beginning and end of lines with '
56+
// # (for the beginning of a line, put it at the beginning of the first non space)
57+
// # (for the end of a line, trim the end putting '+ at the end of the line)
58+
for (var i = 0; i < lines.length; i++) {
59+
var line = lines[i];
60+
61+
num_leading_whitespace = line.search(/\S|$/);
62+
var string_leading = '';
63+
if (num_leading_whitespace){
64+
for (var i = 0; i < num_leading_whitespace; i++) {
65+
string_leading += "\t";
66+
}
67+
}
68+
69+
js_string += string_leading + "'" + line.trim() + "'+\n";
70+
71+
}
72+
73+
editor.insertText(js_string.substring(0,js_string.length-2), {
74+
select: true
75+
}); //# Ignores the last 2 symbols "+\n"
76+
}
77+
78+
}
79+
80+
};

menus/atom-html-to-javascript.cson

Lines changed: 0 additions & 22 deletions
This file was deleted.

menus/html-to-javascript.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"context-menu": {
3+
"atom-text-editor": [
4+
{
5+
"label": "HTML -> JS",
6+
"command": "html-to-javascript:convert"
7+
}
8+
]
9+
},
10+
"menu": [
11+
{
12+
"label": "Packages",
13+
"submenu": [
14+
{
15+
"label": "html-to-javascript",
16+
"submenu": [
17+
{
18+
"label": "Convert HTML -> JS",
19+
"command": "html-to-javascript:convert"
20+
}
21+
]
22+
}
23+
]
24+
}
25+
]
26+
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "html-to-javascript",
3-
"main": "./lib/atom-html-to-javascript",
3+
"main": "./lib/html-to-javascript",
44
"version": "0.1.1",
55
"description": "HTML to Javascript as string, and vice versa.",
66
"keywords": [],
77
"activationCommands": {
8-
"atom-workspace": "atom-html-to-javascript:convert"
8+
"atom-workspace": "html-to-javascript:convert"
99
},
1010
"repository": "https://github.com/keevan/atom-html-to-javascript",
1111
"license": "MIT",

spec/atom-html-to-javascript-spec.coffee

Lines changed: 0 additions & 62 deletions
This file was deleted.

spec/atom-html-to-javascript-view-spec.coffee

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)