Skip to content

Strategy for breaking apart an html tag? #80

Answered by stephannv
robacarp asked this question in Q&A
Discussion options

You must be logged in to vote

I think you could improve this grouping the dates by week, eg.

dates = Time.utc(2024, 9, 2).step(to: Time.utc(2024, 11, 2), by: 1.day)
grouped_by_week = dates.group_by(&.calendar_week)

grouped_by_week.each do |_week, week_dates|
  tr do
    week_dates.each do |date|  
      td do
        # ... code here
      end
    end
  end
end

Another solution is using grid layout, so you wouldn't need to control the rows with html structure, just an element with multiple elements inside.

<style>
  ol.calendar {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }
  ol.calendar > li {
    aspect-ratio: 1 / 1;
  }
</style>

<ol class="calendar">
  <li>29</li>
  <li>30</li>
  <li>1

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@robacarp
Comment options

Answer selected by robacarp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants