noesya/osuny

View on GitHub
app/views/admin/communication/blocks/templates/posts/layouts/_highlight.html.erb

Summary

Maintainability
Test Coverage
<% 
heading_level = block.heading_rank_children
date_format = "%e %B %Y"
highlight_post = block.template.selected_posts.first
highlight_post_l10n = highlight_post&.localization_for(block.language)
highlight_permalink = highlight_post_l10n.current_permalink_url_in_website(@website)
%>
<div class="highlight">
  <div class="highlight-post">
    <article class="post" itemprop="blogPosts" itemscope itemtype="http://schema.org/BlogPosting">
      <div class="post-content">
        <h<%= heading_level %> class='post-title' itemprop='headline'>
          <%= link_to_if highlight_permalink, highlight_post_l10n, highlight_permalink %>
        </h<%= heading_level %>>
        <% if highlight_post_l10n.summary.present? && block.template.option_summary %>
          <p itemprop="articleBody"><%= highlight_post_l10n.summary %></p>
        <% end %>
        <% if block.template.option_author || block.template.option_date %>
          <div class="post-meta">
            <% if block.template.option_date %>
              <time itemprop="datePublished" datetime="<%= highlight_post_l10n.published_at %>"><%= l(highlight_post_l10n.published_at, format: date_format) %></time>
            <% end %>
            <% if block.template.option_author %>
              <div class="post-author" itemscope itemtype="https://schema.org/Person" itemprop="author">
                <p itemprop="name"><%= highlight_post.author&.to_s_in(block.language) %></p>
              </div>
            <% end %>
          </div>
        <% end %>
        <% if !highlight_post.categories.empty? && block.template.option_categories %>
          <ul class="post-categories">
            <% highlight_post.categories.each do |category| %>
              <%
              category_l10n = category.localization_for(block.language)
              next if category_l10n.nil?
              %>
              <%= link_to category_l10n, category_l10n.current_permalink_url_in_website(@website) %>
            <% end %>
          </ul>
        <% end %>
      </div>
      <% if block.template.option_image %>
        <div class="media">
          <% if highlight_post_l10n.best_featured_image.attached? %>
            <%= kamifusen_tag highlight_post_l10n.best_featured_image %>
          <% end %>
        </div>
      <% end %>
    </article>
  </div>

  <div class="list">
    <% 
    block.template.selected_posts.each do |post|
      next if post.nil?
      post_l10n = post.localization_for(block.language)
      permalink = post_l10n.current_permalink_url_in_website(@website)
    %>
      <article class="post" itemprop="blogPosts" itemscope itemtype="http://schema.org/BlogPosting">
        <div class="post-content">
          <h<%= heading_level %> class='post-title' itemprop='headline'>
            <%= link_to_if permalink, post_l10n, permalink %>
          </h<%= heading_level %>>
          <% if post_l10n.summary.present? && block.template.option_summary %>
            <p itemprop="articleBody"><%= post_l10n.summary %></p>
          <% end %>
          <% if block.template.option_author || block.template.option_date %>
            <div class="post-meta">
              <% if block.template.option_date %>
                <time itemprop="datePublished" datetime="<%= post_l10n.published_at %>"><%= l(post_l10n.published_at, format: date_format) %></time>
              <% end %>
              <% if block.template.option_author %>
                <div class="post-author" itemscope itemtype="https://schema.org/Person" itemprop="author">
                  <p itemprop="name"><%= post.author&.to_s_in(block.language) %></p>
                </div>
              <% end %>
            </div>
          <% end %>
          <% if !post.categories.empty? && block.template.option_categories %>
            <ul class="post-categories">
              <% post.categories.each do |category| %>
                <%
                category_l10n = category.localization_for(block.language)
                next if category_l10n.nil?
                %>
                <%= link_to category_l10n, category_l10n.current_permalink_url_in_website(@website) %>
              <% end %>
            </ul>
          <% end %>
        </div>
        <% if block.template.option_image %>
          <div class="media">
            <% if post_l10n.best_featured_image.attached? %>
              <%= kamifusen_tag post_l10n.best_featured_image %>
            <% end %>
          </div>
        <% end %>
      </article>
    <% end %>
  </div>
</div>