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

Update existing code blocks in curriculum content with new formatting #39839

Merged
merged 1 commit into from Mar 31, 2021

Conversation

Hamms
Copy link
Contributor

@Hamms Hamms commented Mar 31, 2021

Pass 1: The Easy Stuff

This PR contains updates to only those blocks that we can trivially identify. This includes blocks that explicitly specify an IDE and blocks for which there are not multiple results for different IDEs.

Used the following ruby script:

BLOCK_RE = /`(?:(?<ide>\w*)\/)?(?<block>[^\(]*)(?<args>\([^\)]*\))?`/

def replace_blocks(text)
  text.gsub(/(?<!\[)`[^`]*`/) do |content|
    match = BLOCK_RE.match(content)
    if match.present?
      query = ProgrammingExpression.joins(:programming_environment)
      query = query.where(
        programming_environment: ProgrammingEnvironment.find_by(name: match[:ide])
      ) if match[:ide]
      query = query.where(name: match[:block])

      if query.count == 1
        pe = query.first
        block = "`#{pe.name}#{match[:args] || ""}`"
        block += "(#{pe.color})" if pe.color
        result = pe.documentation_path ? "[#{block}](#{pe.documentation_path})" : block
        result
      else
        content
      end
    else
      content
    end
  end
end

Follow-up work

Next up, we'll update blocks that couldn't be uniquely identified, by figuring how to map each instance to the appropriate programming environment. Finally, we'll do a pass of blocks that couldn't be mapped to a programming expression at all, just to verify that there aren't any expressions hiding in that set.

PR Checklist:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@Hamms Hamms marked this pull request as ready for review March 31, 2021 19:07
@Hamms Hamms requested a review from a team March 31, 2021 19:07
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.

None yet

2 participants