Skip to content

Commit

Permalink
add explainer comments for format and variant extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
joelhawksley committed Sep 10, 2024
1 parent 34ca335 commit 570faeb
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/view_component/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,13 @@ def gather_templates
ActionView::Template.template_handler_extensions
).map do |path|
# Extract format and variant from template filename
# foo.html.erb => :html, nil
# foo.html+phone.erb => :html, :phone
# variants_component.html+mini.watch.erb => :html, :'mini.watch'
this_format, variant =
File.basename(path).split(".")[1..-2].join(".").split("+").map(&:to_sym)
File
.basename(path) # "variants_component.html+mini.watch.erb"
.split(".")[1..-2] # ["html+mini", "watch"]
.join(".") # "html+mini.watch"
.split("+") # ["html", "mini.watch"]
.map(&:to_sym) # [:html, :"mini.watch"]

out = Template.new(
component: @component,
Expand Down

0 comments on commit 570faeb

Please sign in to comment.