Skip to content

Convert ERB files to Ruby structures that can generate AST#13

Merged
andreimid merged 4 commits intomainfrom
andrei/parse-erb-files
Mar 31, 2025
Merged

Convert ERB files to Ruby structures that can generate AST#13
andreimid merged 4 commits intomainfrom
andrei/parse-erb-files

Conversation

@andreimid
Copy link
Contributor

  • Attempts to convert ERB file to a HEREDOC string that can be parsed and an AST can be generated from
  • Falls back to wrapping the entire file in a HEREDOC if the transformation fails
app_name: <%= ENV['APP_NAME'] %>
version: <%= ENV['APP_VERSION'] %>

database:
  host: <%= ENV['DB_HOST'] %>
  port: <%= ENV['DB_PORT'] %>

<% if ENV['USE_REDIS'] == 'true' %>
redis:
  host: <%= ENV['REDIS_HOST'] %>
  port: <%= ENV['REDIS_PORT'] %>
<% end %>

Gets converted to:

<<~HEREDOC
  app_name: #{ENV['APP_NAME']}
  version: #{ENV['APP_VERSION']}
  database:
    host: #{ENV['DB_HOST']}
    port: #{ENV['DB_PORT']}
  #{
    if ENV['USE_REDIS'] == 'true'
      "redis:\n  host: #{ENV['REDIS_HOST']}\n  port: #{ENV['REDIS_PORT']}"
    else
      ""
    end
  }
HEREDOC

@andreimid andreimid self-assigned this Mar 28, 2025
Copy link
Contributor

@DavidBakerEffendi DavidBakerEffendi left a comment

Choose a reason for hiding this comment

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

Could you also add some tests to basically check the cases where the transform works and where it doesn't? No need to test the resulting ASTs

@andreimid andreimid merged commit 364750f into main Mar 31, 2025
1 check passed
@andreimid andreimid changed the title WIP: Convert ERB files to Ruby structures that can generate AST Convert ERB files to Ruby structures that can generate AST Mar 31, 2025
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