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

Add enrich_li_class for nested tasklist #29

Merged

Conversation

primercuervo
Copy link
Contributor

This intends to generate tasklist the same way vimwiki does
for .wiki extensions. Allows for a visualization of
progress in nested tasklists, and customization of
the same via html templates

it "must enrich task list parent 3" do
allow_any_instance_of(VimwikiMarkdown::VimwikiLink).to receive(:vimwiki_markdown_file_exists?).and_return(true)
allow(wiki_body).to receive(:get_wiki_markdown_contents).and_return('- [O] This is a parent 3 line')
expect(wiki_body.to_s).to match(/<li class="done3"> This is a parent 3 line<\/li>/)
Copy link

Choose a reason for hiding this comment

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

Style/RegexpLiteral: Use %r around regular expression.

it "must enrich task list parent 2" do
allow_any_instance_of(VimwikiMarkdown::VimwikiLink).to receive(:vimwiki_markdown_file_exists?).and_return(true)
allow(wiki_body).to receive(:get_wiki_markdown_contents).and_return('- [o] This is a parent 2 line')
expect(wiki_body.to_s).to match(/<li class="done2"> This is a parent 2 line<\/li>/)
Copy link

Choose a reason for hiding this comment

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

Style/RegexpLiteral: Use %r around regular expression.

it "must enrich task list parent 1" do
allow_any_instance_of(VimwikiMarkdown::VimwikiLink).to receive(:vimwiki_markdown_file_exists?).and_return(true)
allow(wiki_body).to receive(:get_wiki_markdown_contents).and_return('- [.] This is a parent 1 line')
expect(wiki_body.to_s).to match(/<li class="done1"> This is a parent 1 line<\/li>/)
Copy link

Choose a reason for hiding this comment

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

Style/RegexpLiteral: Use %r around regular expression.

it "must enrich task list checked" do
allow_any_instance_of(VimwikiMarkdown::VimwikiLink).to receive(:vimwiki_markdown_file_exists?).and_return(true)
allow(wiki_body).to receive(:get_wiki_markdown_contents).and_return('- [X] This is a checked line')
expect(wiki_body.to_s).to match(/<li class="done4"> This is a checked line<\/li>/)
Copy link

Choose a reason for hiding this comment

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

Style/RegexpLiteral: Use %r around regular expression.

it "must enrich task list unchecked" do
allow_any_instance_of(VimwikiMarkdown::VimwikiLink).to receive(:vimwiki_markdown_file_exists?).and_return(true)
allow(wiki_body).to receive(:get_wiki_markdown_contents).and_return('- [ ] This is one line')
expect(wiki_body.to_s).to match(/<li class="done0"> This is one line<\/li>/)
Copy link

Choose a reason for hiding this comment

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

Style/RegexpLiteral: Use %r around regular expression.

@patrickdavey
Copy link
Owner

Nice work! Especially if you're new to ruby :)

Decisions decisions eh. I reckon, as vimwiki does support the fancy state-based lists (even in markdown format), it would be a shame not to support them.

Also, we don't currently propertly support task lists we're in the nice position of just being able to make it work how we want to.

So, I reckon yip, lets go with #29 . If you're happy to tidy up the rubocop errors that'd be nice, but honestly - I'm happy to merge it as A) I only added rubocop recently as it's a bit of a mess anyway, and B) this is great work and thanks for spending time to make a decent PR with tests etc!

I did have a little play, and slightly tweaked the enrich to:

  def enrich_li_class!
    syms_hash = {" ]" => 0, ".]" => 1, "o]" =>  2, "O]" => 3, "X]" => 4}
    checkbox =  /<li>\s*\[[\s.oOX]\]/
    checkbox_start =  /<li>\s*\[/
    @result.gsub!(checkbox) do |m|
      m.sub(checkbox_start, '<li class="done')
       .sub(/[\s.oOX\]]*$/, syms_hash) << '">'
    end
    @result
  end

Again, don't really mind if you want to keep it as is. I slightly preferred the above as it's using the same regex \s instead of just looking for a single space. I think we should be consistent between the checkbox regex and whatever you're doing with the two subs.

Great work though :) Happy to merge, happy to wait if you want to try fix the code violations.

Thanks!

This intends to generate tasklist the same way vimwiki does
for .wiki extensions. Allows for a visualization of
progress in nested tasklists, and customization of
the same via html templates
@primercuervo primercuervo force-pushed the cuervo/vimwiki_tasklist branch from 1fc9b09 to 2a4820a Compare June 4, 2020 09:33
@primercuervo
Copy link
Contributor Author

Your version looks definitely tidier. Thanks for the suggestion! I added it and updated the rubocop checks as well.

I gotta admit that I like this approach better just because I enjoy seeing those visuals in the HTML.

@patrickdavey patrickdavey merged commit 293f99e into patrickdavey:master Jun 4, 2020
@patrickdavey
Copy link
Owner

I'll update the README and push out a new version in the next hour or so hopefully (assuming my daughter stays alseep ;)

Thanks for the PR & discussion.

@primercuervo primercuervo deleted the cuervo/vimwiki_tasklist branch June 4, 2020 21:50
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