Module: Wesc

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

Defined Under Namespace

Classes: Result

Constant Summary collapse

VERSION =
"0.7.0"

Class Method Summary collapse

Class Method Details

.build(input, outcss: nil, outjs: nil, minify: false) ⇒ Wesc::Result

Build the entry points and return a Result.

result = Wesc.build(["./index.html"], minify: true)
result.html # => the rendered HTML (binary String)
result.css  # => the bundled CSS, or nil
result.js   # => the bundled JS, or nil

Parameters:

  • input (Array<String>)

    entry point paths; the first is the host document.

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

    request the bundled CSS. A non-empty path also writes the file; an empty string keeps it in memory only; ‘nil` skips it.

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

    request the bundled JS. A non-empty path also writes the file; an empty string keeps it in memory only; ‘nil` skips it.

  • minify (Boolean) (defaults to: false)

    minify generated JS/CSS assets. Defaults to false.

Returns:

  • (Wesc::Result)

    the rendered HTML (ASCII-8BIT / binary encoding) plus the bundled CSS/JS (each ‘nil` when not requested).



51
52
53
54
# File 'lib/wesc.rb', line 51

def build(input, outcss: nil, outjs: nil, minify: false)
  html, css, js = Native.build(Array(input), outcss, outjs, minify ? true : false)
  Result.new(html, css, js)
end

.build_stream(input, 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:

  • input (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)


73
74
75
76
77
# File 'lib/wesc.rb', line 73

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

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