Skip to content

Commit

Permalink
use through2
Browse files Browse the repository at this point in the history
  • Loading branch information
jarofghosts committed Apr 16, 2015
1 parent c1c5c1c commit bd0ec3b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
3 changes: 1 addition & 2 deletions README.md
@@ -1,5 +1,4 @@
html-ls
====
# html-ls

[![Build Status](http://img.shields.io/travis/jarofghosts/html-ls.svg?style=flat)](https://travis-ci.org/jarofghosts/html-ls)
[![npm install](http://img.shields.io/npm/dm/html-ls.svg?style=flat)](https://www.npmjs.org/package/html-ls)
Expand Down
31 changes: 20 additions & 11 deletions index.js
@@ -1,7 +1,7 @@
var path = require('path')
, util = require('util')

var through = require('through')
var through = require('through2')
, ls = require('ls-stream')

module.exports = lsHtml
Expand All @@ -24,31 +24,40 @@ function lsHtml(dir, _options) {
, dirs = []
, upDir

stream.queue(util.format('<%s>\n', options.parentTag))
stream.push(util.format('<%s>\n', options.parentTag))

if(options.showUp) {
upDir = path.dirname(dir) + '/'
stream.queue(util.format(
stream.push(util.format(
'<%s><a href="%s">..</a></%s>\n'
, options.childTag
, upDir
, options.childTag
))
}

ls(dir).pipe(through(onDir, done))
ls(dir).pipe(through.obj(onDir, done))

function onDir(data) {
if(!data || path.dirname(data.path) !== dir) return done()
if(options.hideDot && dotfile.test(path.basename(data.path))) return
function onDir(data, _, next) {
if(!data || path.dirname(data.path) !== dir) {
return done()
}

if(options.hideDot && dotfile.test(path.basename(data.path))) {
return next()
}

var objectName = path.basename(data.path)

if(data.stat.isDirectory()) {
return dirs.push(objectName + '/')
dirs.push(objectName + '/')

return next()
}

files.push(objectName)

next()
}

function done() {
Expand All @@ -64,8 +73,8 @@ function lsHtml(dir, _options) {
streamItem(entities[i])
}

stream.queue(util.format('</%s>\n', options.parentTag))
stream.queue(null)
stream.push(util.format('</%s>\n', options.parentTag))
stream.push(null)

function streamItem(objectName) {
var objectString = util.format(
Expand All @@ -76,7 +85,7 @@ function lsHtml(dir, _options) {
, options.childTag
)

stream.queue(objectString)
stream.push(objectString)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -21,10 +21,10 @@
"url": "https://github.com/jarofghosts/html-ls/issues"
},
"dependencies": {
"through": "2.3.4",
"ls-stream": "1.0.0"
"ls-stream": "1.0.0",
"through2": "^0.6.5"
},
"devDependencies": {
"tape": "2.12.3"
"tape": "^4.0.0"
}
}

0 comments on commit bd0ec3b

Please sign in to comment.