From 544f64075bc42a2935624403201c78468e180d3d Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Thu, 19 Oct 2023 11:17:23 -0400 Subject: [ruby/prism] Add RBI and RBS templates for Prism https://github.com/ruby/prism/commit/b62305ff3e Co-authored-by: Stan Lo --- prism/templates/template.rb | 72 +++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 28 deletions(-) (limited to 'prism') diff --git a/prism/templates/template.rb b/prism/templates/template.rb index 4435333900..e55f92111c 100755 --- a/prism/templates/template.rb +++ b/prism/templates/template.rb @@ -290,33 +290,47 @@ module Prism template = File.expand_path("../#{filepath}", __dir__) erb = read_template(template) - - non_ruby_heading = <<~HEADING - /******************************************************************************/ - /* This file is generated by the templates/template.rb script and should not */ - /* be modified manually. See */ - /* #{filepath + " " * (74 - filepath.size) } */ - /* if you are looking to modify the */ - /* template */ - /******************************************************************************/ - HEADING - - ruby_heading = <<~HEADING - # frozen_string_literal: true - =begin - This file is generated by the templates/template.rb script and should not be - modified manually. See #{filepath} - if you are looking to modify the template - =end - - HEADING - - heading = - if File.extname(filepath.gsub(".erb", "")) == ".rb" - ruby_heading - else - non_ruby_heading - end + extension = File.extname(filepath.gsub(".erb", "")) + + heading = case extension + when ".rb" + <<~HEADING + # frozen_string_literal: true + =begin + This file is generated by the templates/template.rb script and should not be + modified manually. See #{filepath} + if you are looking to modify the template + =end + + HEADING + when ".rbs" + <<~HEADING + # This file is generated by the templates/template.rb script and should not be + # modified manually. See #{filepath} + # if you are looking to modify the template + + HEADING + when ".rbi" + <<~HEADING + # typed: true + + =begin + This file is generated by the templates/template.rb script and should not be + modified manually. See #{filepath} + if you are looking to modify the template + =end + HEADING + else + <<~HEADING + /******************************************************************************/ + /* This file is generated by the templates/template.rb script and should not */ + /* be modified manually. See */ + /* #{filepath + " " * (74 - filepath.size) } */ + /* if you are looking to modify the */ + /* template */ + /******************************************************************************/ + HEADING + end write_to ||= File.expand_path("../#{name}", __dir__) contents = heading + erb.result_with_hash(locals) @@ -376,7 +390,9 @@ module Prism "src/node.c", "src/prettyprint.c", "src/serialize.c", - "src/token_type.c" + "src/token_type.c", + "rbi/prism.rbi", + "sig/prism.rbs", ] end -- cgit v1.2.3