Replace content_tag with new tag builder syntax

One of the main advantages of this syntax is we can now omit the content
parameter when it's empty.
This commit is contained in:
Javi Martín
2019-06-21 00:57:06 +02:00
parent fa070f326e
commit 749428d93f
16 changed files with 36 additions and 39 deletions

View File

@@ -1,7 +1,7 @@
module Admin::LocalCensusRecords::ImportsHelper module Admin::LocalCensusRecords::ImportsHelper
def errors_for(resource, field) def errors_for(resource, field)
if resource.errors.include? field if resource.errors.include? field
content_tag :div, class: "error" do tag.div class: "error" do
resource.errors[field].join(", ") resource.errors[field].join(", ")
end end
end end

View File

@@ -40,7 +40,7 @@ module ApplicationHelper
def back_link_to(destination = :back, text = t("shared.back")) def back_link_to(destination = :back, text = t("shared.back"))
link_to destination, class: "back" do link_to destination, class: "back" do
content_tag(:span, nil, class: "icon-angle-left") + text tag.span(class: "icon-angle-left") + text
end end
end end

View File

@@ -21,8 +21,8 @@ module BannersHelper
def banner_target_link(banner) def banner_target_link(banner)
link_to banner.target_url do link_to banner.target_url do
content_tag(:h2, banner.title, style: "color:#{banner.font_color}") + tag.h2(banner.title, style: "color:#{banner.font_color}") +
content_tag(:h3, banner.description, style: "color:#{banner.font_color}") tag.h3(banner.description, style: "color:#{banner.font_color}")
end end
end end
end end

View File

@@ -10,7 +10,7 @@ module BudgetInvestmentsHelper
translation = t("admin.budget_investments.index.list.#{column}") translation = t("admin.budget_investments.index.list.#{column}")
link_to( link_to(
safe_join([translation, content_tag(:span, "", class: "icon-sortable #{icon}")]), safe_join([translation, tag.span(class: "icon-sortable #{icon}")]),
admin_budget_budget_investments_path(sort_by: column, direction: direction) admin_budget_budget_investments_path(sort_by: column, direction: direction)
) )
end end

View File

@@ -4,9 +4,9 @@ module BudgetsHelper
end end
def heading_name_and_price_html(heading, budget) def heading_name_and_price_html(heading, budget)
content_tag :div do tag.div do
concat(heading.name + " ") concat(heading.name + " ")
concat(content_tag(:span, budget.formatted_heading_price(heading))) concat(tag.span(budget.formatted_heading_price(heading)))
end end
end end

View File

@@ -45,7 +45,7 @@ module DocumentsHelper
def document_item_link(document) def document_item_link(document)
info_text = "#{document.humanized_content_type} | #{number_to_human_size(document.attachment_file_size)}" info_text = "#{document.humanized_content_type} | #{number_to_human_size(document.attachment_file_size)}"
link_to safe_join([document.title, content_tag(:small, "(#{info_text})")], " "), link_to safe_join([document.title, tag.small("(#{info_text})")], " "),
document.attachment.url, document.attachment.url,
target: "_blank", target: "_blank",
title: t("shared.target_blank") title: t("shared.target_blank")

View File

@@ -71,7 +71,7 @@ module GlobalizeHelper
current_translation = resource.translation_for(selected_locale(resource)) current_translation = resource.translation_for(selected_locale(resource))
if current_translation.errors.added? :base, :translations_too_short if current_translation.errors.added? :base, :translations_too_short
content_tag :div, class: "small error" do tag.div class: "small error" do
current_translation.errors[:base].join(", ") current_translation.errors[:base].join(", ")
end end
end end

View File

@@ -1,7 +1,7 @@
module LayoutsHelper module LayoutsHelper
def layout_menu_link_to(text, path, is_active, options) def layout_menu_link_to(text, path, is_active, options)
if is_active if is_active
content_tag(:span, t("shared.you_are_in"), class: "show-for-sr") + " " + tag.span(t("shared.you_are_in"), class: "show-for-sr") + " " +
link_to(text, path, options.merge(class: "is-active")) link_to(text, path, options.merge(class: "is-active"))
else else
link_to(text, path, options) link_to(text, path, options)

