Skip to content

Commit

Permalink
Changed base to use javascript instead of coffeescript
Browse files Browse the repository at this point in the history
  • Loading branch information
keevan committed Aug 4, 2016
1 parent b98f71b commit c90c2f6
Show file tree
Hide file tree
Showing 16 changed files with 233 additions and 175 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
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.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# html-to-javascript package
# html-to-javascript

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

11 changes: 0 additions & 11 deletions keymaps/atom-html-to-javascript.cson

This file was deleted.

5 changes: 5 additions & 0 deletions keymaps/html-to-javascript.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"atom-workspace": {
"ctrl-shift-j": "html-to-javascript:convert"
}
}
22 changes: 0 additions & 22 deletions lib/atom-html-to-javascript-view.coffee

This file was deleted.

45 changes: 0 additions & 45 deletions lib/atom-html-to-javascript.coffee

This file was deleted.

29 changes: 29 additions & 0 deletions lib/html-to-javascript-view.js
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;
}

}
80 changes: 80 additions & 0 deletions lib/html-to-javascript.js
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"
}

}

};
22 changes: 0 additions & 22 deletions menus/atom-html-to-javascript.cson

This file was deleted.

26 changes: 26 additions & 0 deletions menus/html-to-javascript.json
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"
}
]
}
]
}
]
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "html-to-javascript",
"main": "./lib/atom-html-to-javascript",
"main": "./lib/html-to-javascript",
"version": "0.1.1",
"description": "HTML to Javascript as string, and vice versa.",
"keywords": [],
"activationCommands": {
"atom-workspace": "atom-html-to-javascript:convert"
"atom-workspace": "html-to-javascript:convert"
},
"repository": "https://github.com/keevan/atom-html-to-javascript",
"license": "MIT",
Expand Down
62 changes: 0 additions & 62 deletions spec/atom-html-to-javascript-spec.coffee

This file was deleted.

5 changes: 0 additions & 5 deletions spec/atom-html-to-javascript-view-spec.coffee

This file was deleted.

Loading

0 comments on commit c90c2f6

Please sign in to comment.