Proposal: ERB Support
ERB is a widely used template library in Ruby. It is adopted as the default view library in Ruby on Rails. It is one of the popular template libraries in Ruby. I believe it's valuable to support it in Steep.
Three enhancements are necessary to let Steep support ERB.
- Allow to change the target file extension
- Convert ERB code into Ruby before type-checking
- Allow to change the "self" context via global-level annotation
Allow to change the target file extension
At present, Steep expects the target source code to be ".rb". It is hard-coded in some modules.
https://github.com/soutaro/steep/blob/81da4a1172fa61551ec4f0d871fb5ed7cd588d2f/lib/steep/project/dsl.rb#L105-L107 https://github.com/soutaro/steep/blob/81da4a1172fa61551ec4f0d871fb5ed7cd588d2f/lib/steep/server/master.rb#L422-L425
It would be better to specify file extension in Steepfile:
target :views do
check "app/views"
ext ".erb"
end
Convert ERB code into Ruby before type-checking
ERB to Ruby code conversion is needed to type-check ERB.
Input:
<html>
<body>
<ul>
<% languages.each do |langage| %>
<li><%= language %>
<% end %>
</ul>
</body>
</html>
Output: (replace HTML tags with whitespace)
languages.each do |langage|
language
end
Allow to change the "self" context via global-level annotation
In the Rails application, some instance variables and helper methods are given from other components (controllers, helpers, ActionView, and so on).
Therefore, it is needed to switch the "self" context at the global level.
<%# @type self: MyERBTemplate %>
<%= @some_instance_variables %>
<% some_helper_methods %>
It must be helpful if we'll support other DSLs.
For example, we'll also be able to support Gemfile and Raketask:
# @type self: Gemfile
gem 'some_gem'
gem 'another_gem'
# @type self: Raketask
desc "my task"
task :my_task do
...
end
namespace :new_group do
...
end