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

Create CodeTag plugin to render code files with and without solutions #29

Merged
merged 14 commits into from
Aug 16, 2024

Conversation

phrdang
Copy link
Member

@phrdang phrdang commented Jun 22, 2024

Created a custom Liquid tag called CodeTag as a Jekyll plugin. This tag allows staff to easily "import" code snippets located in the _includes/ directory, and hide/show solutions as needed.

Fixes phrdang#14

Next steps (in separate PRs)

  • Figure out how to write tests for this. Currently I just manually tested it by changing inputs and seeing what the jekyll site looked like/what error was thrown
  • Automatically wrap the output of this tag in a highlight block
  • Should we render a placeholder like "*** YOUR CODE HERE ***" if @show_solution is false?
  • How do we want to create solution pages? Do we want them to be auto generated during the build process or manually created as .md files by staff?

@phrdang phrdang requested a review from cycomachead June 22, 2024 04:11
@phrdang phrdang self-assigned this Jun 22, 2024
_includes/test.py Outdated Show resolved Hide resolved
_includes/test.py Outdated Show resolved Hide resolved
_includes/test.py Outdated Show resolved Hide resolved
_includes/test.py Outdated Show resolved Hide resolved
phrdang and others added 3 commits June 21, 2024 21:13
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@phrdang
Copy link
Member Author

phrdang commented Jun 22, 2024

Maybe using the context variable will allow us to get jekyll variables/front matter? https://stackoverflow.com/questions/7919644/using-liquid-variables-inside-of-a-liquid-tag-call?lq=1

https://blog.sverrirs.com/2016/04/custom-jekyll-tags.html#accessing-post-variables-in-tags

https://github.com/Shopify/liquid/blob/main/lib/liquid/context.rb#L176

Will investigate...

edit: yep this works. example:

# frozen_string_literal: true

module Jekyll
  class MyTag < Liquid::Tag
    def render(context)
      context['page.nav_exclude'] == true # displays true when the tag is rendered if the variable is set to true
    end
  end
end

Liquid::Template.register_tag('my_tag', Jekyll::MyTag)

@phrdang phrdang marked this pull request as draft June 22, 2024 04:42
@phrdang phrdang changed the title Create PythonTag plugin to render Python files with and without solutions Create CodeTag plugin to render code files with and without solutions Jun 25, 2024
@phrdang phrdang marked this pull request as ready for review June 25, 2024 04:59
@phrdang
Copy link
Member Author

phrdang commented Jul 12, 2024

Copying conversation from Slack:

@.cycomachead

Two comments: The name code is a little too generic? I don’t immediately have another name that’s short. example code_with_solutions assignment_code … maybe code is best since there’s no harm in using this for any code file, and it could syntax highlight, eventually. (oh we’ll need to use a custom theme for that!)

For the argument to show a solution ({% code questions/sample_question.py true %}) is there a way to use show_solution=true or maybe require that it be named? boolean args are kind of challenge to interpret.
I am OK if that makes people write show_solution=page.show_solutions or something. If that’s a common enough use, maybe the plugin can read page variables, or even entire site variables…

@.phrdang

Yeah I wasn’t sure what the best name was. We could do include_code maybe? example and assignment_code might be too specific since you can theoretically include code for any reason (to show an example, to show problem starter code, to show the solution), etc.

I could definitely make it required to be named. Right now everything after the tag name is parsed as a string so we could just require show_solution= to be at the start

@cycomachead cycomachead merged commit 31dac9a into main Aug 16, 2024
6 checks passed
@cycomachead cycomachead deleted the python-plugin branch August 16, 2024 23:39
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.

Figure out how to hide solutions from included python files
2 participants