libtmplgen/lib.rs
1//This file is part of tmplgen
2//
3//tmplgen is free software: you can redistribute it and/or modify
4//it under the terms of the GNU General Public License as published by
5//the Free Software Foundation, either version 3 of the License, or
6//(at your option) any later version.
7//
8//tmplgen is distributed in the hope that it will be useful,
9//but WITHOUT ANY WARRANTY; without even the implied warranty of
10//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11//GNU General Public License for more details.
12//
13//You should have received a copy of the GNU General Public License
14//along with tmplgen. If not, see <http://www.gnu.org/licenses/>.
15
16//! libtmplgen can be used for querying different language-specific package managers and generating
17//! Void Linux build templates for them. Currently the following providers are supported:
18//!
19//! * [crates.io](https://crates.io)
20//! * [metacpan.org](https://metacpan.org)
21//! * [rubygems.org](https://rubygems.org)
22//!
23//! # Usage
24//!
25//! The following will write a template for `tmplgen` in `$XBPS_DISTDIR/srcpkgs/rust-tmplgen/template`
26//!
27//! ```
28//! use libtmplgen::*;
29//! use std::fs::File;
30//! use std::io::prelude::*;
31//!
32//! fn write_template() -> Result<(), Error> {
33//! let template = TmplBuilder::new("tmplgen").get_type()?.get_info()?.generate(true)?;
34//!
35//! let mut file = File::create("./template")?;
36//! file.write_all(template.inner.as_bytes())?;
37//!
38//! Ok(())
39//! }
40//! ```
41//!
42//! *Wait. What?*
43//! Here's a step-by-step example:
44//! ```
45//! use libtmplgen::*;
46//! use std::fs::File;
47//! use std::io::prelude::*;
48//!
49//! fn write_template() -> Result<(), Error> {
50//! // Creates a new TmplBuilder for the pkg "tmplgen"
51//! let mut tmpl_builder = TmplBuilder::new("tmplgen");
52//! // Get the PkgType of this crate
53//! tmpl_builder.get_type()?;
54//! // Get a PkgInfo struct of this crate
55//! tmpl_builder.get_info()?;
56//! // Generate a [Template](crate::types::Template) which we can write later on
57//! // The bool sets if we want the template to be prefixed with {perl-,ruby-,rust-}
58//! let template = tmpl_builder.generate(true)?;
59//!
60//! // Create a file called "template" in the current dir
61//! let mut file = File::create("./template")?;
62//! // Write the [Template](crate::types::Template) to the file we just created
63//! file.write_all(template.inner.as_bytes())?;
64//!
65//! Ok(())
66//! }
67//! ```
68//!
69//! See [TmplBuilder](crate::types::TmplBuilder) for most of the exciting other stuff.
70
71mod crates;
72mod gems;
73mod helpers;
74mod perldist;
75#[cfg(test)]
76mod tests;
77
78pub mod errors;
79pub mod tmplwriter;
80pub mod types;
81
82pub use crate::errors::*;
83pub use crate::tmplwriter::*;
84pub use crate::types::*;