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

Commit ab1e50b

Browse files
committed
Merge branch 'dev'
2 parents 36c89f2 + a717ea9 commit ab1e50b

File tree

5 files changed

+94
-7
lines changed

5 files changed

+94
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
- Snippet tag functionalities
99
- Edit option for snippets
1010
- IMEX module: *(Import & Export)*
11-
- CSV ~ *Simple spreadsheet format* `importable`
11+
- .CSV ~ Simple spreadsheet format `importable`
12+
- .MD ~ Markdown file `unimportable`
1213
#### Improvements
1314
- Quick Start Guide enhanced
1415
- `README.md`

lib/db/imex.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"name": "CSV File",
77
"extensions": ["csv"]
88
},
9+
"labeling": "headline",
910
"labels": [
1011
"Title",
1112
"Author",
@@ -50,5 +51,32 @@
5051
"field": ";",
5152
"line": "\n"
5253
}
54+
},
55+
{
56+
"name": "md",
57+
"importable": false,
58+
"dialogOptions": {
59+
"name": "Markdown",
60+
"extensions": ["md"]
61+
},
62+
"labeling": "inline",
63+
"labels": [
64+
{"prefix":"## ","suffix":""},
65+
{"prefix":"**by ","suffix":"**"},
66+
{"prefix":"```\n","suffix":"```"},
67+
{"prefix":"*written in* ","suffix":""},
68+
{"prefix":"Tags:","suffix":""}
69+
],
70+
"order": [
71+
"title",
72+
"author",
73+
"content",
74+
"lang",
75+
"tags"
76+
],
77+
"divider": {
78+
"field": "\n",
79+
"line": "\n\n---\n\n"
80+
}
5381
}
5482
]

lib/imex.js

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export default class IMEX {
3434
case 'csv':
3535
return this._expcsv();
3636
break;
37+
case 'md':
38+
return this._expmd();
39+
break;
3740
default:
3841
return false;
3942
}
@@ -125,11 +128,9 @@ export default class IMEX {
125128
});
126129

127130
var filters = new Array();
128-
this.data.forEach(function(e) {
129-
filters.push({
130-
name: e.dialogOptions.name,
131-
extensions: e.dialogOptions.extensions
132-
});
131+
filters.push({
132+
name: config.dialogOptions.name,
133+
extensions: config.dialogOptions.extensions
133134
});
134135
filters.push({name: 'Any File', extensions: ['*']});
135136

@@ -154,6 +155,58 @@ export default class IMEX {
154155
}
155156
}
156157

158+
_expmd() {
159+
var storage = this.store;
160+
var config = this.data.filter(function(e) {
161+
if(e.name === 'md') {
162+
return true;
163+
} else {
164+
return false;
165+
}
166+
})[0];
167+
var files = storage.retrieveFiles();
168+
var md_string = '';
169+
170+
if(files.length > 0) {
171+
files.forEach(function(element,index,array) {
172+
var snippet = new Snippet(JSON.parse(storage.retrieveFile(element.replace('.json',''))));
173+
config.order.forEach(function(e,i,a) {
174+
md_string += config.labels[i].prefix;
175+
md_string += snippet._get(e);
176+
md_string += config.labels[i].suffix;
177+
md_string += config.divider.field;
178+
});
179+
md_string += config.divider.line;
180+
});
181+
182+
var filters = new Array();
183+
filters.push({
184+
name: config.dialogOptions.name,
185+
extensions: config.dialogOptions.extensions
186+
});
187+
filters.push({name: 'Any File', extensions: ['*']});
188+
189+
dialog.showSaveDialog({
190+
buttonLabel: 'Export',
191+
filters: filters
192+
},function(filename) {
193+
if(Util.isset(filename,'string')) {
194+
fs.writeFileSync(filename,md_string);
195+
if(fs.existsSync(filename)) {
196+
atom.notifications.addSuccess('Successfully exported the local storage to chosen location.', null);
197+
return true;
198+
} else {
199+
atom.notifications.addError('An Error occured while exporting the local storage.', null);
200+
return false;
201+
}
202+
}
203+
});
204+
} else {
205+
atom.notifications.addWarning('The local storage is empty, therefore it can\'t be exported.', options)
206+
return false;
207+
}
208+
}
209+
157210
_impcsv(filename) {
158211
var storage = this.store;
159212
var config = this.data.filter(function(e) {

lib/snippet-injector.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export default {
5656
// IMEX commmands
5757
this.subscriptions.add(atom.commands.add('atom-workspace', {
5858
'snippet-injector:export-to-csv': function() {_this.imex_module.storage_export('csv')},
59+
'snippet-injector:export-to-md': function() {_this.imex_module.storage_export('md')},
5960
'snippet-injector:import': function() {_this.imex_module.storage_import()}
6061
}));
6162

menus/snippet-injector.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@
5555
"label": "Export Snippets",
5656
"submenu": [
5757
{
58-
"label": "CSV",
58+
"label": "Spreadsheet",
5959
"command": "snippet-injector:export-to-csv"
60+
},
61+
{
62+
"label": "Markdown",
63+
"command": "snippet-injector:export-to-md"
6064
}
6165
]
6266
},

0 commit comments

Comments
 (0)