View File

@@ -25,16 +25,15 @@ module MapLocationsHelper
def render_map(map_location, parent_class, editable, remove_marker_label, investments_coordinates = nil) def render_map(map_location, parent_class, editable, remove_marker_label, investments_coordinates = nil)
map_location = MapLocation.new if map_location.nil? map_location = MapLocation.new if map_location.nil?
map = content_tag :div, "", map = tag.div id: dom_id(map_location),
id: dom_id(map_location), class: "map_location map",
class: "map_location map", data: prepare_map_settings(map_location, editable, parent_class, investments_coordinates)
data: prepare_map_settings(map_location, editable, parent_class, investments_coordinates)
map += map_location_remove_marker(map_location, remove_marker_label) if editable map += map_location_remove_marker(map_location, remove_marker_label) if editable
map map
end end
def map_location_remove_marker(map_location, text) def map_location_remove_marker(map_location, text)
content_tag :div, class: "margin-bottom" do tag.div class: "margin-bottom" do
content_tag :a, content_tag :a,
id: map_location_remove_marker_link_id(map_location), id: map_location_remove_marker_link_id(map_location),
href: "#", href: "#",

View File

@@ -2,17 +2,15 @@ module MilestonesHelper
def progress_tag_for(progress_bar) def progress_tag_for(progress_bar)
text = number_to_percentage(progress_bar.percentage, precision: 0) text = number_to_percentage(progress_bar.percentage, precision: 0)
content_tag :div, class: "progress", tag.div class: "progress",
role: "progressbar", role: "progressbar",
"aria-valuenow": "#{progress_bar.percentage}", "aria-valuenow": "#{progress_bar.percentage}",
"aria-valuetext": "#{progress_bar.percentage}%", "aria-valuetext": "#{progress_bar.percentage}%",
"aria-valuemax": ProgressBar::RANGE.max, "aria-valuemax": ProgressBar::RANGE.max,
"aria-valuemin": "0", "aria-valuemin": "0",
tabindex: "0" do tabindex: "0" do
content_tag(:span, "", tag.span(class: "progress-meter", style: "width: #{progress_bar.percentage}%;") +
class: "progress-meter", tag.p(text, class: "progress-meter-text")
style: "width: #{progress_bar.percentage}%;") +
content_tag(:p, text, class: "progress-meter-text")
end end
end end
end end

View File

@@ -2,7 +2,7 @@ module StatsHelper
def chart_tag(opt = {}) def chart_tag(opt = {})
opt[:data] ||= {} opt[:data] ||= {}
opt[:data][:graph] = admin_api_stats_path(chart_data(opt)) opt[:data][:graph] = admin_api_stats_path(chart_data(opt))
content_tag :div, "", opt tag.div opt
end end
def chart_data(opt = {}) def chart_data(opt = {})
@@ -26,7 +26,7 @@ module StatsHelper
def budget_investments_chart_tag(opt = {}) def budget_investments_chart_tag(opt = {})
opt[:data] ||= {} opt[:data] ||= {}
opt[:data][:graph] = admin_api_stats_path(budget_investments: true) opt[:data][:graph] = admin_api_stats_path(budget_investments: true)
content_tag :div, "", opt tag.div opt
end end
def number_to_stats_percentage(number, options = {}) def number_to_stats_percentage(number, options = {})
@@ -34,9 +34,9 @@ module StatsHelper
end end
def number_with_info_tags(number, text, html_class: "") def number_with_info_tags(number, text, html_class: "")
content_tag :p, class: "number-with-info #{html_class}".strip do tag.p class: "number-with-info #{html_class}".strip do
content_tag :span, class: "content" do tag.span class: "content" do
content_tag(:span, number, class: "number") + content_tag(:span, text, class: "info") tag.span(number, class: "number") + tag.span(text, class: "info")
end end
end end
end end

