Skip to content

Commit 072787e

Browse files
README.md 周りの修正 (#45)
* wip: sync.rs 更新 * docs: README.md 類を更新 * chore: バージョンアップ * fix: dry run をする場合、バージョンを揃えられない問題があることに気付いたため、dry run を削除 * docs: todo.md 更新
1 parent c62bdc9 commit 072787e

File tree

17 files changed

+417
-95
lines changed

17 files changed

+417
-95
lines changed

.github/scripts/sync.rs

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,28 @@ struct Readme {
2727
common: String,
2828
}
2929

30+
#[derive(serde::Serialize)]
31+
struct VersionInfo {
32+
version: String,
33+
}
34+
3035
#[hooq(anyhow)]
3136
fn main() -> anyhow::Result<()> {
3237
let Args { check } = Args::parse();
3338

34-
sync_sub_crate_versions(check)?;
39+
let version = sync_sub_crate_versions(check)?;
40+
let version_info = VersionInfo { version };
41+
3542
cargo_sort(check)?;
3643
for lang in ["", "/ja"] {
37-
sync_readme(lang, check)?;
44+
sync_readme(lang, check, &version_info)?;
3845
}
3946

4047
Ok::<(), anyhow::Error>(())
4148
}
4249

4350
#[hooq(anyhow)]
44-
fn sync_sub_crate_versions(check_only: bool) -> anyhow::Result<()> {
51+
fn sync_sub_crate_versions(check_only: bool) -> anyhow::Result<String> {
4552
let workspace_toml = toml::from_str::<toml::Value>(&std::fs::read_to_string("./Cargo.toml")?)?;
4653

4754
if workspace_toml.as_table()?.get("workspace").is_none() {
@@ -105,7 +112,7 @@ fn sync_sub_crate_versions(check_only: bool) -> anyhow::Result<()> {
105112
)?;
106113
}
107114

108-
Ok::<(), anyhow::Error>(())
115+
Ok::<String, anyhow::Error>(version.to_string())
109116
}
110117

111118
// TOMLの上書きは順番がおかしくなるので、cargo-sortで整形
@@ -132,15 +139,18 @@ fn cargo_sort(check_only: bool) -> anyhow::Result<()> {
132139
}
133140

134141
#[hooq(anyhow)]
135-
fn sync_readme(lang: &str, check_only: bool) -> anyhow::Result<()> {
136-
let common_md = std::fs::read_to_string(format!("./hooq/docs{lang}/README.md"))?;
137-
138-
let readme = Readme { common: common_md };
142+
fn sync_readme(lang: &str, check_only: bool, version_info: &VersionInfo) -> anyhow::Result<()> {
143+
let common_template_md =
144+
std::fs::read_to_string(format!("./docs{lang}/_readme_root.md.template"))?;
139145

140146
let mut handlebars = handlebars::Handlebars::new();
141147
handlebars.set_strict_mode(true);
142148
handlebars.register_escape_fn(handlebars::no_escape);
143149

150+
let common_md = handlebars.render_template(&common_template_md, &version_info)?;
151+
152+
let readme = Readme { common: common_md };
153+
144154
// GitHub README.md
145155
let github_template_md = std::fs::read_to_string("./docs/_readme_github.md.template")?;
146156
let github_readme_md = handlebars.render_template(&github_template_md, &readme)?;
@@ -158,6 +168,23 @@ fn sync_readme(lang: &str, check_only: bool) -> anyhow::Result<()> {
158168
std::fs::write(&path, github_readme_md)?;
159169
}
160170

171+
// hooq README.md
172+
// コピーするのみ
173+
let hooq_readme_md = readme.common.clone();
174+
175+
let path = format!("./hooq/docs{lang}/README.md");
176+
177+
if check_only {
178+
let existing_hooq_readme_md = std::fs::read_to_string(&path)?;
179+
if existing_hooq_readme_md != hooq_readme_md {
180+
return Err(anyhow::anyhow!(
181+
"README.md is out of date. Please run the sync script to update it."
182+
));
183+
}
184+
} else {
185+
std::fs::write(&path, hooq_readme_md)?;
186+
}
187+
161188
// hooq-macros and hooq-helpers README.md
162189
let sub_crates_template_md = std::fs::read_to_string("./docs/_readme_sub_crates.md.template")?;
163190
let sub_crates_readme_md = handlebars.render_template(&sub_crates_template_md, &readme)?;

.github/workflows/crates_io_publish_hooq_348912.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ jobs:
1212
id-token: write
1313
steps:
1414
- uses: actions/checkout@v5
15-
- run: |
16-
cargo publish -p hooq-helpers --dry-run
17-
cargo publish -p hooq-macros --dry-run
18-
cargo publish -p hooq --dry-run
1915
- uses: rust-lang/crates-io-auth-action@v1
2016
id: auth
2117
- run: cargo publish -p hooq-helpers

.github/workflows/create_release_note.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ jobs:
1010
contents: write
1111
steps:
1212
- uses: actions/checkout@v5
13-
- run: |
14-
cargo publish -p hooq-helpers --dry-run
15-
cargo publish -p hooq-macros --dry-run
16-
cargo publish -p hooq --dry-run
1713
- name: Obtain Included Files List
1814
id: included-files-list
1915
run: |

Cargo.lock

Lines changed: 18 additions & 18 deletions
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
@@ -11,7 +11,7 @@ members = [
1111
]
1212

1313
[workspace.package]
14-
version = "0.1.0"
14+
version = "0.1.1"
1515
edition = "2024"
1616
rust-version = "1.88.0"
1717
authors = ["namnium <anotherhollow1125@gmail.com>"]

docs/README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# hooq
22

3-
A simple macro that inserts a method before the `?` operator
3+
A simple macro that inserts a method before `?`.
44

55
The crate name comes from the acronym "HOOk for Question mark operator".
66

7+
> [!NOTE]
8+
> 日本語版ドキュメントはこちら: [docs/ja/README.md](https://github.com/anotherhollow1125/hooq/tree/main/docs/ja)
9+
710
```rust
811
use hooq::hooq;
912

@@ -28,7 +31,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
2831
}
2932
```
3033

31-
The above expands into the following.
34+
The above expands to the following.
3235

3336
```ignore
3437
use hooq::hooq;
@@ -104,22 +107,20 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
104107

105108
## Quick Start
106109

107-
Add the crate with `cargo add` as shown below, or
110+
Add it with `cargo add` as shown below, or add it to your `Cargo.toml`.
108111

109112
```bash
110113
cargo add hooq
111114
```
112115

113-
add it to your `Cargo.toml`.
114-
115116
```toml
116117
[dependencies]
117-
hooq = "*"
118+
hooq = "0.1.1"
118119
```
119120

120-
## Methods Inserted by Default
121+
## Method inserted by default
121122

122-
If nothing is specifically specified for `#[hooq]`, the following method is inserted:
123+
If you don't specify anything for `#[hooq]`, the following method is inserted by default.
123124

124125
```ignore
125126
.inspect_err(|e| {
@@ -130,20 +131,20 @@ If nothing is specifically specified for `#[hooq]`, the following method is inse
130131
})
131132
```
132133

133-
You can switch the hooked method with the inert attribute `#[hooq::method(...)]`. Also, if you specify a flavor like `#[hooq(log)]` or `#[hooq(anyhow)]` (requires the `anyhow` feature) at the macro call site, the inserted method will correspond to that flavor.
134+
You can switch the method to hook with the inert attribute `#[hooq::method(...)]`. Also, when you specify a flavor at the call site such as `#[hooq(log)]` or `#[hooq(anyhow)]` (the `anyhow` feature is required), the inserted method will change according to that flavor!
134135

135-
Available flavors can be found here: [hooq-macros/src/impls/flavor/presets/](../../hooq-macros/src/impls/flavor/presets/)
136+
You can find the available flavors here: [hooq-macros/src/impls/flavor/presets/](https://github.com/anotherhollow1125/hooq/tree/main/hooq-macros/src/impls/flavor/presets)
136137

137138
(More to come!)
138139

139140
## Attributes
140141

141142
(WIP)
142143

143-
## Metavariables
144+
## Meta variables
144145

145146
(WIP)
146147

147-
## Flavors
148+
## Flavor
148149

149150
(WIP)

0 commit comments

Comments
 (0)