Skip to content

Commit

Permalink
style(mrml-core): rename Options to RenderOptions
Browse files Browse the repository at this point in the history
Signed-off-by: Jérémie Drouet <[email protected]>
  • Loading branch information
jdrouet committed Dec 7, 2023
1 parent 266ed0b commit 6d650bc
Show file tree
Hide file tree
Showing 37 changed files with 138 additions and 133 deletions.
2 changes: 1 addition & 1 deletion packages/mrml-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::io::prelude::*;
use clap::{Parser, Subcommand};
use mrml::mjml::Mjml;
use mrml::prelude::print::Print;
use mrml::prelude::render::Options as RenderOptions;
use mrml::prelude::render::RenderOptions;

#[derive(Debug, Parser)]
#[clap(author, version, about, long_about = None)]
Expand Down
4 changes: 2 additions & 2 deletions packages/mrml-core/benches/basic.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use mrml::prelude::render::Options;
use mrml::prelude::render::RenderOptions;

fn render(input: &str) {
let opts = Options::default();
let opts = RenderOptions::default();
let root = mrml::mjml::Mjml::parse(input).unwrap();
root.render(&opts).unwrap();
}
Expand Down
4 changes: 2 additions & 2 deletions packages/mrml-core/benches/template.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use mrml::prelude::render::Options;
use mrml::prelude::render::RenderOptions;

fn render(input: &str) {
let opts = Options::default();
let opts = RenderOptions::default();
let root = mrml::mjml::Mjml::parse(input).unwrap();
root.render(&opts).unwrap();
}
Expand Down
12 changes: 6 additions & 6 deletions packages/mrml-core/src/comment/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::cell::{Ref, RefCell};
use std::rc::Rc;

use super::Comment;
use crate::prelude::render::{Error, Header, Options, Render, Renderable};
use crate::prelude::render::{Error, Header, Render, RenderOptions, Renderable};

struct CommentRender<'e, 'h> {
header: Rc<RefCell<Header<'h>>>,
Expand All @@ -14,7 +14,7 @@ impl<'e, 'h> Render<'h> for CommentRender<'e, 'h> {
self.header.borrow()
}

fn render(&self, opts: &Options) -> Result<String, Error> {
fn render(&self, opts: &RenderOptions) -> Result<String, Error> {
if opts.disable_comments {
Ok(String::default())
} else {
Expand All @@ -39,19 +39,19 @@ impl<'r, 'e: 'r, 'h: 'r> Renderable<'r, 'e, 'h> for Comment {
#[cfg(all(test, feature = "parse"))]
mod tests {
use crate::mjml::Mjml;
use crate::prelude::render::Options;
use crate::prelude::render::RenderOptions;

#[test]
fn render_enabled() {
let opts = Options::default();
let opts = RenderOptions::default();
let root = Mjml::parse(r#"<mjml><mj-body><!-- Hello World! --></mj-body></mjml>"#).unwrap();
let result = root.render(&opts).unwrap();
assert!(result.contains("Hello World!"));
}

#[test]
fn render_disabled() {
let opts = Options {
let opts = RenderOptions {
disable_comments: true,
..Default::default()
};
Expand All @@ -62,7 +62,7 @@ mod tests {

#[test]
fn render_with_is_raw() {
let opts = Options::default();
let opts = RenderOptions::default();
let root = Mjml::parse(r#"<mjml><mj-body><mj-section><mj-column><!-- Hello World! --></mj-column></mj-section></mj-body></mjml>"#).unwrap();
let result = root.render(&opts).unwrap();
assert!(result.contains("Hello World!"));
Expand Down
4 changes: 2 additions & 2 deletions packages/mrml-core/src/mj_accordion/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::{MjAccordion, MjAccordionChild, NAME};
use crate::helper::size::{Pixel, Size};
use crate::helper::tag::Tag;
use crate::prelude::hash::Map;
use crate::prelude::render::{Error, Header, Options, Render, Renderable};
use crate::prelude::render::{Error, Header, Render, RenderOptions, Renderable};

const CHILDREN_ATTRIBUTES: [&str; 9] = [
"border",
Expand Down Expand Up @@ -109,7 +109,7 @@ impl<'e, 'h> Render<'h> for MjAccordionRender<'e, 'h> {
self.raw_siblings = value;
}

fn render(&self, opts: &Options) -> Result<String, Error> {
fn render(&self, opts: &RenderOptions) -> Result<String, Error> {
self.update_header();
let children = self
.element
Expand Down
12 changes: 6 additions & 6 deletions packages/mrml-core/src/mj_accordion_element/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::helper::tag::Tag;
use crate::mj_accordion_text::MjAccordionText;
use crate::mj_accordion_title::MjAccordionTitle;
use crate::prelude::hash::Map;
use crate::prelude::render::{Error, Header, Options, Render, Renderable};
use crate::prelude::render::{Error, Header, Render, RenderOptions, Renderable};

const CHILDREN_ATTRIBUTES: [&str; 9] = [
"border",
Expand All @@ -28,7 +28,7 @@ struct MjAccordionElementRender<'e, 'h> {
}

impl<'e, 'h> MjAccordionElementRender<'e, 'h> {
fn render_title(&self, opts: &Options) -> Result<String, Error> {
fn render_title(&self, opts: &RenderOptions) -> Result<String, Error> {
if let Some(ref child) = self.element.children.title {
let mut renderer = child.renderer(Rc::clone(&self.header));
CHILDREN_ATTRIBUTES.iter().for_each(|name| {
Expand All @@ -45,7 +45,7 @@ impl<'e, 'h> MjAccordionElementRender<'e, 'h> {
}
}

fn render_text(&self, opts: &Options) -> Result<String, Error> {
fn render_text(&self, opts: &RenderOptions) -> Result<String, Error> {
if let Some(ref child) = self.element.children.text {
let mut renderer = child.renderer(Rc::clone(&self.header));
CHILDREN_ATTRIBUTES.iter().for_each(|name| {
Expand All @@ -62,7 +62,7 @@ impl<'e, 'h> MjAccordionElementRender<'e, 'h> {
}
}

fn render_children(&self, opts: &Options) -> Result<String, Error> {
fn render_children(&self, opts: &RenderOptions) -> Result<String, Error> {
Ok(self.render_title(opts)? + &self.render_text(opts)?)
}
}
Expand All @@ -88,7 +88,7 @@ impl<'e, 'h> Render<'h> for MjAccordionElementRender<'e, 'h> {
self.header.borrow()
}

fn render(&self, opts: &Options) -> Result<String, Error> {
fn render(&self, opts: &RenderOptions) -> Result<String, Error> {
let input = negation_conditional_tag(
Tag::new("input")
.add_attribute("type", "checkbox")
Expand Down Expand Up @@ -136,7 +136,7 @@ mod tests {

#[test]
fn basic() {
let opts = Options::default();
let opts = RenderOptions::default();
let head = Rc::new(RefCell::new(Header::new(&None)));
let element = MjAccordionElement {
attributes: Default::default(),
Expand Down
6 changes: 3 additions & 3 deletions packages/mrml-core/src/mj_accordion_text/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::rc::Rc;
use super::{MjAccordionText, NAME};
use crate::helper::tag::Tag;
use crate::prelude::hash::Map;
use crate::prelude::render::{Error, Header, Options, Render, Renderable};
use crate::prelude::render::{Error, Header, Render, RenderOptions, Renderable};

struct MjAccordionTextRender<'e, 'h> {
header: Rc<RefCell<Header<'h>>>,
Expand All @@ -13,7 +13,7 @@ struct MjAccordionTextRender<'e, 'h> {
}

impl<'e, 'h> MjAccordionTextRender<'e, 'h> {
fn render_children(&self, opts: &Options) -> Result<String, Error> {
fn render_children(&self, opts: &RenderOptions) -> Result<String, Error> {
let content = self
.element
.children
Expand Down Expand Up @@ -68,7 +68,7 @@ impl<'e, 'h> Render<'h> for MjAccordionTextRender<'e, 'h> {
self.header.borrow()
}

fn render(&self, opts: &Options) -> Result<String, Error> {
fn render(&self, opts: &RenderOptions) -> Result<String, Error> {
let font_families = self.attribute("font-family");
self.header
.borrow_mut()
Expand Down
6 changes: 3 additions & 3 deletions packages/mrml-core/src/mj_accordion_title/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::{MjAccordionTitle, NAME};
use crate::helper::condition::negation_conditional_tag;
use crate::helper::tag::Tag;
use crate::prelude::hash::Map;
use crate::prelude::render::{Error, Header, Options, Render, Renderable};
use crate::prelude::render::{Error, Header, Render, RenderOptions, Renderable};

struct MjAccordionTitleRender<'e, 'h> {
header: Rc<RefCell<Header<'h>>>,
Expand All @@ -20,7 +20,7 @@ impl<'e, 'h> MjAccordionTitleRender<'e, 'h> {
.maybe_add_style("height", self.attribute("icon-height"))
}

fn render_title(&self, opts: &Options) -> Result<String, Error> {
fn render_title(&self, opts: &RenderOptions) -> Result<String, Error> {
let content = self
.element
.children
Expand Down Expand Up @@ -96,7 +96,7 @@ impl<'e, 'h> Render<'h> for MjAccordionTitleRender<'e, 'h> {
self.header.borrow()
}

fn render(&self, opts: &Options) -> Result<String, Error> {
fn render(&self, opts: &RenderOptions) -> Result<String, Error> {
let font_families = self.attribute("font-family");
self.header
.borrow_mut()
Expand Down
6 changes: 3 additions & 3 deletions packages/mrml-core/src/mj_body/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::MjBody;
use crate::helper::size::Pixel;
use crate::helper::tag::Tag;
use crate::prelude::hash::Map;
use crate::prelude::render::{Error, Header, Options, Render, Renderable};
use crate::prelude::render::{Error, Header, Render, RenderOptions, Renderable};

struct MjBodyRender<'e, 'h> {
header: Rc<RefCell<Header<'h>>>,
Expand Down Expand Up @@ -51,7 +51,7 @@ impl<'e, 'h> MjBodyRender<'e, 'h> {
}
}

fn render_content(&self, opts: &Options) -> Result<String, Error> {
fn render_content(&self, opts: &RenderOptions) -> Result<String, Error> {
let div = self.get_content_div_tag();
let element_width = self.get_width();
let mut children = String::default();
Expand Down Expand Up @@ -89,7 +89,7 @@ impl<'e, 'h> Render<'h> for MjBodyRender<'e, 'h> {
self.header.borrow()
}

fn render(&self, opts: &Options) -> Result<String, Error> {
fn render(&self, opts: &RenderOptions) -> Result<String, Error> {
let body = self.get_body_tag();
let result = body.render(self.render_preview() + &self.render_content(opts)?);
Ok(result)
Expand Down
6 changes: 3 additions & 3 deletions packages/mrml-core/src/mj_button/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::{MjButton, NAME};
use crate::helper::size::Pixel;
use crate::helper::tag::Tag;
use crate::prelude::hash::Map;
use crate::prelude::render::{Error, Header, Options, Render, Renderable};
use crate::prelude::render::{Error, Header, Render, RenderOptions, Renderable};

struct MjButtonRender<'e, 'h> {
header: Rc<RefCell<Header<'h>>>,
Expand Down Expand Up @@ -37,7 +37,7 @@ impl<'e, 'h> MjButtonRender<'e, 'h> {
}
}

fn render_children(&self, opts: &Options) -> Result<String, Error> {
fn render_children(&self, opts: &RenderOptions) -> Result<String, Error> {
self.element
.children
.iter()
Expand Down Expand Up @@ -122,7 +122,7 @@ impl<'e, 'h> Render<'h> for MjButtonRender<'e, 'h> {
self.header.borrow()
}

fn render(&self, opts: &Options) -> Result<String, Error> {
fn render(&self, opts: &RenderOptions) -> Result<String, Error> {
let font_family = self.attribute("font-family");
self.header
.borrow_mut()
Expand Down
14 changes: 7 additions & 7 deletions packages/mrml-core/src/mj_carousel/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::helper::size::{Pixel, Size};
use crate::helper::style::Style;
use crate::helper::tag::Tag;
use crate::prelude::hash::Map;
use crate::prelude::render::{Error, Header, Options, Render, Renderable};
use crate::prelude::render::{Error, Header, Render, RenderOptions, Renderable};

impl<'r, 'e: 'r, 'h: 'r> Renderable<'r, 'e, 'h> for MjCarouselChild {
fn renderer(&'e self, header: Rc<RefCell<Header<'h>>>) -> Box<dyn Render<'h> + 'r> {
Expand Down Expand Up @@ -89,7 +89,7 @@ impl<'e, 'h> MjCarouselRender<'e, 'h> {
.add_style("padding", "0px")
}

fn render_radios(&self, opts: &Options) -> Result<String, Error> {
fn render_radios(&self, opts: &RenderOptions) -> Result<String, Error> {
self.element
.children
.iter()
Expand All @@ -110,7 +110,7 @@ impl<'e, 'h> MjCarouselRender<'e, 'h> {
})
}

fn render_thumbnails(&self, opts: &Options) -> Result<String, Error> {
fn render_thumbnails(&self, opts: &RenderOptions) -> Result<String, Error> {
if self.attribute_equals("thumbnails", "visible") {
let width = self.get_thumbnails_width();
self.element
Expand Down Expand Up @@ -172,7 +172,7 @@ impl<'e, 'h> MjCarouselRender<'e, 'h> {
.render(div)
}

fn render_images(&self, opts: &Options) -> Result<String, Error> {
fn render_images(&self, opts: &RenderOptions) -> Result<String, Error> {
let content = self
.element
.children
Expand All @@ -197,7 +197,7 @@ impl<'e, 'h> MjCarouselRender<'e, 'h> {
Ok(self.set_style_images_td(Tag::td()).render(div))
}

fn render_carousel(&self, opts: &Options) -> Result<String, Error> {
fn render_carousel(&self, opts: &RenderOptions) -> Result<String, Error> {
let previous =
self.render_controls("previous", self.attribute("left-icon").unwrap().as_str());
let images = self.render_images(opts)?;
Expand All @@ -212,7 +212,7 @@ impl<'e, 'h> MjCarouselRender<'e, 'h> {
Ok(table)
}

fn render_fallback(&self, opts: &Options) -> Result<String, Error> {
fn render_fallback(&self, opts: &RenderOptions) -> Result<String, Error> {
match self
.element
.children
Expand Down Expand Up @@ -438,7 +438,7 @@ impl<'e, 'h> Render<'h> for MjCarouselRender<'e, 'h> {
self.raw_siblings = value;
}

fn render(&self, opts: &Options) -> Result<String, Error> {
fn render(&self, opts: &RenderOptions) -> Result<String, Error> {
let styles = self.render_style();
self.header.borrow_mut().maybe_add_style(styles);
let radios = self.render_radios(opts)?;
Expand Down
6 changes: 3 additions & 3 deletions packages/mrml-core/src/mj_carousel_image/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::{MjCarouselImage, NAME};
use crate::helper::size::Pixel;
use crate::helper::tag::Tag;
use crate::prelude::hash::Map;
use crate::prelude::render::{Error, Header, Options, Render, Renderable};
use crate::prelude::render::{Error, Header, Render, RenderOptions, Renderable};

struct MjCarouselImageRender<'e, 'h> {
header: Rc<RefCell<Header<'h>>>,
Expand Down Expand Up @@ -167,7 +167,7 @@ impl<'e, 'h> Render<'h> for MjCarouselImageRender<'e, 'h> {
self.header.borrow()
}

fn render_fragment(&self, name: &str, opts: &Options) -> Result<String, Error> {
fn render_fragment(&self, name: &str, opts: &RenderOptions) -> Result<String, Error> {
match name {
"main" => self.render(opts),
"radio" => Ok(self.render_radio()),
Expand All @@ -176,7 +176,7 @@ impl<'e, 'h> Render<'h> for MjCarouselImageRender<'e, 'h> {
}
}

fn render(&self, _opts: &Options) -> Result<String, Error> {
fn render(&self, _opts: &RenderOptions) -> Result<String, Error> {
let img = self
.set_style_images_img(Tag::new("img"))
.add_attribute("border", "0")
Expand Down
8 changes: 4 additions & 4 deletions packages/mrml-core/src/mj_column/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::{MjColumn, NAME};
use crate::helper::size::{Pixel, Size};
use crate::helper::tag::Tag;
use crate::prelude::hash::Map;
use crate::prelude::render::{Error, Header, Options, Render, Renderable};
use crate::prelude::render::{Error, Header, Render, RenderOptions, Renderable};

struct MjColumnRender<'e, 'h> {
header: Rc<RefCell<Header<'h>>>,
Expand Down Expand Up @@ -178,7 +178,7 @@ impl<'e, 'h> MjColumnRender<'e, 'h> {
.maybe_add_style("padding-left", self.attribute("padding-left"))
}

fn render_gutter(&self, opts: &Options) -> Result<String, Error> {
fn render_gutter(&self, opts: &RenderOptions) -> Result<String, Error> {
let table = Tag::table_presentation().add_attribute("width", "100%");
let tbody = Tag::tbody();
let tr = Tag::tr();
Expand All @@ -194,7 +194,7 @@ impl<'e, 'h> MjColumnRender<'e, 'h> {
}
}

fn render_column(&self, opts: &Options) -> Result<String, Error> {
fn render_column(&self, opts: &RenderOptions) -> Result<String, Error> {
let table = self
.set_style_table(Tag::table_presentation())
.add_attribute("width", "100%");
Expand Down Expand Up @@ -290,7 +290,7 @@ impl<'e, 'h> Render<'h> for MjColumnRender<'e, 'h> {
}
}

fn render(&self, opts: &Options) -> Result<String, Error> {
fn render(&self, opts: &RenderOptions) -> Result<String, Error> {
let (classname, size) = self.get_column_class();
self.header
.borrow_mut()
Expand Down
Loading

0 comments on commit 6d650bc

Please sign in to comment.