View File

@@ -34,7 +34,7 @@ module TranslatableFormHelper
def fields_for_locale(locale) def fields_for_locale(locale)
fields_for_translation(@translations[locale]) do |translations_form| fields_for_translation(@translations[locale]) do |translations_form|
@template.content_tag :div, translations_options(translations_form.object, locale) do @template.tag.div translations_options(translations_form.object, locale) do
@template.concat translations_form.hidden_field( @template.concat translations_form.hidden_field(
:_destroy, :_destroy,
value: !@template.enabled_locale?(translations_form.object.globalized_model, locale), value: !@template.enabled_locale?(translations_form.object.globalized_model, locale),

View File

@@ -15,8 +15,8 @@ module UsersHelper
if commentable.nil? if commentable.nil?
deleted_commentable_text(comment) deleted_commentable_text(comment)
elsif commentable.hidden? elsif commentable.hidden?
content_tag(:del, commentable.title) + " " + tag.del(commentable.title) + " " +
content_tag(:span, "(" + deleted_commentable_text(comment) + ")", class: "small") tag.span("(#{deleted_commentable_text(comment)})", class: "small")
else else
link_to(commentable.title, comment) link_to(commentable.title, comment)
end end

View File

@@ -21,7 +21,7 @@
<tbody> <tbody>
<% @officer_assignments.each do |officer_assignment| %> <% @officer_assignments.each do |officer_assignment| %>
<tr id="<%= dom_id officer_assignment %>"> <tr id="<%= dom_id officer_assignment %>">
<td><%= l(officer_assignment.date.to_date) %> <%= content_tag :strong, t("polls.final_date") if officer_assignment.final %></td> <td><%= l(officer_assignment.date.to_date) %> <%= tag.strong t("polls.final_date") if officer_assignment.final %></td>
<td><%= booth_name_with_location(officer_assignment.booth_assignment.booth) %></td> <td><%= booth_name_with_location(officer_assignment.booth_assignment.booth) %></td>
</tr> </tr>
<% end %> <% end %>

View File

@@ -7,8 +7,8 @@
<div id="budget-investments" class="budget-investments-list small-12 medium-9 column"> <div id="budget-investments" class="budget-investments-list small-12 medium-9 column">
<div class="small-12 search-results"> <div class="small-12 search-results">
<%= content_tag(:h2, t("management.budget_investments.filters.unfeasible")) if params[:unfeasible].present? %> <%= tag.h2 t("management.budget_investments.filters.unfeasible") if params[:unfeasible].present? %>
<%= content_tag(:h2, t("management.budget_investments.filters.heading", heading: @heading.name)) if @heading.present? %> <%= tag.h2 t("management.budget_investments.filters.heading", heading: @heading.name) if @heading.present? %>
<% if params[:search].present? %> <% if params[:search].present? %>
<h2> <h2>
<%= page_entries_info @investments %> <%= page_entries_info @investments %>

View File

@@ -21,7 +21,7 @@ class ConsulFormBuilder < FoundationRailsHelper::FormBuilder
def check_box(attribute, options = {}) def check_box(attribute, options = {})
if options[:label] != false if options[:label] != false
label = content_tag(:span, sanitize(label_text(object, attribute, options[:label])), class: "checkbox") label = tag.span sanitize(label_text(object, attribute, options[:label])), class: "checkbox"
super(attribute, options.merge(label: label, label_options: label_options_for(options))) super(attribute, options.merge(label: label, label_options: label_options_for(options)))
else else
@@ -70,7 +70,7 @@ class ConsulFormBuilder < FoundationRailsHelper::FormBuilder
def help_text(attribute, options) def help_text(attribute, options)
if options[:hint] if options[:hint]
content_tag :span, options[:hint], class: "help-text", id: help_text_id(attribute, options) tag.span options[:hint], class: "help-text", id: help_text_id(attribute, options)
end end
end end