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 Mar 4, 2024
1 parent a09ee4b commit 3c5264c
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 2 deletions.
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.

13 changes: 11 additions & 2 deletions 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.14.0"
Expand Down Expand Up @@ -60,7 +67,7 @@ insta = { version = "1.35.1", features = ["filters"] }
itertools = "0.12.1"
libc = { version = "0.2.153" }
maplit = "1.0.2"
minus = { version = "5.5.0", features = [ "dynamic_output", "search" ] }
minus = { version = "5.5.0", features = ["dynamic_output", "search"] }
num_cpus = "1.16.0"
once_cell = "1.19.0"
ouroboros = "0.18.0"
Expand All @@ -79,6 +86,7 @@ ref-cast = "1.0.22"
regex = "1.10.3"
rpassword = "7.3.1"
rustix = { version = "0.38.31", 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.114"
Expand Down Expand Up @@ -114,6 +122,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.14.0" }
jj-lib = { path = "lib", version = "0.14.0" }
jj-lib-proc-macros = { path = "lib/proc-macros", version = "0.14.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 3c5264c

Please sign in to comment.