Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
patternlibrary
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
js
patternlibrary
Commits
22873c21
Commit
22873c21
authored
Mar 20, 2018
by
Björn Bartels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PATLAB-7
add page-template tests
parent
6345db90
Changes
25
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
287 additions
and
89 deletions
+287
-89
patternlibrary.js
lib/patternlibrary.js
+36
-36
default.html
test/fixtures.templating/layout/layouts/default.html
+0
-0
mylayout.html
test/fixtures.templating/layout/layouts/mylayout.html
+0
-0
mypage.html
test/fixtures.templating/layout/pages/mypage.html
+0
-0
.gitkeep
test/fixtures.templating/layout/partials/.gitkeep
+0
-0
footer.html
test/fixtures.templating/layout/partials/footer.html
+0
-0
default.html
test/fixtures.templating/page-filename/layouts/default.html
+5
-0
mylayout.html
test/fixtures.templating/page-filename/layouts/mylayout.html
+6
-0
mypage.html
test/fixtures.templating/page-filename/pages/pl/mypage.html
+1
-0
.gitkeep
test/fixtures.templating/page-filename/partials/.gitkeep
+0
-0
footer.html
test/fixtures.templating/page-filename/partials/footer.html
+0
-0
index.html
...fixtures.templating/page-guipages/gui/pages/pl/index.html
+1
-0
mypage.html
...ixtures.templating/page-guipages/gui/pages/pl/mypage.html
+1
-0
default.html
test/fixtures.templating/page-guipages/layouts/default.html
+5
-0
mylayout.html
test/fixtures.templating/page-guipages/layouts/mylayout.html
+6
-0
otherpage.html
test/fixtures.templating/page-guipages/pages/otherpage.html
+1
-0
.gitkeep
test/fixtures.templating/page-guipages/partials/.gitkeep
+0
-0
footer.html
test/fixtures.templating/page-guipages/partials/footer.html
+0
-0
default.html
test/fixtures.templating/page-markdown/layouts/default.html
+5
-0
mylayout.html
test/fixtures.templating/page-markdown/layouts/mylayout.html
+6
-0
mypage.md
test/fixtures.templating/page-markdown/pages/mypage.md
+1
-0
.gitkeep
test/fixtures.templating/page-markdown/partials/.gitkeep
+0
-0
footer.html
test/fixtures.templating/page-markdown/partials/footer.html
+0
-0
test.10.basic-templating.js
test/test.10.basic-templating.js
+212
-52
test.90.handlebars.js
test/test.90.handlebars.js
+1
-1
No files found.
lib/patternlibrary.js
View file @
22873c21
...
...
@@ -97,7 +97,8 @@ class Patternlibrary {
* Retrieves (handlebars) page template
*
* if no page template is set yet, returns the default
* gui doc-page template
* gui doc-page templateto be used in a series of similar
* pages with iterating data
*
* it retrieves a compiled Handlebars template and
* returns the rendred page content when invoked
...
...
@@ -118,6 +119,8 @@ class Patternlibrary {
/**
* Sets and compiles (handlebars) page by page filename
* for a *Patternlibrary* page template to be used in a
* series of similar pages with iterating data
*
* if `page` is a '.md' or '.markdown' file, it is also
* passed through the markdown renderer
...
...
@@ -128,6 +131,14 @@ class Patternlibrary {
* var rendered = P.pagetemplate(pagevars);
* ```
*
* if the parameter does not correspond to a readable file
* the parameter's string value is assigned as page template
*
* look-up order:
* - project's doc pages dir (pages src dir + basepath)
* - project's `gui` pages dir
* - module's `gui` pages dir
* - file path
*
* @param {string} page - the file basename of the page-file
* @var {function} pagetemplate - a precompiled (handlebars) template
...
...
@@ -142,47 +153,36 @@ class Patternlibrary {
var
pagefile
=
path
.
join
(
this
.
options
.
root
,
this
.
options
.
basepath
,
page
);
var
guipage
=
resolvePath
(
path
.
join
(
this
.
options
.
gui
.
pages
,
this
.
options
.
basepath
,
page
));
try
{
if
(
!
fs
.
existsSync
(
pagefile
)
)
{
if
(
fs
.
existsSync
(
guipage
)
)
{
// file from gui pages
pageSource
=
fs
.
readFileSync
(
guipage
).
toString
();
}
else
{
if
(
fs
.
existsSync
(
pageSource
)
)
{
// file from `pageSource` as a file-path by it self
pageSource
=
fs
.
readFileSync
(
pageSource
).
toString
();
}
}
if
(
!
fs
.
existsSync
(
pagefile
)
)
{
if
(
fs
.
existsSync
(
guipage
)
)
{
// file from gui pages
pageSource
=
fs
.
readFileSync
(
guipage
).
toString
();
}
else
{
// file from pages
pageSource
=
fs
.
readFileSync
(
pagefile
).
toString
();
if
(
fs
.
existsSync
(
pageSource
)
)
{
// file from `pageSource` as a file-path by it self
pageSource
=
fs
.
readFileSync
(
pageSource
).
toString
();
}
}
}
catch
(
e
)
{
this
.
log
.
warn
(
'Error loading Patternlibrary pagefile "'
+
pagefile
+
'"'
);
throw
new
Error
(
e
.
message
);
}
}
else
{
// file from pages
pageSource
=
fs
.
readFileSync
(
pagefile
).
toString
(
);
}
}
// strip yml data in the beginning
pageSource
=
fm
(
pageSource
).
body
;
try
{
// finally compile Markdown content, if we have a markdown file here...
if
(
markdown
)
{
this
.
log
.
info
(
'Rendering Markdown content...'
);
// interestingly, just rendering with MarkdownIt seems to do too much escaping
// and renders some special characters useless for to be interpreted by
// Handlebars, like `{{> ...`, so we wrap it with Handlebars and let its
// MarkdownIt helper there do it...
pageSource
=
'{{#md}}'
+
pageSource
+
'{{/md}}'
;
}
}
catch
(
e
)
{
this
.
log
.
warn
(
'Error rendering Markdown content'
);
throw
new
Error
(
e
.
message
);
}
// finally compile Markdown content, if we have a markdown file here...
if
(
markdown
)
{
this
.
log
.
info
(
'Rendering Markdown content...'
);
// interestingly, just rendering with MarkdownIt seems to do too much escaping
// and renders some special characters useless for to be interpreted by
// Handlebars, like `{{> ...`, so we wrap it with Handlebars and let its
// MarkdownIt helper there do it...
pageSource
=
'{{#markdown}}'
+
pageSource
+
'{{/markdown}}'
;
}
this
.
_pageTemplate
=
this
.
handlebars
.
compile
(
pageSource
,
{
noEscape
:
true
});
}
...
...
test/fixtures.
core/basic
/layouts/default.html
→
test/fixtures.
templating/layout
/layouts/default.html
View file @
22873c21
File moved
test/fixtures.
core/basic
/layouts/mylayout.html
→
test/fixtures.
templating/layout
/layouts/mylayout.html
View file @
22873c21
File moved
test/fixtures.
core/basic
/pages/mypage.html
→
test/fixtures.
templating/layout
/pages/mypage.html
View file @
22873c21
File moved
test/fixtures.
core/basic
/partials/.gitkeep
→
test/fixtures.
templating/layout
/partials/.gitkeep
View file @
22873c21
File moved
test/fixtures.
core/basic
/partials/footer.html
→
test/fixtures.
templating/layout
/partials/footer.html
View file @
22873c21
File moved
test/fixtures.templating/page-filename/layouts/default.html
0 → 100644
View file @
22873c21
<html>
<body>
{{> body}}
</body>
</html>
test/fixtures.templating/page-filename/layouts/mylayout.html
0 → 100644
View file @
22873c21
<html>
<body>
<h1>
My Layout
</h1>
{{> body}}
</body>
</html>
test/fixtures.templating/page-filename/pages/pl/mypage.html
0 → 100644
View file @
22873c21
<p>
Body
</p>
test/fixtures.templating/page-filename/partials/.gitkeep
0 → 100644
View file @
22873c21
test/fixtures.templating/page-filename/partials/footer.html
0 → 100644
View file @
22873c21
test/fixtures.templating/page-guipages/gui/pages/pl/index.html
0 → 100644
View file @
22873c21
<p>
Patternlist
</p>
test/fixtures.templating/page-guipages/gui/pages/pl/mypage.html
0 → 100644
View file @
22873c21
<p>
Body
</p>
test/fixtures.templating/page-guipages/layouts/default.html
0 → 100644
View file @
22873c21
<html>
<body>
{{> body}}
</body>
</html>
test/fixtures.templating/page-guipages/layouts/mylayout.html
0 → 100644
View file @
22873c21
<html>
<body>
<h1>
My Layout
</h1>
{{> body}}
</body>
</html>
test/fixtures.templating/page-guipages/pages/otherpage.html
0 → 100644
View file @
22873c21
<p>
Body
</p>
test/fixtures.templating/page-guipages/partials/.gitkeep
0 → 100644
View file @
22873c21
test/fixtures.templating/page-guipages/partials/footer.html
0 → 100644
View file @
22873c21
test/fixtures.templating/page-markdown/layouts/default.html
0 → 100644
View file @
22873c21
<html>
<body>
{{> body}}
</body>
</html>
test/fixtures.templating/page-markdown/layouts/mylayout.html
0 → 100644
View file @
22873c21
<html>
<body>
<h1>
My Layout
</h1>
{{> body}}
</body>
</html>
test/fixtures.templating/page-markdown/pages/mypage.md
0 → 100644
View file @
22873c21
# Body
\ No newline at end of file
test/fixtures.templating/page-markdown/partials/.gitkeep
0 → 100644
View file @
22873c21
test/fixtures.templating/page-markdown/partials/footer.html
0 → 100644
View file @
22873c21
test/test.10.basic-templating.js
View file @
22873c21
This diff is collapsed.
Click to expand it.
test/test.90.handlebars.js
View file @
22873c21
...
...
@@ -204,7 +204,7 @@ describe('Patternlibrary built-in Handlebars helpers', () => {
});
describe
(
'{{md}}'
,
()
=>
{
it
(
'converts Markdown to HTML'
,
()
=>
{
it
(
'converts Markdown to HTML
(helper with parameter)
'
,
()
=>
{
compare
(
'{{md "**Bold**"}}'
,
'<p><strong>Bold</strong></p>
\
n'
);
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment