Skip to content

Commit

Permalink
- add module / static path for including pug files
Browse files Browse the repository at this point in the history
  • Loading branch information
zbryikt committed Jan 30, 2021
1 parent cdfaae9 commit 58fe90c
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## 2.2.0

- add module / static path for including pug files


## 2.1.10

- trim i18n key when use to prevent confusion
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ additionally, use `intlbase` to wrap path with a i18n based relative path:
a(href=intlbase('/faq'))


## Pug Include Path

Use `@` to include files in modules:

include @/ldview/dist/ldview.pug

Use `@static` to include files under `static` folder:

include @static/assets/sample.pug


## TODO

* support both indir building or src / static building.
Expand Down
21 changes: 20 additions & 1 deletion bin/lib/build/pug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions lib/build/pug.ls
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@ lc = {i18n: {}}
md-options = html: {breaks: true, renderer: new marked.Renderer!}
marked.set-options md-options.html

resolve = (fn,src,opt) ->
if !/^@/.exec(fn) => return path.resolve(path.join(path.dirname(src), fn))
try
if /^@\//.exec(fn) =>
return require.resolve(fn.replace /^@\//, "")
else if /^@static\//.exec(fn) =>
return path.resolve(path.join(path.dirname(src), fn.replace(/^@static/,'/../../static/')))
catch e
throw new Error("no such file or directory: #fn")


pug-extapi = do
plugins: [{resolve}]
filters: do
'lsc': (text, opt) -> return livescript.compile(text,{bare:true,header:false})
'lson': (text, opt) -> return livescript.compile(text,{bare:true,header:false,json:true})
Expand Down
21 changes: 20 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "MIT",
"main": "bin/lib/index.js",
"description": "simple, quick template for bootstrap a page",
"version": "2.1.10",
"version": "2.2.0",
"homepage": "https://github.com/zbryikt/template",
"repository": {
"type": "git",
Expand Down Expand Up @@ -39,5 +39,8 @@
},
"bin": {
"server": "./bin/cli.js"
},
"devDependencies": {
"ldview": "^0.0.2"
}
}
3 changes: 3 additions & 0 deletions src/pug/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ html
div: :i18n i18n key
div= i18n("alternative:namespace-test")
div= intlbase("/")
include @/ldview/dist/ldview.pug
+scope("hi"): div include module pug with #[code @] works.
include @static/assets/sample.pug
1 change: 1 addition & 0 deletions static/assets/sample.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
div include with #[code @static] works.
2 changes: 1 addition & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
div.textContent = "livescript filter test";</script><script type="application/json">{
"output": "lson test ok"
}
</script><div>i18n 翻譯測試 ( 編譯時期, pug filter )</div><div>i18n 翻譯測試 ( 執行時期, pug function )</div><div>i18n 翻譯測試 ( 執行時期, pug function )</div><div>命名域測試成功.</div><div>/intl/zh-TW/</div></body></html>
</script><div>i18n 翻譯測試 ( 編譯時期, pug filter )</div><div>i18n 翻譯測試 ( 執行時期, pug function )</div><div>i18n 翻譯測試 ( 執行時期, pug function )</div><div>命名域測試成功.</div><div>/intl/zh-TW/</div><div ld-scope="hi"><div>include module pug with <code>@</code> works.</div></div><div>include with <code>@static</code> works.</div></body></html>
2 changes: 1 addition & 1 deletion static/intl/en/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
div.textContent = "livescript filter test";</script><script type="application/json">{
"output": "lson test ok"
}
</script><div>i18n translation test ( compile time filter )</div><div>i18n translation test ( runtime function )</div><div>i18n translation test ( runtime function )</div><div>namespace test ok.</div><div>/intl/en/</div></body></html>
</script><div>i18n translation test ( compile time filter )</div><div>i18n translation test ( runtime function )</div><div>i18n translation test ( runtime function )</div><div>namespace test ok.</div><div>/intl/en/</div><div ld-scope="hi"><div>include module pug with <code>@</code> works.</div></div><div>include with <code>@static</code> works.</div></body></html>
2 changes: 1 addition & 1 deletion static/intl/zh-TW/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
div.textContent = "livescript filter test";</script><script type="application/json">{
"output": "lson test ok"
}
</script><div>i18n 翻譯測試 ( 編譯時期, pug filter )</div><div>i18n 翻譯測試 ( 執行時期, pug function )</div><div>i18n 翻譯測試 ( 執行時期, pug function )</div><div>命名域測試成功.</div><div>/intl/zh-TW/</div></body></html>
</script><div>i18n 翻譯測試 ( 編譯時期, pug filter )</div><div>i18n 翻譯測試 ( 執行時期, pug function )</div><div>i18n 翻譯測試 ( 執行時期, pug function )</div><div>命名域測試成功.</div><div>/intl/zh-TW/</div><div ld-scope="hi"><div>include module pug with <code>@</code> works.</div></div><div>include with <code>@static</code> works.</div></body></html>

0 comments on commit 58fe90c

Please sign in to comment.