wesc 0.6.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +19 -11
- data/ext/wesc/Cargo.toml +2 -2
- data/ext/wesc/src/lib.rs +29 -11
- data/lib/wesc/version.rb +1 -1
- data/lib/wesc.rb +27 -13
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 47c2b769ea5ee8965966048474a3a7e7bd61a5f57aded42e5f17bd23c2a83b33
|
|
4
|
+
data.tar.gz: cb4939e9e701cf77b033ac27eb9f3a14b071806852c5315cd6bbec692fba0d3c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: de1dbfb74b637b3ef8476a489df630cfe8da2e73243f71e9b605dbfad5eab96ef358814584df32c66268575ac7006ab16ea98e6a7088b746cc73550d70e1ef2d
|
|
7
|
+
data.tar.gz: 2f5b3bd0ac049589f640e3c863b0688818c65ab04e4d49dd1538d5eba6f1a0756467e5c7efb85ed3922efb785141050f1c6fb51ab7573feb41fe30ce3184dd54
|
data/README.md
CHANGED
|
@@ -21,9 +21,13 @@ gem install wesc
|
|
|
21
21
|
```ruby
|
|
22
22
|
require "wesc"
|
|
23
23
|
|
|
24
|
-
# One-shot: returns the
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
# One-shot: returns a Wesc::Result with the HTML plus the bundled CSS/JS.
|
|
25
|
+
# Pass outcss:/outjs: to also get the bundles (an empty string keeps them in
|
|
26
|
+
# memory only; a path additionally writes the file).
|
|
27
|
+
result = Wesc.build(["./index.html"], outcss: "", outjs: "", minify: true)
|
|
28
|
+
puts "#{result.html.bytesize} bytes of HTML"
|
|
29
|
+
puts result.css # the bundled CSS (nil when outcss: was not requested)
|
|
30
|
+
puts result.js # the bundled JS (nil when outjs: was not requested)
|
|
27
31
|
|
|
28
32
|
# Streaming: low memory, chunk by chunk. The block receives each chunk as a
|
|
29
33
|
# String, then `nil` once to signal end-of-stream. Raising from the block
|
|
@@ -35,20 +39,24 @@ end
|
|
|
35
39
|
|
|
36
40
|
## API
|
|
37
41
|
|
|
38
|
-
- `Wesc.build(
|
|
39
|
-
- `Wesc.build_stream(
|
|
42
|
+
- `Wesc.build(input, outcss: nil, outjs: nil, minify: false) -> Wesc::Result`
|
|
43
|
+
- `Wesc.build_stream(input, outcss: nil, outjs: nil, minify: false) { |chunk| ... } -> nil`
|
|
40
44
|
|
|
41
45
|
| Argument | Type | Notes |
|
|
42
46
|
| -------------- | --------------------- | -------------------------------------------------- |
|
|
43
|
-
| `
|
|
44
|
-
| `outcss` | `String, nil` |
|
|
45
|
-
| `outjs` | `String, nil` |
|
|
47
|
+
| `input` | `Array<String>` | First entry is the host document. |
|
|
48
|
+
| `outcss` | `String, nil` | Request the bundled CSS. Path writes the file; `""` is in-memory only; `nil` skips. |
|
|
49
|
+
| `outjs` | `String, nil` | Request the bundled JS. Path writes the file; `""` is in-memory only; `nil` skips. |
|
|
46
50
|
| `minify` | `Boolean` | Minify generated assets. Defaults to `false`. |
|
|
47
51
|
| `&block` | `{ \|String, nil\| }` | `build_stream` only. Gets each chunk, then `nil`. |
|
|
48
52
|
|
|
49
|
-
`build` returns a
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
`build` returns a `Wesc::Result` (`Struct.new(:html, :css, :js)`): `html` is a
|
|
54
|
+
binary (`ASCII-8BIT`) `String`, and `css`/`js` are binary `String`s when
|
|
55
|
+
requested via `outcss`/`outjs` or `nil` otherwise. `outcss`/`outjs` still write
|
|
56
|
+
the bundle to disk when given a non-empty path; an empty string returns it in
|
|
57
|
+
memory only. `build_stream` yields each HTML chunk as a binary `String`, then
|
|
58
|
+
yields `nil` once to mark end-of-stream — the same trailing-`nil`/`None`
|
|
59
|
+
convention as the Python and PHP bindings.
|
|
52
60
|
|
|
53
61
|
> The bundler keeps a process-global file/template cache, so builds should not
|
|
54
62
|
> run concurrently within a single process — serialize them (the
|
data/ext/wesc/Cargo.toml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "wesc-rb"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.7.0" # x-release-please-version
|
|
4
4
|
authors = ["Wesley Luyten <me@wesleyluyten.com>"]
|
|
5
5
|
edition = "2021"
|
|
6
6
|
license = "MIT"
|
|
@@ -28,5 +28,5 @@ crate-type = ["cdylib"]
|
|
|
28
28
|
# the core crate's version (the marker keeps release-please bumping it in
|
|
29
29
|
# lockstep); otherwise the patched local 0.x core fails to satisfy it and the
|
|
30
30
|
# whole workspace stops resolving.
|
|
31
|
-
wesc = "0.
|
|
31
|
+
wesc = "0.7.0" # x-release-please-version
|
|
32
32
|
magnus = "0.7"
|
data/ext/wesc/src/lib.rs
CHANGED
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
//! wrapper split).
|
|
14
14
|
//!
|
|
15
15
|
//! Two entry points, matching how a server typically consumes a build:
|
|
16
|
-
//! - [`build`] — returns the full output as a (binary) `String
|
|
16
|
+
//! - [`build`] — returns the full HTML output as a (binary) `String`
|
|
17
|
+
//! plus the bundled CSS/JS (each `nil` when absent), as a 3-element array.
|
|
17
18
|
//! - [`build_stream`] — yields each chunk to the block (low memory). The block
|
|
18
19
|
//! runs in Ruby, then receives `nil` once to signal end-of-stream.
|
|
19
20
|
//!
|
|
@@ -31,38 +32,51 @@ use wesc::{build as wesc_build, BuildOptions};
|
|
|
31
32
|
|
|
32
33
|
/// Assemble [`BuildOptions`] from the native (positional) arguments.
|
|
33
34
|
fn collect_options(
|
|
34
|
-
|
|
35
|
+
input: Vec<String>,
|
|
35
36
|
outcss: Option<String>,
|
|
36
37
|
outjs: Option<String>,
|
|
37
38
|
minify: bool,
|
|
38
39
|
) -> BuildOptions {
|
|
39
40
|
BuildOptions {
|
|
40
|
-
|
|
41
|
+
input,
|
|
42
|
+
source: None,
|
|
41
43
|
outcss,
|
|
42
44
|
outjs,
|
|
45
|
+
cwd: None,
|
|
43
46
|
minify,
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
49
|
|
|
47
|
-
/// Build the entry points and return the full HTML output
|
|
50
|
+
/// Build the entry points and return the full HTML output plus the bundled
|
|
51
|
+
/// CSS/JS.
|
|
52
|
+
///
|
|
53
|
+
/// Returns a 3-tuple `(html, css, js)` — Magnus converts it to a Ruby array,
|
|
54
|
+
/// and each `None` to `nil`. `html` is always present (a binary `String`); the
|
|
55
|
+
/// CSS/JS are bundled and returned when requested via `outcss`/`outjs` and
|
|
56
|
+
/// `nil` otherwise. A non-empty `outcss`/`outjs` path additionally writes the
|
|
57
|
+
/// bundle to disk; an empty string returns it in memory only.
|
|
48
58
|
///
|
|
49
59
|
/// Exposed to Ruby as `Wesc::Native.build`; see `Wesc.build` in `lib/wesc.rb`
|
|
50
60
|
/// for the public keyword-argument API.
|
|
51
61
|
fn build(
|
|
52
62
|
ruby: &Ruby,
|
|
53
|
-
|
|
63
|
+
input: Vec<String>,
|
|
54
64
|
outcss: Option<String>,
|
|
55
65
|
outjs: Option<String>,
|
|
56
66
|
minify: bool,
|
|
57
|
-
) -> RString {
|
|
58
|
-
let options = collect_options(
|
|
67
|
+
) -> (RString, Option<RString>, Option<RString>) {
|
|
68
|
+
let options = collect_options(input, outcss, outjs, minify);
|
|
59
69
|
|
|
60
70
|
let mut output: Vec<u8> = Vec::new();
|
|
61
|
-
wesc_build(options, &mut |chunk: &[u8]| {
|
|
71
|
+
let assets = wesc_build(options, &mut |chunk: &[u8]| {
|
|
62
72
|
output.extend_from_slice(chunk);
|
|
63
73
|
});
|
|
64
74
|
|
|
65
|
-
ruby.str_from_slice(&output)
|
|
75
|
+
let html = ruby.str_from_slice(&output);
|
|
76
|
+
let css = assets.css.map(|css| ruby.str_new(&css));
|
|
77
|
+
let js = assets.js.map(|js| ruby.str_new(&js));
|
|
78
|
+
|
|
79
|
+
(html, css, js)
|
|
66
80
|
}
|
|
67
81
|
|
|
68
82
|
/// Stream the build to the block, chunk by chunk, for low-memory output.
|
|
@@ -71,17 +85,21 @@ fn build(
|
|
|
71
85
|
/// `String`, then once with `nil` to signal the end of the stream. If the block
|
|
72
86
|
/// raises, no further chunks are delivered and the exception propagates out.
|
|
73
87
|
///
|
|
88
|
+
/// HTML only: this streams just the markup. A non-empty `outcss`/`outjs` path
|
|
89
|
+
/// still bundles and writes the CSS/JS to disk (the in-memory assets are not
|
|
90
|
+
/// returned here — use [`build`] for those).
|
|
91
|
+
///
|
|
74
92
|
/// Exposed to Ruby as `Wesc::Native.build_stream`; see `Wesc.build_stream` in
|
|
75
93
|
/// `lib/wesc.rb` for the public keyword-argument API.
|
|
76
94
|
fn build_stream(
|
|
77
95
|
ruby: &Ruby,
|
|
78
|
-
|
|
96
|
+
input: Vec<String>,
|
|
79
97
|
outcss: Option<String>,
|
|
80
98
|
outjs: Option<String>,
|
|
81
99
|
minify: bool,
|
|
82
100
|
) -> Result<(), Error> {
|
|
83
101
|
let block = ruby.block_proc()?;
|
|
84
|
-
let options = collect_options(
|
|
102
|
+
let options = collect_options(input, outcss, outjs, minify);
|
|
85
103
|
|
|
86
104
|
// Remember the first block error so we can stop yielding and surface it.
|
|
87
105
|
let mut pending_error: Option<Error> = None;
|
data/lib/wesc/version.rb
CHANGED
data/lib/wesc.rb
CHANGED
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
#
|
|
9
9
|
# require "wesc"
|
|
10
10
|
#
|
|
11
|
-
# # One-shot: returns the
|
|
12
|
-
#
|
|
11
|
+
# # One-shot: returns a Wesc::Result with the HTML plus the bundled CSS/JS.
|
|
12
|
+
# result = Wesc.build(["./index.html"], minify: true)
|
|
13
|
+
# result.html # => the rendered HTML (binary String)
|
|
13
14
|
#
|
|
14
15
|
# # Streaming: low memory, chunk by chunk. The block gets each chunk as a
|
|
15
16
|
# # String, then `nil` once to signal end-of-stream.
|
|
@@ -23,20 +24,33 @@ require_relative "wesc/version"
|
|
|
23
24
|
require_relative "wesc/wesc_rb"
|
|
24
25
|
|
|
25
26
|
module Wesc
|
|
27
|
+
# The result of a one-shot {Wesc.build}: the rendered +html+ plus the bundled
|
|
28
|
+
# +css+/+js+. The CSS/JS are populated when requested via `outcss`/`outjs`
|
|
29
|
+
# (an empty string keeps them in memory only; a path also writes the file) and
|
|
30
|
+
# are `nil` otherwise.
|
|
31
|
+
Result = Struct.new(:html, :css, :js)
|
|
32
|
+
|
|
26
33
|
module_function
|
|
27
34
|
|
|
28
|
-
# Build the entry points and return
|
|
35
|
+
# Build the entry points and return a {Wesc::Result}.
|
|
29
36
|
#
|
|
30
|
-
#
|
|
37
|
+
# result = Wesc.build(["./index.html"], minify: true)
|
|
38
|
+
# result.html # => the rendered HTML (binary String)
|
|
39
|
+
# result.css # => the bundled CSS, or nil
|
|
40
|
+
# result.js # => the bundled JS, or nil
|
|
31
41
|
#
|
|
32
|
-
# @param
|
|
42
|
+
# @param input [Array<String>] entry point paths; the first is the host
|
|
33
43
|
# document.
|
|
34
|
-
# @param outcss [String, nil]
|
|
35
|
-
#
|
|
44
|
+
# @param outcss [String, nil] request the bundled CSS. A non-empty path also
|
|
45
|
+
# writes the file; an empty string keeps it in memory only; `nil` skips it.
|
|
46
|
+
# @param outjs [String, nil] request the bundled JS. A non-empty path also
|
|
47
|
+
# writes the file; an empty string keeps it in memory only; `nil` skips it.
|
|
36
48
|
# @param minify [Boolean] minify generated JS/CSS assets. Defaults to false.
|
|
37
|
-
# @return [
|
|
38
|
-
|
|
39
|
-
|
|
49
|
+
# @return [Wesc::Result] the rendered HTML (ASCII-8BIT / binary encoding) plus
|
|
50
|
+
# the bundled CSS/JS (each `nil` when not requested).
|
|
51
|
+
def build(input, outcss: nil, outjs: nil, minify: false)
|
|
52
|
+
html, css, js = Native.build(Array(input), outcss, outjs, minify ? true : false)
|
|
53
|
+
Result.new(html, css, js)
|
|
40
54
|
end
|
|
41
55
|
|
|
42
56
|
# Stream the build to a block, chunk by chunk, for low-memory output.
|
|
@@ -49,16 +63,16 @@ module Wesc
|
|
|
49
63
|
# io.write(chunk) unless chunk.nil?
|
|
50
64
|
# end
|
|
51
65
|
#
|
|
52
|
-
# @param
|
|
66
|
+
# @param input [Array<String>] entry point paths; the first is the host
|
|
53
67
|
# document.
|
|
54
68
|
# @param outcss [String, nil] optional path to write the bundled CSS file.
|
|
55
69
|
# @param outjs [String, nil] optional path to write the bundled JS file.
|
|
56
70
|
# @param minify [Boolean] minify generated JS/CSS assets. Defaults to false.
|
|
57
71
|
# @yieldparam chunk [String, nil] each output chunk, then `nil` at end-of-stream.
|
|
58
72
|
# @return [void]
|
|
59
|
-
def build_stream(
|
|
73
|
+
def build_stream(input, outcss: nil, outjs: nil, minify: false, &block)
|
|
60
74
|
raise ArgumentError, "Wesc.build_stream requires a block" unless block
|
|
61
75
|
|
|
62
|
-
Native.build_stream(Array(
|
|
76
|
+
Native.build_stream(Array(input), outcss, outjs, minify ? true : false, &block)
|
|
63
77
|
end
|
|
64
78
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: wesc
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Wesley Luyten
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-06-
|
|
11
|
+
date: 2026-06-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rb_sys
|