-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGistGen.rb
33 lines (24 loc) · 908 Bytes
/
GistGen.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require 'gist'
files=Dir["java-examples/*.java"]
destDir="content/Java-Code-Library/"
Gist.login!
files.each do |file|
rawJavaName = file.split('/')[1].strip;
step = rawJavaName.split('-')[0].strip.to_i;
newFile = destDir+rawJavaName.split(".java")[0].strip+".md";
title = rawJavaName[4..rawJavaName.size-6].tr("-"," ");
javaContent = File.open(file, "rb");
contents = javaContent.read;
ret = Gist.gist(contents, :filename=>title.tr(" ","")+".java", :public=>true);
#<script src="https://gist.github.com/madhephaestus/ad697c4b87b18bb494f9.js"></script>
id=ret["id"]
owner=ret["owner"]["login"]
gitsUrl = "<script src='https://gist.github.com/" +owner+"/"+id + ".js'></script>";
content = "---"+\
"\ntitle: "+title+\
"\nstep: "+step.to_s+\
"\nlayout: post"+\
"\n---"+\
"\n\n"+gitsUrl;
File.write(newFile, content)
end