Skip to content

Commit

Permalink
progress with block
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoczim committed Jan 1, 2024
1 parent 51b2761 commit eafd0e1
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 138 deletions.
2 changes: 1 addition & 1 deletion src/component.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pub mod location;
pub mod inline;
pub mod block;

/*
pub mod block;
pub mod section;
pub mod asset;
pub mod page;
Expand Down
34 changes: 18 additions & 16 deletions src/component/block.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
//! This module exports components that are of type block, as well their kind.

use super::{Component, ComponentKind, InlineComponent};
use crate::render::{Context, Html, Markdown, Render, Renderer, Text};
use std::fmt::{self, Write};

use crate::{
domain::{
component::{self, Component},
render,
Render,
Renderer,
},
format::{Html, Markdown, Text},
};

use super::InlineComponent;

pub mod text;
pub mod media;
/*
pub mod list;
pub mod table;
*/

/// A block component. Such component is one that cannot appear in the middle of
/// reading text and can appear directly in the body of a section.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
pub struct BlockComponent;

impl ComponentKind for BlockComponent {}
impl component::Kind for BlockComponent {}

/// Wrapper over inline components to make them a block component. Note,
/// however, that if you just use this in a section body, the outcome might not
/// be desirable, but if you use this in a table cell, for example, it makes
/// perfect sense.
///
/// # HTML Classes
///
/// - `pedia-inline-block` attached to a `<span>` element.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
pub struct InlineBlock<C>(pub C)
where
Expand All @@ -43,7 +45,7 @@ where
fn render(
&self,
renderer: &mut Renderer<Html>,
ctx: Context<Self::Kind>,
ctx: render::Context<Self::Kind>,
) -> fmt::Result {
renderer.write_str("<span class=\"pedia-inline-block\">")?;
self.0.render(renderer, ctx.with_kind(&InlineComponent))?;
Expand All @@ -59,7 +61,7 @@ where
fn render(
&self,
renderer: &mut Renderer<Markdown>,
ctx: Context<Self::Kind>,
ctx: render::Context<Self::Kind>,
) -> fmt::Result {
self.0.render(renderer, ctx.with_kind(&InlineComponent))
}
Expand All @@ -72,7 +74,7 @@ where
fn render(
&self,
renderer: &mut Renderer<Text>,
ctx: Context<Self::Kind>,
ctx: render::Context<Self::Kind>,
) -> fmt::Result {
self.0.render(renderer, ctx.with_kind(&InlineComponent))
}
Expand Down
28 changes: 10 additions & 18 deletions src/component/block/list.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
//! This module exports list related components.

use super::BlockComponent;
use crate::{
component::Component,
hseq::IntoIterRef,
render::{markdown, text, Context, Html, Markdown, Render, Renderer, Text},
};
use std::{
cmp::Ordering,
fmt::{self, Write},
Expand All @@ -19,10 +14,7 @@ use std::{
///
/// - `pedia-unord-list` attached to an `<ul>` element.
/// - `pedia-list-elem` attached to `<li>` elements.
pub struct UnorderedList<L>(pub L)
where
L: IntoIterRef,
<L as IntoIterRef>::Item: Component<Kind = BlockComponent>;
pub struct UnorderedList<T, V> {}

impl<L> fmt::Debug for UnorderedList<L>
where
Expand Down Expand Up @@ -134,7 +126,7 @@ where
fn render(
&self,
renderer: &mut Renderer<Html>,
ctx: Context<Self::Kind>,
ctx: render::Context<Self::Kind>,
) -> fmt::Result {
renderer.write_str("<ul class=\"pedia-unord-list\">")?;
for element in self.0.iter() {
Expand All @@ -155,7 +147,7 @@ where
fn render(
&self,
renderer: &mut Renderer<Markdown>,
ctx: Context<Self::Kind>,
ctx: render::Context<Self::Kind>,
) -> fmt::Result {
renderer.scoped(markdown::Nest, |renderer| {
for element in self.0.iter() {
Expand All @@ -176,7 +168,7 @@ where
fn render(
&self,
renderer: &mut Renderer<Text>,
ctx: Context<Self::Kind>,
ctx: render::Context<Self::Kind>,
) -> fmt::Result {
renderer.scoped(text::Nest, |renderer| {
for element in self.0.iter() {
Expand Down Expand Up @@ -312,7 +304,7 @@ where
fn render(
&self,
renderer: &mut Renderer<Html>,
ctx: Context<Self::Kind>,
ctx: render::Context<Self::Kind>,
) -> fmt::Result {
renderer.write_str("<ol class=\"pedia-ord-list\">")?;
for element in self.0.iter() {
Expand All @@ -333,7 +325,7 @@ where
fn render(
&self,
renderer: &mut Renderer<Markdown>,
ctx: Context<Self::Kind>,
ctx: render::Context<Self::Kind>,
) -> fmt::Result {
renderer.scoped(markdown::Nest, |renderer| {
for element in self.0.iter() {
Expand All @@ -354,7 +346,7 @@ where
fn render(
&self,
renderer: &mut Renderer<Text>,
ctx: Context<Self::Kind>,
ctx: render::Context<Self::Kind>,
) -> fmt::Result {
renderer.scoped(text::Nest, |renderer| {
for (i, element) in self.0.iter().enumerate() {
Expand All @@ -379,7 +371,7 @@ mod test {
location::InternalPath,
render::{
html::test::validate_html_fragment,
Context,
render::Context,
Html,
RenderAsDisplay,
},
Expand All @@ -392,7 +384,7 @@ mod test {
(InlineBlock("abc"), Paragraph("def")): BlockComponent
]),
&mut Html::default(),
Context::new(&InternalPath::default(), &BlockComponent),
render::Context::new(location::Path::ROOT, &BlockComponent),
)
.to_string();

Expand All @@ -406,7 +398,7 @@ mod test {
(InlineBlock("abc"), Paragraph("def")): BlockComponent
]),
&mut Html::default(),
Context::new(&InternalPath::default(), &BlockComponent),
render::Context::new(location::Path::ROOT, &BlockComponent),
)
.to_string();

Expand Down
Loading

0 comments on commit eafd0e1

Please sign in to comment.