0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

テンプレートの読み込み

Last updated at Posted at 2015-05-19
var templateFolder="C:\\Users\\Nao\\Documents\\個人フォルダ\\90.テンプレート\\";

function readTemplate(fileName) {
	var fs = new ActiveXObject("Scripting.FileSystemObject");
	var fileName = templateFolder + fileName;
	var ts = fs.openTextFile(fileName);
	var template_text = ts.ReadAll();
	ts.close();
	return template_text;
}

function textReplace(text, word1, word2) {
	word1 = word1.replace(/[\r|\n]/g, "");
	word2 = word2.replace(/[\r|\n]/g, "");
	var text = text.replace(new RegExp(word1, "g"), word2);
	return text;
}

SelectAll();
var text = GetSelectedString(0);

var lines = text.split("\n");
for (var cnt = 0 in lines) {
	if (cnt == 0) {
		// 1行目はテンプレートファイル名とする
		template_file_name = lines[cnt];
		template_file_name = template_file_name.replace(/[\r|\n]/ig, "");
		template_file_name += ".tpl";
		template_text = readTemplate(template_file_name);
	} else {
		if (lines[cnt].match(/^(%.*%)=(.*)$/)) {
			r = lines[cnt].match(/^(%.*%)=(.*)$/);
			template_text = textReplace(template_text, r[1], r[2]);
		}
	}
}

ClipboardEmpty();
SetClipboardByFormat(template_text, 'CF_TEXT', 0, -1);

一行目がテンプレートのファイル名になるように改造。
出力はクリップボードに出力するようにした。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?