Skip to content
This repository was archived by the owner on Dec 12, 2021. It is now read-only.

Commit 01108f7

Browse files
author
Max Schmidt
committed
Merge branch 'dev'
2 parents 89c3128 + f198618 commit 01108f7

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

lib/snippet-injector.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export default {
3636

3737
create() {
3838
var selection = atom.workspace.getActiveTextEditor().getSelectedText();
39+
var grammar = atom.workspace.getActiveTextEditor().getGrammar();
3940
var storage = this.storage;
4041
const inputPrompt = Util.promptUser({
4142
placeholder: 'Enter snippet title',
@@ -46,7 +47,8 @@ export default {
4647
var result = storage.store(new Snippet({
4748
title: text,
4849
tags: new Array(),
49-
content: selection
50+
content: selection,
51+
lang: grammar
5052
}));
5153
if(result) {
5254
atom.notifications.addSuccess('Snippet "'+text+'" was saved successfully.', null);

lib/snippet.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ export default class Snippet {
55
content = '';
66
title = '';
77
tags = new Array();
8+
lang = '';
89

910
constructor(state) {
1011
if(state !== undefined && state !== null && typeof state === 'object') {
1112
this.title = state.title;
1213
this.tags = state.tags;
1314
this.content = state.content;
15+
this.lang = state.lang;
1416
} else {
1517
this.title = "";
1618
this.tags = new Array();
1719
this.content = "";
20+
tis.lang = "";
1821
}
1922
}
2023

@@ -23,14 +26,15 @@ export default class Snippet {
2326
return {
2427
'title':this.title,
2528
'tags':this.tags,
26-
'content':this.content
29+
'content':this.content,
30+
'lang':this.lang
2731
};
2832
}
2933

3034
// Tear down any state and detach
3135
destroy() {}
3236

33-
37+
3438
getTitle() {
3539
return this.title;
3640
}
@@ -43,4 +47,7 @@ export default class Snippet {
4347
return this.tags;
4448
}
4549

50+
getLang() {
51+
return this.lang;
52+
}
4653
}

lib/storage.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,19 @@ export default class Storage {
2828
destroy() {}
2929

3030
init(directory) {
31-
this.dir = directory;
32-
try {
33-
fs.statSync(this.storageDir+this.dir);
34-
} catch(e) {
35-
fs.mkdirSync(this.storageDir+this.dir);
36-
}
31+
var temp = '\\';
32+
var store = this.storageDir;
33+
directory.split('/').join('\\').split('\\').forEach(function(currentValue,index) {
34+
if(currentValue !== "" && currentValue !== " " && currentValue !== null && currentValue !== undefined) {
35+
temp += currentValue+'\\';
36+
try {
37+
fs.statSync(store+temp);
38+
} catch(e) {
39+
fs.mkdirSync(store+temp);
40+
}
41+
}
42+
});
43+
this.dir = temp;
3744
}
3845

3946
store(snippet) {

0 commit comments

Comments
 (0)