summaryrefslogtreecommitdiffstats
path: root/third_party/rust/askama
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/askama
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/askama')
-rw-r--r--third_party/rust/askama/.cargo-checksum.json1
-rw-r--r--third_party/rust/askama/Cargo.toml55
-rw-r--r--third_party/rust/askama/LICENSE-APACHE201
-rw-r--r--third_party/rust/askama/LICENSE-MIT25
-rw-r--r--third_party/rust/askama/src/lib.rs185
5 files changed, 467 insertions, 0 deletions
diff --git a/third_party/rust/askama/.cargo-checksum.json b/third_party/rust/askama/.cargo-checksum.json
new file mode 100644
index 0000000000..f83fbad020
--- /dev/null
+++ b/third_party/rust/askama/.cargo-checksum.json
@@ -0,0 +1 @@
+{"files":{"Cargo.toml":"f15e26a3a1f5c3efc5cb364ee53ae42d462a4221c9e416d8a765260e2a75eada","LICENSE-APACHE":"87cb0d734c723c083e51c825930ff42bce28596b52dee15567f6b28f19c195e3","LICENSE-MIT":"df20e0180764bf5bd76f74d47bc9e8c0069a666401629c390003a1d5eba99c92","src/lib.rs":"fd52fa3b97acd0957a183d9dac465ca67d53c53f49dad461ca174c312d81e32e"},"package":"fb98f10f371286b177db5eeb9a6e5396609555686a35e1d4f7b9a9c6d8af0139"} \ No newline at end of file
diff --git a/third_party/rust/askama/Cargo.toml b/third_party/rust/askama/Cargo.toml
new file mode 100644
index 0000000000..f566aa4eba
--- /dev/null
+++ b/third_party/rust/askama/Cargo.toml
@@ -0,0 +1,55 @@
+# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
+#
+# When uploading crates to the registry Cargo will automatically
+# "normalize" Cargo.toml files for maximal compatibility
+# with all versions of Cargo and also rewrite `path` dependencies
+# to registry (e.g., crates.io) dependencies.
+#
+# If you are reading this file be aware that the original Cargo.toml
+# will likely look very different (and much more reasonable).
+# See Cargo.toml.orig for the original contents.
+
+[package]
+edition = "2018"
+name = "askama"
+version = "0.11.1"
+description = "Type-safe, compiled Jinja-like templates for Rust"
+homepage = "https://github.com/djc/askama"
+documentation = "https://docs.rs/askama"
+readme = "../README.md"
+keywords = ["markup", "template", "jinja2", "html"]
+categories = ["template-engine"]
+license = "MIT OR Apache-2.0"
+repository = "https://github.com/djc/askama"
+[package.metadata.docs.rs]
+features = ["config", "humansize", "num-traits", "serde-json", "serde-yaml"]
+[dependencies.askama_derive]
+version = "0.11.2"
+
+[dependencies.askama_escape]
+version = "0.10"
+
+[dependencies.askama_shared]
+version = "0.12.1"
+default-features = false
+
+[features]
+config = ["askama_derive/config", "askama_shared/config"]
+default = ["config", "humansize", "num-traits", "urlencode"]
+humansize = ["askama_shared/humansize"]
+markdown = ["askama_shared/markdown"]
+mime = []
+mime_guess = []
+num-traits = ["askama_shared/num-traits"]
+serde-json = ["askama_derive/json", "askama_shared/json"]
+serde-yaml = ["askama_derive/yaml", "askama_shared/yaml"]
+urlencode = ["askama_shared/percent-encoding"]
+with-actix-web = ["askama_derive/actix-web"]
+with-axum = ["askama_derive/axum"]
+with-gotham = ["askama_derive/gotham"]
+with-mendes = ["askama_derive/mendes"]
+with-rocket = ["askama_derive/rocket"]
+with-tide = ["askama_derive/tide"]
+with-warp = ["askama_derive/warp"]
+[badges.maintenance]
+status = "actively-developed"
diff --git a/third_party/rust/askama/LICENSE-APACHE b/third_party/rust/askama/LICENSE-APACHE
new file mode 100644
index 0000000000..b7ca568694
--- /dev/null
+++ b/third_party/rust/askama/LICENSE-APACHE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
+
+APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+Copyright 2017-2020 Dirkjan Ochtman
+
+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.
diff --git a/third_party/rust/askama/LICENSE-MIT b/third_party/rust/askama/LICENSE-MIT
new file mode 100644
index 0000000000..c765f2e75a
--- /dev/null
+++ b/third_party/rust/askama/LICENSE-MIT
@@ -0,0 +1,25 @@
+Copyright (c) 2017-2020 Dirkjan Ochtman
+
+Permission is hereby granted, free of charge, to any
+person obtaining a copy of this software and associated
+documentation files (the "Software"), to deal in the
+Software without restriction, including without
+limitation the rights to use, copy, modify, merge,
+publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software
+is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice
+shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
+ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
+TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
+SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
diff --git a/third_party/rust/askama/src/lib.rs b/third_party/rust/askama/src/lib.rs
new file mode 100644
index 0000000000..ccfddc8fb3
--- /dev/null
+++ b/third_party/rust/askama/src/lib.rs
@@ -0,0 +1,185 @@
+//! Askama implements a type-safe compiler for Jinja-like templates.
+//! It lets you write templates in a Jinja-like syntax,
+//! which are linked to a `struct` defining the template context.
+//! This is done using a custom derive implementation (implemented
+//! in [`askama_derive`](https://crates.io/crates/askama_derive)).
+//!
+//! For feature highlights and a quick start, please review the
+//! [README](https://github.com/djc/askama/blob/main/README.md).
+//!
+//! The primary documentation for this crate now lives in
+//! [the book](https://djc.github.io/askama/).
+//!
+//! # Creating Askama templates
+//!
+//! An Askama template is a `struct` definition which provides the template
+//! context combined with a UTF-8 encoded text file (or inline source, see
+//! below). Askama can be used to generate any kind of text-based format.
+//! The template file's extension may be used to provide content type hints.
+//!
+//! A template consists of **text contents**, which are passed through as-is,
+//! **expressions**, which get replaced with content while being rendered, and
+//! **tags**, which control the template's logic.
+//! The template syntax is very similar to [Jinja](http://jinja.pocoo.org/),
+//! as well as Jinja-derivatives like [Twig](http://twig.sensiolabs.org/) or
+//! [Tera](https://github.com/Keats/tera).
+//!
+//! ## The `template()` attribute
+//!
+//! Askama works by generating one or more trait implementations for any
+//! `struct` type decorated with the `#[derive(Template)]` attribute. The
+//! code generation process takes some options that can be specified through
+//! the `template()` attribute. The following sub-attributes are currently
+//! recognized:
+//!
+//! * `path` (as `path = "foo.html"`): sets the path to the template file. The
+//! path is interpreted as relative to the configured template directories
+//! (by default, this is a `templates` directory next to your `Cargo.toml`).
+//! The file name extension is used to infer an escape mode (see below). In
+//! web framework integrations, the path's extension may also be used to
+//! infer the content type of the resulting response.
+//! Cannot be used together with `source`.
+//! * `source` (as `source = "{{ foo }}"`): directly sets the template source.
+//! This can be useful for test cases or short templates. The generated path
+//! is undefined, which generally makes it impossible to refer to this
+//! template from other templates. If `source` is specified, `ext` must also
+//! be specified (see below). Cannot be used together with `path`.
+//! * `ext` (as `ext = "txt"`): lets you specify the content type as a file
+//! extension. This is used to infer an escape mode (see below), and some
+//! web framework integrations use it to determine the content type.
+//! Cannot be used together with `path`.
+//! * `print` (as `print = "code"`): enable debugging by printing nothing
+//! (`none`), the parsed syntax tree (`ast`), the generated code (`code`)
+//! or `all` for both. The requested data will be printed to stdout at
+//! compile time.
+//! * `escape` (as `escape = "none"`): override the template's extension used for
+//! the purpose of determining the escaper for this template. See the section
+//! on configuring custom escapers for more information.
+//! * `syntax` (as `syntax = "foo"`): set the syntax name for a parser defined
+//! in the configuration file. The default syntax , "default", is the one
+//! provided by Askama.
+
+#![forbid(unsafe_code)]
+#![deny(elided_lifetimes_in_paths)]
+#![deny(unreachable_pub)]
+
+pub use askama_shared as shared;
+
+pub use askama_escape::{Html, Text};
+
+/// Main `Template` trait; implementations are generally derived
+///
+/// If you need an object-safe template, use [`DynTemplate`].
+pub trait Template {
+ /// Helper method which allocates a new `String` and renders into it
+ fn render(&self) -> Result<String> {
+ let mut buf = String::with_capacity(Self::SIZE_HINT);
+ self.render_into(&mut buf)?;
+ Ok(buf)
+ }
+
+ /// Renders the template to the given `writer` buffer
+ fn render_into(&self, writer: &mut (impl std::fmt::Write + ?Sized)) -> Result<()>;
+
+ /// The template's extension, if provided
+ const EXTENSION: Option<&'static str>;
+
+ /// Provides a conservative estimate of the expanded length of the rendered template
+ const SIZE_HINT: usize;
+
+ /// The MIME type (Content-Type) of the data that gets rendered by this Template
+ const MIME_TYPE: &'static str;
+}
+
+/// Object-safe wrapper trait around [`Template`] implementers
+///
+/// This trades reduced performance (mostly due to writing into `dyn Write`) for object safety.
+pub trait DynTemplate {
+ /// Helper method which allocates a new `String` and renders into it
+ fn dyn_render(&self) -> Result<String>;
+
+ /// Renders the template to the given `writer` buffer
+ fn dyn_render_into(&self, writer: &mut dyn std::fmt::Write) -> Result<()>;
+
+ /// Helper function to inspect the template's extension
+ fn extension(&self) -> Option<&'static str>;
+
+ /// Provides a conservative estimate of the expanded length of the rendered template
+ fn size_hint(&self) -> usize;
+
+ /// The MIME type (Content-Type) of the data that gets rendered by this Template
+ fn mime_type(&self) -> &'static str;
+}
+
+impl<T: Template> DynTemplate for T {
+ fn dyn_render(&self) -> Result<String> {
+ <Self as Template>::render(self)
+ }
+
+ fn dyn_render_into(&self, writer: &mut dyn std::fmt::Write) -> Result<()> {
+ <Self as Template>::render_into(self, writer)
+ }
+
+ fn extension(&self) -> Option<&'static str> {
+ Self::EXTENSION
+ }
+
+ fn size_hint(&self) -> usize {
+ Self::SIZE_HINT
+ }
+
+ fn mime_type(&self) -> &'static str {
+ Self::MIME_TYPE
+ }
+}
+
+pub use crate::shared::filters;
+pub use crate::shared::helpers;
+pub use crate::shared::{read_config_file, Error, MarkupDisplay, Result};
+pub use askama_derive::*;
+
+#[deprecated(since = "0.11.1", note = "The only function in this mod is deprecated")]
+pub mod mime {
+ #[cfg(all(feature = "mime_guess", feature = "mime"))]
+ #[deprecated(since = "0.11.1", note = "Use Template::MIME_TYPE instead")]
+ pub use crate::shared::extension_to_mime_type;
+}
+
+/// Old build script helper to rebuild crates if contained templates have changed
+///
+/// This function is now deprecated and does nothing.
+#[deprecated(
+ since = "0.8.1",
+ note = "file-level dependency tracking is handled automatically without build script"
+)]
+pub fn rerun_if_templates_changed() {}
+
+#[cfg(test)]
+mod tests {
+ use super::{DynTemplate, Template};
+
+ #[test]
+ fn dyn_template() {
+ struct Test;
+ impl Template for Test {
+ fn render_into(
+ &self,
+ writer: &mut (impl std::fmt::Write + ?Sized),
+ ) -> askama_shared::Result<()> {
+ Ok(writer.write_str("test")?)
+ }
+
+ const EXTENSION: Option<&'static str> = Some("txt");
+
+ const SIZE_HINT: usize = 4;
+
+ const MIME_TYPE: &'static str = "text/plain; charset=utf-8";
+ }
+
+ fn render(t: &dyn DynTemplate) -> String {
+ t.dyn_render().unwrap()
+ }
+
+ assert_eq!(render(&Test), "test");
+ }
+}