hyperstream

stream html into html at a css selector

  • 所有者: substack/hyperstream
  • 平台:
  • 許可證: Other
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

hyperstream

stream html into html at a css selector

build status

example

var hyperstream = require('hyperstream');
var fs = require('fs');

var hs = hyperstream({
    '#a': fs.createReadStream(__dirname + '/a.html'),
    '#b': fs.createReadStream(__dirname + '/b.html')
});
var rs = fs.createReadStream(__dirname + '/index.html');
rs.pipe(hs).pipe(process.stdout);
$ node example/hs.js
<html>
  <body>
    <div id="a"><h1>a!!!</h1></div>
    <div id="b"><b>bbbbbbbbbbbbbbbbbbbbbb</b></div>
  </body>
</html>

methods

var hyperstream = require('hyperstream')

var hs = hyperstream(streamMap)

Return a duplex stream that takes an html stream as input and produces an html
stream as output, inserting the streams given by streamMap at the css selector
keys.

If streamMap values are strings or functions, update the contents at the css
selector key with their contents directly without using a stream.

If streamMap values are non-stream objects, iterate over the keys and set
attributes for each key.

These attributes are special. Each attribute can be a string, buffer, or stream:

  • _html - set the inner content as raw html
  • _text - set the inner content as text encoded as html entities
  • _append, _appendText - add text to the end of the inner content encoded as
    html entities
  • _appendHtml - add raw html to the end of the inner content
  • _prepend, _prependText - add text to the beginning of the inner content
    encoded as html entities
  • _prependHtml - add raw html to the beginning of the inner context

For example, to set raw html into the inner content with the _html attribute,
do:

hyperstream({
    '#content': {
        _html: stream,
        'data-start': 'cats!',
        'data-end': 'cats!\ufff'
    }
})

You can also specify string operations for properties with an object instead of
a string. The object can have these properties:

  • append
  • prepend

Object properties are particularly handy for adding classes:

hyperstream({
    '.row': {
        class: { append: ' active' }
    }
})

which turns:

<div class="row"><b>woo</b></div>

into:

<div class="row active"><b>woo</b></div>

hs.select(), hs.update(), hs.replace(), hs.remove()

Proxy through methods to the underlying
trumpet instance.

install

With npm do:

npm install hyperstream

license

MIT

主要指標

概覽
名稱與所有者substack/hyperstream
主編程語言JavaScript
編程語言JavaScript (語言數: 1)
平台
許可證Other
所有者活动
創建於2013-01-02 02:43:05
推送於2016-02-26 16:05:50
最后一次提交2014-11-19 13:57:08
發布數17
最新版本名稱1.2.2 (發布於 2014-11-19 13:57:08)
第一版名稱0.0.0 (發布於 2013-01-01 18:47:09)
用户参与
星數185
關注者數11
派生數10
提交數96
已啟用問題?
問題數4
打開的問題數2
拉請求數3
打開的拉請求數2
關閉的拉請求數4
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?