lgpl_docs/
lib.rs

1extern crate stripper_lib;
2
3use std::io;
4use std::path::Path;
5use stripper_lib::{loop_over_files, parse_cmts, regenerate_comments, strip_comments};
6
7#[derive(Clone, Copy, Debug)]
8pub enum Library {
9    GstWebRTC,
10    GstVideo,
11    GstSdp,
12    GstRtspServer,
13    GstRtsp,
14    GstRtp,
15    GstPlayer,
16    GstNet,
17    GstGL,
18    GES,
19    GstCheck,
20    GstPbutils,
21    GstBase,
22    GstAudio,
23    GstApp,
24    Gst,
25}
26
27fn docs(lib: Library) -> Option<&'static str> {
28    match lib {
29        Library::GstWebRTC => Some(include_str!("../gstreamer-webrtc/docs.md")),
30        Library::GstVideo => Some(include_str!("../gstreamer-video/docs.md")),
31        Library::GstSdp => Some(include_str!("../gstreamer-sdp/docs.md")),
32        Library::GstRtspServer => Some(include_str!("../gstreamer-rtsp-server/docs.md")),
33        Library::GstRtsp => Some(include_str!("../gstreamer-rtsp/docs.md")),
34        Library::GstRtp => Some(include_str!("../gstreamer-rtp/docs.md")),
35        Library::GstPlayer => Some(include_str!("../gstreamer-player/docs.md")),
36        Library::GstNet => Some(include_str!("../gstreamer-net/docs.md")),
37        Library::GstGL => Some(include_str!("../gstreamer-gl/docs.md")),
38        Library::GES => Some(include_str!("../gstreamer-editing-services/docs.md")),
39        Library::GstCheck => Some(include_str!("../gstreamer-check/docs.md")),
40        Library::GstPbutils => Some(include_str!("../gstreamer-pbutils/docs.md")),
41        Library::GstBase => Some(include_str!("../gstreamer-base/docs.md")),
42        Library::GstAudio => Some(include_str!("../gstreamer-audio/docs.md")),
43        Library::GstApp => Some(include_str!("../gstreamer-app/docs.md")),
44        Library::Gst => Some(include_str!("../gstreamer/docs.md")),
45    }
46}
47
48fn vendor_docs(_lib: Library) -> Option<&'static str> {
49    None
50}
51
52/// Embeds the docs.
53///
54/// `path` is the root directory to process.
55///
56/// `ignores` is the list of files to skip (relative to `path`).
57pub fn embed<P: AsRef<Path>>(library: Library, path: P, ignores: &[&str]) {
58    if let Some(docs) = docs(library) {
59        do_embed(docs, path.as_ref(), ignores);
60    }
61    if let Some(docs) = vendor_docs(library) {
62        do_embed(docs, path.as_ref(), ignores);
63    }
64}
65
66fn do_embed(docs: &str, path: &Path, ignores: &[&str]) {
67    let mut infos = parse_cmts(docs.lines(), true);
68    loop_over_files(
69        path,
70        &mut |w, s| regenerate_comments(w, s, &mut infos, true, true),
71        &ignores,
72        false,
73    );
74}
75
76/// Remove any doc comments.
77///
78/// `path` is the root directory to process.
79///
80/// `ignores` is the list of files to skip (relative to `path`).
81pub fn purge<P: AsRef<Path>>(path: P, ignores: &[&str]) {
82    loop_over_files(
83        path.as_ref(),
84        &mut |w, s| strip_comments(w, s, &mut io::sink(), true),
85        &ignores,
86        false,
87    );
88}