Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split build() for readability #369

Merged
merged 1 commit into from
Jan 24, 2018
Merged

Conversation

Geobert
Copy link
Contributor

@Geobert Geobert commented Jan 23, 2018

I've split cobalt.rs build() function to make it easier to read

Copy link
Member

@epage epage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While there are some things that could improved in this, I think its fine to hold off because we'll need to revisit it as part of #368.

// compile SASS along the way
{
debug!("Copying remaining assets");
fn parse_files(page_files: &files::Files,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parse_files -> parse_pages

let doc_html = doc.render(&globals, &parser, &layouts, &mut layouts_cache)
.chain_err(|| format!("Failed to render for {:?}", doc.file_path))?;
files::write_document_file(doc_html, dest.join(doc.file_path))?;
fn construct_page_files(source: &Path, config: &Config) -> Result<files::Files> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

construct_page_files -> find_pages

trace!("Generating other documents");
for mut doc in documents {
trace!("Generating {}", doc.url_path);
fn process_included_drafts(config: &Config,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this would be split into find_draft_files and parse_drafts. Not sure how clean that'd be at the moment.

Ok(())
}

fn sort_documents_by_date(posts: &mut Vec<Document>, config: &Config) -> Result<()> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this takes in the config, it seems like this could just skip putting the sort policy in the function name because that will eventually be configurable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, what should I call it, as the code is really doing sorting by date ^^'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sort_pages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! I misread, I though you wanted me to drop the "sort" word. You were talking "sort policy" ^^'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see how that can be missed and be confusing :)

Ok(())
}

fn generate_posts(posts: &mut Vec<Document>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to find ways to refactor this so the code can be shared between "other" and "posts".


let default_front = config.posts.default.clone().set_draft(true);
fn generate_other_docs(posts: Vec<Document>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confusingly, I'd call this generate_pages. That is the name (so far) for the default collection.

@epage epage merged commit f60e3ce into cobalt-org:master Jan 24, 2018
@Geobert
Copy link
Contributor Author

Geobert commented Jan 24, 2018

I'll do the renaming tonight :)

@Geobert Geobert deleted the refactoring_build branch January 27, 2018 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants