Module: Wesc

Defined in:
lib/wesc.rb,
lib/wesc/version.rb

Constant Summary collapse

VERSION =
"0.6.2"

Class Method Summary collapse

Class Method Details

.build(entry_points, outcss: nil, outjs: nil, minify: false) ⇒ String

Build the entry points and return the full HTML output as a (binary) String.

html = Wesc.build(["./index.html"], minify: true)

Parameters:

  • entry_points (Array<String>)

    entry point paths; the first is the host document.

  • outcss (String, nil) (defaults to: nil)

    optional path to write the bundled CSS file.

  • outjs (String, nil) (defaults to: nil)

    optional path to write the bundled JS file.

  • minify (Boolean) (defaults to: false)

    minify generated JS/CSS assets. Defaults to false.

Returns:

  • (String)

    the rendered HTML (ASCII-8BIT / binary encoding).



38
39
40
# File 'lib/wesc.rb', line 38

def build(entry_points, outcss: nil, outjs: nil, minify: false)
  Native.build(Array(entry_points), outcss, outjs, minify ? true : false)
end

.build_stream(entry_points, outcss: nil, outjs: nil, minify: false) {|chunk| ... } ⇒ void

This method returns an undefined value.

Stream the build to a block, chunk by chunk, for low-memory output.

The block is called with each chunk as a String, then once with ‘nil` to signal the end of the stream. Raising from the block stops the build and the exception propagates out of this method.

Wesc.build_stream(["./index.html"]) do |chunk|
  io.write(chunk) unless chunk.nil?
end

Parameters:

  • entry_points (Array<String>)

    entry point paths; the first is the host document.

  • outcss (String, nil) (defaults to: nil)

    optional path to write the bundled CSS file.

  • outjs (String, nil) (defaults to: nil)

    optional path to write the bundled JS file.

  • minify (Boolean) (defaults to: false)

    minify generated JS/CSS assets. Defaults to false.

Yield Parameters:

  • chunk (String, nil)

    each output chunk, then ‘nil` at end-of-stream.

Raises:

  • (ArgumentError)


59
60
61
62
63
# File 'lib/wesc.rb', line 59

def build_stream(entry_points, outcss: nil, outjs: nil, minify: false, &block)
  raise ArgumentError, "Wesc.build_stream requires a block" unless block

  Native.build_stream(Array(entry_points), outcss, outjs, minify ? true : false, &block)
end