neft
Version:
JavaScript. Everywhere.
65 lines (43 loc) • 1.36 kB
text/coffeescript
Tag used to link *neft:fragment*s from a file and use them.
```xml
<neft:require href="./user_utils.html" />
<use:avatar />
```
Optional argument `as` will link all fragments into the specified namespace.
```xml
<neft:require href="./user_utils.html" as="user" />
<use:user:avatar />
```
'use strict'
pathUtils = require 'path'
module.exports = (File) -> (file) ->
links = []
{children} = file.node
i = -1
n = children.length
while ++i < n
node = children[i]
if node.name isnt "#{File.HTML_NS}:require"
continue
href = node.attrs.href or node.attrs.src
unless href then continue
namespace = node.attrs.as
path = getFilePath File, file, href
links.push
path: path
namespace: namespace
links
getFilePath = module.exports.getFilePath = (File, file, path) ->
if pathUtils.isAbsolute(path)
return path
if path[0] is '.' and path[1] is '/'
dirname = pathUtils.dirname file.path
return pathUtils.join(dirname, path)
pathUtils.join File.FILES_PATH, path
- [neft:require](