Skip to content

Commit

Permalink
Merge pull request #1744 from ruby/uk-improve-erb-comment-gen
Browse files Browse the repository at this point in the history
Improve comment generation in templates
  • Loading branch information
kddnewton authored Oct 30, 2023
2 parents 4ff8fe2 + dee76b5 commit 5ac0d77
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
6 changes: 5 additions & 1 deletion templates/java/org/prism/Nodes.java.erb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ public abstract class Nodes {
<%# NODES -%>
<%- nodes.each do |node| -%>

<%= "#{node.comment.split("\n").map { |line| "// #{line}" }.join("\n ")}\n" if node.comment -%>
/**
<%- node.comment.each_line do |line| -%>
*<%= line.prepend(" ").rstrip %>
<%- end -%>
*/
public static final class <%= node.name -%> extends Node {
<%- if node.needs_serialized_length? -%>
public final int serializedLength;
Expand Down
4 changes: 3 additions & 1 deletion templates/javascript/src/nodes.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ const <%= flag.name %> = {
<%- nodes.each do |node| -%>

/**
<%= "#{node.comment.split("\n").map { |line| line.empty? ? " *" : " * #{line}" }.join("\n")}" %>
<%- node.comment.each_line do |line| -%>
*<%= line.prepend(" ").rstrip %>
<%- end -%>
*/
export class <%= node.name -%> {
<%- node.fields.each do |field| -%>
Expand Down
5 changes: 4 additions & 1 deletion templates/lib/prism/node.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ module Prism
end
<%- nodes.each do |node| -%>
<%= "#{node.comment.split("\n").map { |line| line.empty? ? "#" : "# #{line}" }.join("\n ")}\n " if node.comment %>class <%= node.name -%> < Node
<%- node.comment.each_line do |line| -%>
#<%= line.prepend(" ").rstrip %>
<%- end -%>
class <%= node.name -%> < Node
<%- node.fields.each do |field| -%>
# attr_reader <%= field.name %>: <%= field.rbs_class %>
<%= "private " if field.is_a?(Prism::FlagsField) %>attr_reader :<%= field.name %>
Expand Down
5 changes: 4 additions & 1 deletion templates/rbi/prism.rbi.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@

module Prism
<%- nodes.each do |node| -%>
<%= "#{node.comment.split("\n").map { |line| line.empty? ? "#" : "# #{line}" }.join("\n ")}\n " if node.comment %>class <%= node.name -%> < Node
<%- node.comment.each_line do |line| -%>
#<%= line.prepend(" ").rstrip %>
<%- end -%>
class <%= node.name -%> < Node
<%- node.fields.each do |field| -%>
sig { returns(<%= field.rbi_class %>) }
attr_reader :<%= field.name %>
Expand Down
5 changes: 4 additions & 1 deletion templates/sig/prism.rbs.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
module Prism
<%- nodes.each do |node| -%>
<%= "#{node.comment.split("\n").map { |line| line.empty? ? "#" : "# #{line}" }.join("\n ")}\n " if node.comment %>class <%= node.name -%> < Node
<%- node.comment.each_line do |line| -%>
#<%= line.prepend(" ").rstrip %>
<%- end -%>
class <%= node.name -%> < Node
<%- node.fields.each do |field| -%>
attr_reader <%= field.name %>: <%= field.rbs_class %>
<%- end -%>
Expand Down

0 comments on commit 5ac0d77

Please sign in to comment.