8000 [refactor] simplify template format. · zhangzhishan/leetcode-cli@167fa23 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 167fa23

Browse files
committed
[refactor] simplify template format.
Signed-off-by: Eric Wang <skygragon@gmail.com>
1 parent fb5f597 commit 167fa23

File tree

5 files changed

+33
-19
lines changed

5 files changed

+33
-19
lines changed

lib/cli.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ function initLogLevel() {
5454
}
5555

5656
function initDir() {
57+
file.init();
5758
file.mkdir(file.homeDir())
5859
}
5960

lib/file.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ var mkdirp = require('mkdirp');
77

88
const file = {}
99

10+
file.init = function() {
11+
_.templateSettings = {
12+
evaluate: /\{\{(.+?)\}\}/g,
13+
interpolate: /\$\{(.+?)\}/g
14+
};
15+
};
16+
1017
file.isWindows = function() {
1118
return process.platform === 'win32';
1219
};

templates/codeonly.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<%= code %>
1+
${code}

templates/detailed.tpl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
<%= comment.start %>
2-
<%= comment.line %> @lc app=<%= app %> id=<%= fid %> lang=<%= lang %>
3-
<%= comment.line %>
4-
<%= comment.line %> [<%= fid %>] <%= name %>
5-
<%= comment.line %>
6-
<%= comment.line %> <%= link %>
7-
<%= comment.line %>
8-
<%= comment.line %> <%= category %>
9-
<%= comment.line %> <%= level %> (<%= percent %>%)
10-
<%= comment.line %> Total Accepted: <%= totalAC %>
11-
<%= comment.line %> Total Submissions: <%= totalSubmit %>
12-
<%= comment.line %> Testcase Example: <%= testcase %>
13-
<%= comment.line %>
14-
<% desc.forEach(function(x) { %><%= comment.line %> <%= x %>
15-
<% }) %><%= comment.end %>
16-
<%= code %>
1+
${comment.start}
2+
${comment.line} @lc app=${app} id=${fid} lang=${lang}
3+
${comment.line}
4+
${comment.line} [${fid}] ${name}
5+
${comment.line}
6+
${comment.line} ${link}
7+
${comment.line}
8+
${comment.line} ${category}
9+
${comment.line} ${level} (${percent}%)
10+
${comment.line} Total Accepted: ${totalAC}
11+
${comment.line} Total Submissions: ${totalSubmit}
12+
${comment.line} Testcase Example: ${testcase}
13+
${comment.line}
14+
{{ desc.forEach(function(x) { }}${comment.line} ${x}
15+
{{ }) }}${comment.end}
16+
${code}

test/test_core.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ describe('core', function() {
142142
}); // #starProblem
143143

144144
describe('#exportProblem', function() {
145+
let file;
146+
147+
beforeEach(function() {
148+
file = rewire('../lib/file');
149+
file.init();
150+
core.__set__('file', file);
151+
});
152+
145153
it('should codeonly ok', function() {
146154
const expected = [
147155
'/**',
@@ -171,9 +179,7 @@ describe('core', function() {
171179
});
172180

173181
it('should codeonly ok in windows', function() {
174-
const file = rewire('../lib/file');
175182
file.isWindows = () => true;
176-
core.__set__('file', file);
177183

178184
const expected = [
179185
'/**',

0 commit comments

Comments
 (0)
0