Skip to content

Commit d23be5b

Browse files
committed
feat: add html support
add support for ray!().html("<strong>big test</strong>")
1 parent b64f358 commit d23be5b

File tree

6 files changed

+139
-5
lines changed

6 files changed

+139
-5
lines changed

.github/workflows/publish.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Publish Crate 🦀
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
audit:
9+
name: Audit
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 10
12+
steps:
13+
- uses: actions/checkout@v3
14+
- uses: bp3d-actions/audit-check@9c23bd47e5e7b15b824739e0862cb878a52cc211
15+
with:
16+
token: ${{ secrets.GITHUB_TOKEN }}
17+
18+
build_and_test_linux:
19+
name: Build and Test (Linux)
20+
runs-on: ubuntu-latest
21+
timeout-minutes: 10
22+
steps:
23+
- uses: actions/checkout@v3
24+
- uses: dtolnay/rust-toolchain@stable
25+
26+
- uses: taiki-e/install-action@nextest
27+
- name: "Build and test"
28+
run: cargo nextest run --workspace --all-features
29+
30+
build_and_test_windows:
31+
name: Build and Test (Windows)
32+
runs-on: windows-latest
33+
timeout-minutes: 20
34+
steps:
35+
- name: Prepare symlink configuration
36+
run: git config --global core.symlinks true
37+
38+
- uses: actions/checkout@v3
39+
- uses: dtolnay/rust-toolchain@stable
40+
41+
- uses: taiki-e/install-action@nextest
42+
- name: "Build and test"
43+
run: cargo nextest run --workspace --all-features
44+
45+
crates_io_publish:
46+
name: Publish (crates.io)
47+
needs:
48+
- audit
49+
- build_and_test_linux
50+
- build_and_test_windows
51+
52+
runs-on: ubuntu-latest
53+
timeout-minutes: 25
54+
steps:
55+
- uses: actions/checkout@v3
56+
- uses: dtolnay/rust-toolchain@stable
57+
58+
- name: cargo-release Cache
59+
id: cargo_release_cache
60+
uses: actions/cache@v3
61+
with:
62+
path: ~/.cargo/bin/cargo-release
63+
key: ${{ runner.os }}-cargo-release
64+
65+
- run: cargo install cargo-release
66+
if: steps.cargo_release_cache.outputs.cache-hit != 'true'
67+
68+
- name: cargo login
69+
run: cargo login ${{ secrets.CRATES_IO_API_TOKEN }}
70+
71+
- name: "cargo release publish"
72+
run: |-
73+
cargo release \
74+
publish \
75+
--workspace \
76+
--all-features \
77+
--allow-branch HEAD \
78+
--no-confirm \
79+
--no-verify \
80+
--execute

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ray-rust"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
edition = "2021"
55
authors = ["ALameLlama NicholasACiechanowski@gmail.com"]
66
description = "Spatie Ray in Rust"

src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,21 @@ impl Ray {
165165

166166
self.send()
167167
}
168+
169+
pub fn html(&mut self, value: &str) -> &mut Self {
170+
let message = RayMessage::HTML(RayHtml {
171+
label: RayMessageType::HTML,
172+
content: value.to_string(),
173+
});
174+
175+
let content = RayContent {
176+
content_type: RayHtml::get_type(),
177+
origin: RayOrigin::new(),
178+
content: message,
179+
};
180+
181+
self.request.payloads.push(content);
182+
183+
self.send()
184+
}
168185
}

src/message.rs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,31 @@ pub enum RayMessage {
66
Log(RayLog),
77
Text(RayText),
88
Color(RayColor),
9+
HTML(RayHtml),
910
}
1011

1112
#[derive(Debug, Serialize, Deserialize, Clone)]
1213
pub enum RayMessageType {
1314
Log,
1415
Text,
16+
HTML,
17+
}
18+
19+
#[derive(Debug, Serialize, Deserialize, Clone)]
20+
pub enum RayContentType {
21+
Log,
22+
Custom,
23+
Color,
24+
}
25+
26+
impl RayContentType {
27+
pub fn as_string(&self) -> String {
28+
match self {
29+
RayContentType::Log => "log".to_string(),
30+
RayContentType::Custom => "custom".to_string(),
31+
RayContentType::Color => "color".to_string(),
32+
}
33+
}
1534
}
1635

1736
// https://github.com/spatie/ray/blob/main/src/Payloads/LogPayload.php
@@ -23,7 +42,7 @@ pub struct RayLog {
2342

2443
impl RayLog {
2544
pub fn get_type() -> String {
26-
"log".to_string()
45+
RayContentType::Log.as_string()
2746
}
2847
}
2948

@@ -36,7 +55,7 @@ pub struct RayText {
3655

3756
impl RayText {
3857
pub fn get_type() -> String {
39-
"custom".to_string()
58+
RayContentType::Custom.as_string()
4059
}
4160
}
4261

@@ -48,7 +67,7 @@ pub struct RayColor {
4867

4968
impl RayColor {
5069
pub fn get_type() -> String {
51-
"color".to_string()
70+
RayContentType::Color.as_string()
5271
}
5372
}
5473

@@ -77,3 +96,16 @@ impl RayColors {
7796
}
7897
}
7998
}
99+
100+
// https://github.com/spatie/ray/blob/main/src/Payloads/HtmlPayload.php
101+
#[derive(Debug, Serialize, Deserialize, Clone)]
102+
pub struct RayHtml {
103+
pub label: RayMessageType,
104+
pub content: String,
105+
}
106+
107+
impl RayHtml {
108+
pub fn get_type() -> String {
109+
RayContentType::Custom.as_string()
110+
}
111+
}

src/tests.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ fn test_ray_text() {
1616
fn test_ray_color() {
1717
ray!("Hello Color").color("green");
1818
}
19+
20+
#[test]
21+
fn test_ray_html() {
22+
ray!().html("<strong>Hello, HTML!</strong>");
23+
}

0 commit comments

Comments
 (0)