Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
persona
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hexang 息壤平台
persona
Commits
83f9e945
Commit
83f9e945
authored
12 years ago
by
Sean McArthur
Browse files
Options
Downloads
Patches
Plain Diff
split up create_templates script into a lib file
parent
ecb16aab
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/static/views.js
+3
-3
3 additions, 3 deletions
lib/static/views.js
lib/templates.js
+61
-0
61 additions, 0 deletions
lib/templates.js
scripts/create_templates.js
+10
-62
10 additions, 62 deletions
scripts/create_templates.js
with
74 additions
and
65 deletions
lib/static/views.js
+
3
−
3
View file @
83f9e945
...
...
@@ -232,11 +232,11 @@ exports.setup = function(app) {
// /common/js/templates.js is dynamically built each time
if
(
!
config
.
get
(
'
use_minified_resources
'
))
{
var
generateT
emplates
=
require
(
'
../
../scripts/create_
templates
'
);
var
t
emplates
=
require
(
'
../templates
'
);
var
dialogTemplatesPath
=
path
.
join
(
__dirname
,
'
../../resources/static/dialog/views
'
)
var
dialogTemplatesData
;
app
.
get
(
'
/common/js/templates.js
'
,
function
(
req
,
res
)
{
var
str
=
generateT
emplates
(
generate
Templates
.
RETURN
,
dialogTemplatesPath
);
var
str
=
t
emplates
.
generate
(
dialogTemplatesPath
);
if
(
str
)
dialogTemplatesData
=
str
;
res
.
send
(
dialogTemplatesData
);
...
...
@@ -245,7 +245,7 @@ exports.setup = function(app) {
var
siteTemplatesPath
=
path
.
join
(
__dirname
,
"
../../resources/views
"
);
var
siteTemplatesData
;
app
.
get
(
'
/test/mocks/site-templates.js
'
,
function
(
req
,
res
)
{
var
str
=
generateT
emplates
(
generate
Templates
.
RETURN
,
siteTemplatesPath
,
"
site/
"
);
var
str
=
t
emplates
.
generate
(
siteTemplatesPath
,
"
site/
"
);
if
(
str
)
siteTemplatesData
=
str
;
res
.
send
(
siteTemplatesData
);
...
...
This diff is collapsed.
Click to expand it.
lib/templates.js
0 → 100644
+
61
−
0
View file @
83f9e945
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const
fs
=
require
(
'
fs
'
),
path
=
require
(
'
path
'
),
ejs
=
require
(
'
ejs
'
),
config
=
require
(
'
./configuration
'
);
var
bundles
=
{};
exports
.
generate
=
function
generate
(
templatesDir
,
namePrefix
,
lastGen
)
{
if
(
!
namePrefix
)
namePrefix
=
""
;
var
bundle
=
bundles
[
templatesDir
]
||
(
bundles
[
templatesDir
]
=
{});
lastGen
=
lastGen
||
bundle
.
lastGen
||
0
;
var
templateData
=
bundle
.
data
;
var
fileNames
=
fs
.
readdirSync
(
templatesDir
);
var
templates
=
[];
// is a regen necessary?
try
{
for
(
var
i
=
0
;
i
<
fileNames
.
length
;
i
++
)
{
if
(
lastGen
<
fs
.
statSync
(
path
.
join
(
templatesDir
,
fileNames
[
i
])).
mtime
)
{
throw
"
newer
"
;
}
}
// no rebuild needed
console
.
log
(
"
templates [%s] up to date
"
,
templatesDir
);
return
templateData
;
}
catch
(
e
)
{
console
.
log
(
"
creating templates [%s]
"
,
templatesDir
);
}
for
(
var
index
=
0
,
max
=
fileNames
.
length
;
index
<
max
;
index
++
)
{
var
fileName
=
fileNames
[
index
];
if
(
fileName
.
match
(
/
\.
ejs$/
))
{
var
templateName
=
namePrefix
+
fileName
.
replace
(
/
\.
ejs/
,
''
);
var
templateText
=
fs
.
readFileSync
(
path
.
join
(
templatesDir
,
fileName
),
"
utf8
"
);
templates
[
templateName
]
=
ejs
.
compile
(
templateText
,
{
client
:
true
,
compileDebug
:
!
config
.
get
(
'
use_minified_resources
'
)
});
}
}
templateData
=
"
BrowserID.Templates = BrowserID.Templates || {};
"
;
for
(
var
t
in
templates
)
{
if
(
templates
.
hasOwnProperty
(
t
))
{
templateData
+=
"
\n
BrowserID.Templates['
"
+
t
+
"
'] =
"
+
String
(
templates
[
t
]);
}
}
bundle
.
lastGen
=
Date
.
now
();
bundle
.
data
=
templateData
;
return
templateData
;
};
This diff is collapsed.
Click to expand it.
scripts/create_templates.js
+
10
−
62
View file @
83f9e945
...
...
@@ -7,74 +7,22 @@
const
fs
=
require
(
"
fs
"
),
path
=
require
(
'
path
'
),
ejs
=
require
(
'
ejs
'
),
config
=
require
(
'
../lib/configuration
'
);
templates
=
require
(
'
../lib/templates
'
);
var
existsSync
=
fs
.
existsSync
||
path
.
existsSync
;
var
dir
=
process
.
env
.
TEMPLATE_DIR
||
process
.
cwd
();
var
output_dir
=
process
.
env
.
BUILD_DIR
||
dir
;
var
bundles
=
{};
function
generateTemplates
(
outputType
,
templatesDir
,
namePrefix
)
{
if
(
templatesDir
)
dir
=
templatesDir
;
if
(
!
namePrefix
)
namePrefix
=
""
;
var
bundle
=
bundles
[
templatesDir
]
||
(
bundles
[
templatesDir
]
=
{});
var
lastGen
=
bundle
.
lastGen
||
0
;
var
templateData
=
bundle
.
data
;
var
fileNames
=
fs
.
readdirSync
(
dir
);
var
templates
=
{};
// is a regen even neccesary?
try
{
if
(
outputType
!==
generateTemplates
.
RETURN
)
{
lastGen
=
fs
.
statSync
(
path
.
join
(
output_dir
,
"
templates.js
"
)).
mtime
;
}
for
(
var
i
=
0
;
i
<
fileNames
.
length
;
i
++
)
{
if
(
lastGen
<
fs
.
statSync
(
path
.
join
(
dir
,
fileNames
[
i
])).
mtime
)
{
throw
"
newer
"
;
}
};
// no rebuild needed
console
.
log
(
"
templates.js is up to date
"
);
return
templateData
;
}
catch
(
e
)
{
console
.
log
(
"
creating templates.js
"
);
}
for
(
var
index
=
0
,
max
=
fileNames
.
length
;
index
<
max
;
index
++
)
{
var
fileName
=
fileNames
[
index
];
if
(
fileName
.
match
(
/
\.
ejs$/
))
{
var
templateName
=
namePrefix
+
fileName
.
replace
(
/
\.
ejs/
,
''
);
var
templateText
=
fs
.
readFileSync
(
dir
+
"
/
"
+
fileName
,
"
utf8
"
);
templates
[
templateName
]
=
ejs
.
compile
(
templateText
,
{
client
:
true
,
compileDebug
:
!
config
.
get
(
'
use_minified_resources
'
)
});
}
}
templateData
=
"
BrowserID.Templates = BrowserID.Templates || {};
"
;
for
(
var
t
in
templates
)
{
if
(
templates
.
hasOwnProperty
(
t
))
{
templateData
+=
"
\n
BrowserID.Templates['
"
+
t
+
"
'] =
"
+
String
(
templates
[
t
]);
}
}
if
(
outputType
===
generateTemplates
.
RETURN
)
{
bundle
.
lastGen
=
Date
.
now
();
bundle
.
data
=
templateData
;
return
templateData
;
}
else
{
fs
.
writeFileSync
(
output_dir
+
"
/templates.js
"
,
templateData
,
"
utf8
"
);
var
outputFile
=
path
.
join
(
output_dir
,
"
templates.js
"
);
function
generateTemplates
()
{
var
lastGen
=
existsSync
(
outputFile
)
?
fs
.
statSync
(
outputFile
).
mtime
:
0
;
var
templateData
=
templates
.
generate
(
dir
,
null
,
lastGen
);
if
(
templateData
)
{
// no data most likely means we're already up-to-date
fs
.
writeFileSync
(
path
.
join
(
output_dir
,
"
templates.js
"
),
templateData
,
"
utf8
"
);
}
};
generateTemplates
.
FILE
=
0
;
generateTemplates
.
RETURN
=
1
;
// run or export the function
if
(
process
.
argv
[
1
]
===
__filename
)
generateTemplates
();
else
module
.
exports
=
generateTemplates
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment