1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-03-25 23:49:54 +02:00
michael-kerscher 355d65b3ba
Add mdbook-slide-evaluator ()
I created a first implementation for the mdbook-slide-evaluator I
described in .

One has to run a WebDriver compatible browser (e.g. selenium-chromium)
so the slides can be rendered. The browser can access the file either
via a file:// or http:// uri.

The tool grabs the configurable element from that page and evaluates the
size of this element. Output can be stored in a csv file or at stdout
and looks like this at the moment:
```
$ mdbook-slide-evaluator book/html/android/aidl
book/html/android/aidl/birthday-service.html: 750x134
book/html/android/aidl/example-service/changing-definition.html: 750x555
book/html/android/aidl/example-service/changing-implementation.html: 750x786
book/html/android/aidl/example-service/client.html: 750x1096
book/html/android/aidl/example-service/deploy.html: 750x635
book/html/android/aidl/example-service/interface.html: 750x570
book/html/android/aidl/example-service/server.html: 750x837
book/html/android/aidl/example-service/service-bindings.html: 750x483
book/html/android/aidl/example-service/service.html: 750x711
book/html/android/aidl/types/arrays.html: 750x291
book/html/android/aidl/types/file-descriptor.html: 750x1114
book/html/android/aidl/types/objects.html: 750x1258
book/html/android/aidl/types/parcelables.html: 750x637
book/html/android/aidl/types/primitives.html: 750x366
book/html/android/aidl/types.html: 750x197
```

---------

Co-authored-by: Martin Geisler <martin@geisler.net>
2024-08-21 07:18:07 +00:00

55 lines
1.6 KiB
Rust

// Copyright 2024 Google LLC
//
// 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
//
// http://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::path::{Path, PathBuf};
use std::sync::Arc;
use log::debug;
/// a slide is a page in the book
#[derive(Debug, Clone)]
pub struct Slide {
pub filename: Arc<Path>,
}
/// a book is a collection of slides
pub struct Book {
/// the path to the root directory of this book
_source_dir: PathBuf,
/// the collection of slides
slides: Vec<Slide>,
}
impl Book {
/// create a book from all html files in the source_dir
pub fn from_html_slides(source_dir: PathBuf) -> anyhow::Result<Book> {
let mut slides = vec![];
let files = glob::glob(&format!(
"{}/**/*.html",
source_dir.to_str().expect("invalid path")
))?;
for file in files {
let slide = Slide { filename: file?.into() };
debug!("add {:?}", slide);
slides.push(slide);
}
Ok(Book { _source_dir: source_dir, slides })
}
/// return a reference to the slides of this book
pub fn slides(&self) -> &[Slide] {
&self.slides
}
}