File tree 3 files changed +48
-0
lines changed
3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 2
2
# will have compiled files and executables
3
3
/target /
4
4
5
+ wasm /target
6
+
5
7
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
6
8
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
7
9
Cargo.lock
Original file line number Diff line number Diff line change
1
+ [package ]
2
+ name = " css-inline-wasm"
3
+ version = " 0.3.0"
4
+ authors = [
" Dmitry Dygalo <[email protected] >" ]
5
+ edition = " 2018"
6
+
7
+ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8
+
9
+ [lib ]
10
+ name = " css_inline"
11
+ crate-type = [" cdylib" ]
12
+
13
+ [dependencies .css-inline ]
14
+ path = " .."
15
+ version = " = 0.3.3"
16
+ default-features = false
17
+
18
+ [dependencies ]
19
+ wasm-bindgen = " 0.2"
Original file line number Diff line number Diff line change
1
+ use css_inline as rust_inline;
2
+ use wasm_bindgen:: prelude:: * ;
3
+
4
+ struct InlineErrorWrapper ( rust_inline:: InlineError ) ;
5
+
6
+ impl From < InlineErrorWrapper > for JsValue {
7
+ fn from ( error : InlineErrorWrapper ) -> Self {
8
+ JsValue :: from_str ( error. 0 . to_string ( ) . as_str ( ) )
9
+ }
10
+ }
11
+
12
+ #[ wasm_bindgen]
13
+ pub fn inline (
14
+ html : & str ,
15
+ options : rust_inline:: InlineOptions ,
16
+ ) -> Result < String , JsValue > {
17
+ let default_options = rust_inline:: CSSInliner :: default ( ) ;
18
+ let options = rust_inline:: InlineOptions {
19
+ remove_style_tags : options. remove_style_tags . unwrap_or ( default_options. remove_style_tags ) ,
20
+ extra_css : options. extra_css . unwrap_or ( default_options. extra_css ) ,
21
+ inline_style_tags : options. inline_style_tags . unwrap_or ( default_options. inline_style_tags ) ,
22
+ base_url : options. base_url . unwrap_or ( default_options. base_url ) ,
23
+ load_remote_stylesheets : options. load_remote_stylesheets . unwrap_or ( default_options. load_remote_stylesheets ) ,
24
+ } ;
25
+ let inliner = rust_inline:: CSSInliner :: new ( options) ;
26
+ Ok ( inliner. inline ( html) . map_err ( InlineErrorWrapper ) ?)
27
+ }
You can’t perform that action at this time.
0 commit comments