Skip to content

Commit

Permalink
docs: initialize new jj-docs crate
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Seipp <[email protected]>
  • Loading branch information
thoughtpolice committed Apr 4, 2024
1 parent 2cf1c34 commit 1e9e4ad
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 1 deletion.
42 changes: 42 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ cargo-features = []

[workspace]
resolver = "2"
members = ["cli", "lib", "lib/gen-protos", "lib/proc-macros", "lib/testutils"]
members = [
"cli",
"lib",
"docs",
"lib/gen-protos",
"lib/proc-macros",
"lib/testutils",
]

[workspace.package]
version = "0.16.0"
Expand Down Expand Up @@ -80,6 +87,7 @@ ref-cast = "1.0.22"
regex = "1.10.3"
rpassword = "7.3.1"
rustix = { version = "0.38.32", features = ["fs"] }
rust-embed = { version = "8.3.0", features = ["include-exclude"] }
scm-record = "0.2.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.115"
Expand Down Expand Up @@ -116,6 +124,7 @@ zstd = "0.12.4"
# put all inter-workspace libraries, i.e. those that use 'path = ...' here in
# their own (alphabetically sorted) block

jj-docs = { path = "docs", version = "0.16.0" }
jj-lib = { path = "lib", version = "0.16.0" }
jj-lib-proc-macros = { path = "lib/proc-macros", version = "0.16.0" }
testutils = { path = "lib/testutils" }
Expand Down
19 changes: 19 additions & 0 deletions docs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "jj-docs"
description = "Documentation for Jujutsu - an experimental version control system"
autotests = false

version = { workspace = true }
edition = { workspace = true }
rust-version = { workspace = true }
license = { workspace = true }
homepage = { workspace = true }
repository = { workspace = true }
documentation = { workspace = true }
readme = { workspace = true }

[lib]
path = "lib.rs"

[dependencies]
rust-embed = { workspace = true }
40 changes: 40 additions & 0 deletions docs/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2024 The Jujutsu Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::borrow::Cow;

#[derive(rust_embed::RustEmbed)]
#[folder = "."]
#[include = "*.md"]
struct DocAssetsMd;

pub struct DocAssets;

/// Documentation assets, allowing you to look up and iterate all the documents
/// available.
impl DocAssets {
// This is a simple wrapper around the `DocAssetsMd`
// struct that handles trimming off Markdown `.md` extensions, so that users
// can refer to documentation items without needing to know the file extension.

/// Iterator. Returns all the documentation items available.
pub fn iter() -> impl Iterator<Item = String> {
DocAssetsMd::iter().map(|name| name.trim_end_matches(".md").to_owned())
}

pub fn get(name: &str) -> Option<Cow<'static, [u8]>> {
// re-attach the `.md` extension before lookup
DocAssetsMd::get(&format!("{}.md", name)).map(|data| data.data)
}
}

0 comments on commit 1e9e4ad

Please sign in to comment.