Skip to content

Commit

Permalink
Add Comments and apply Suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
SeppFS committed Dec 8, 2023
1 parent 0d39597 commit a7b8813
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion commons/src/config/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct Output {
/// If this option is not set, the input is rendered to all supported formats.
///
/// **Supported formats:** `html`
#[arg(long, alias = "output-formats", value_parser = parse_to_hashset::<OutputFormatKind>, required = false, default_value = "umi")]
#[arg(long, alias = "output-formats", value_parser = parse_to_hashset::<OutputFormatKind>, required = false, default_value = "html")]
pub formats: HashSet<OutputFormatKind>,
/// `true` overwrites existing output files
#[arg(long, alias = "overwrite-out-files")]
Expand Down
39 changes: 18 additions & 21 deletions render/src/umi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,11 @@ impl Umi {
}
}

// fn with_wb() -> Self{}
// Merge two Umi Structs
fn merge(&mut self, other_umi: &mut Umi) {
self.elements.append(&mut other_umi.elements);
}

pub fn create_workbook(&mut self) -> &mut Self {
let mut wb = WorkBook::new_empty();

let mut sheet = Sheet::new("umi");
// Set the Header Row, could be left out if it is not meant for viewing
// Set the Header Row
sheet.set_value(0, 0, "position");
sheet.set_value(0, 1, "id");
sheet.set_value(0, 2, "kind");
Expand Down Expand Up @@ -110,12 +104,11 @@ impl Umi {
inlines.2.to_inlines()
}

fn fetch_next_line(&mut self, current_line: &mut UmiRow, new_line_index: usize) -> bool {
fn fetch_next_line(&mut self, new_line_index: usize) -> Option<UmiRow> {
if new_line_index < self.elements.len() {
*current_line = self.elements[new_line_index].clone();
true
} else {
false
Some(self.elements[new_line_index].clone())
}else{
None
}
}

Expand Down Expand Up @@ -165,9 +158,9 @@ impl Umi {

let bullet_list_depth = current_line.depth;
let mut current_line_index = line + 1;
self.fetch_next_line(&mut current_line, current_line_index);
current_line = self.fetch_next_line(current_line_index).unwrap();

while current_line.depth != bullet_list_depth {
while current_line.depth > bullet_list_depth {
if current_line.depth == bullet_list_depth + 1 {
// Append Element to Bullet List
let block = self.read_row(current_line_index);
Expand All @@ -181,9 +174,11 @@ impl Umi {
}

current_line_index += 1;
if !self.fetch_next_line(&mut current_line, current_line_index) {
let fetched = self.fetch_next_line(current_line_index);
if fetched.is_none(){
break;
}
current_line = fetched.unwrap();
}

Block::BulletList(bullet_list)
Expand All @@ -203,9 +198,9 @@ impl Umi {

let bullet_list_entry_depth = current_line.depth;
let mut current_line_index = line + 1;
self.fetch_next_line(&mut current_line, current_line_index);
current_line = self.fetch_next_line(current_line_index).unwrap();

while current_line.depth != bullet_list_entry_depth {
while current_line.depth > bullet_list_entry_depth {
if current_line.depth == bullet_list_entry_depth + 1 {
// Append Element to Bullet List Entry Body
let block = self.read_row(current_line_index);
Expand All @@ -215,10 +210,12 @@ impl Umi {
}

current_line_index += 1;

if !self.fetch_next_line(&mut current_line, current_line_index) {

let fetched = self.fetch_next_line(current_line_index);
if fetched.is_none(){
break;
}
current_line = fetched.unwrap();
}

Block::BulletListEntry(bullet_list_entry)
Expand All @@ -229,7 +226,7 @@ impl Umi {

pub fn create_um(&mut self) -> Vec<Block> {
self.elements.clear();
assert!(!self.ods.is_empty());
debug_assert!(!self.ods.is_empty());

let wb: WorkBook = read_ods_buf(&self.ods).unwrap();
let sheet = wb.sheet(0);
Expand Down Expand Up @@ -299,8 +296,8 @@ impl OutputFormat for Umi {
}
}

// Merge two umi elements
fn append(&mut self, mut other: Self) -> Result<(), crate::log_id::RenderError> {
// Append two Umi Elements
self.elements.append(&mut other.elements);
Ok(())
}
Expand Down
21 changes: 12 additions & 9 deletions render/src/umi/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@ pub struct UmiRenderer {
}

impl UmiRenderer {
// Step into a nested element (Should be called by parent)
fn step_in(&mut self) {
self.depth += 1;
}

// Step out of a nested element (Should be called by parent)
fn step_out(&mut self) {
self.depth -= 1;
}

fn proceed(&mut self, new_umi: &mut Umi) -> Result<Umi, crate::log_id::RenderError> {
// Should always be called after element has been fully rendered to Umi
fn proceed(&mut self, new_umi: Umi) -> Result<Umi, crate::log_id::RenderError> {
if self.depth != 0 {
Ok(new_umi.clone())
} else {
self.umi.merge(new_umi);
let _ = self.umi.append(new_umi);
Ok(self.umi.clone())
}
}
Expand All @@ -53,7 +56,7 @@ impl Renderer<Umi> for UmiRenderer {
);
self.pos += 1;

self.proceed(&mut Umi::with_um(
self.proceed(Umi::with_um(
vec![paragraph],
context.get_lang().to_string(),
))
Expand Down Expand Up @@ -98,7 +101,7 @@ impl Renderer<Umi> for UmiRenderer {
);
self.pos += 1;

self.proceed(&mut Umi::with_um(
self.proceed(Umi::with_um(
vec![verbatim],
context.get_lang().to_string(),
))
Expand Down Expand Up @@ -137,7 +140,7 @@ impl Renderer<Umi> for UmiRenderer {
);
self.pos += 1;

self.proceed(&mut Umi::with_um(
self.proceed(Umi::with_um(
vec![heading],
context.get_lang().to_string(),
))
Expand Down Expand Up @@ -178,7 +181,7 @@ impl Renderer<Umi> for UmiRenderer {
}
self.step_out();

self.proceed(&mut bullet_list_content)
self.proceed(bullet_list_content)
}

fn render_bullet_list_entry(
Expand Down Expand Up @@ -229,12 +232,12 @@ impl Renderer<Umi> for UmiRenderer {
// Render All Bullet List Body Elements
self.step_in();
if !bullet_list_entry.body.is_empty() {
let next_entry = &mut self.render_blocks(&bullet_list_entry.body, context)?;
entry.merge(next_entry);
let next_entry = self.render_blocks(&bullet_list_entry.body, context)?;
let _ = entry.append(next_entry);
}
self.step_out();

self.proceed(&mut entry)
self.proceed(entry)
}

fn render_inlines(
Expand Down

0 comments on commit a7b8813

Please sign in to comment.