Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Globally replace use of content_tag with tag.<el> #477

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/views/kaminari/trestle/_first_page.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
<% if current_page.first? %>
<span class="page-link">&laquo;</span>
<% else %>
<%= link_to content_tag(:span, "&laquo;".html_safe), url, class: "page-link", remote: remote %>
<%= link_to tag.span("&laquo;".html_safe), url, class: "page-link", remote: remote %>
<% end %>
</li>
2 changes: 1 addition & 1 deletion app/views/kaminari/trestle/_last_page.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
<% if current_page.last? %>
<span class="page-link">&raquo;</span>
<% else %>
<%= link_to content_tag(:span, "&raquo;".html_safe), url, class: "page-link", remote: remote %>
<%= link_to tag.span("&raquo;".html_safe), url, class: "page-link", remote: remote %>
<% end %>
</li>
2 changes: 1 addition & 1 deletion app/views/kaminari/trestle/_page.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
remote: data-remote
-%>
<li class="page-item<% if page.current? %> active<% end %>">
<%= link_to content_tag(:span, page), url, class: "page-link", remote: remote, rel: page.next? ? 'next' : page.prev? ? 'prev' : nil %>
<%= link_to tag.span(page), url, class: "page-link", remote: remote, rel: page.next? ? 'next' : page.prev? ? 'prev' : nil %>
</li>
2 changes: 1 addition & 1 deletion app/views/layouts/trestle/admin.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<%= hook :head %>
</head>

<%= content_tag :body, body_attributes do %>
<%= tag.body(**body_attributes) do %>
<div id="app-wrapper" class="app-wrapper" data-controller="wrapper" data-action="click->wrapper#hideMobileSidebar touchstart->wrapper#hideMobileSidebar" data-wrapper-mobile-sidebar-outlet=".app-sidebar">
<%= render "trestle/shared/sidebar" %>

Expand Down
4 changes: 2 additions & 2 deletions app/views/layouts/trestle/modal.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= content_tag(:div, modal_wrapper_attributes) do %>
<%= content_tag(:div, modal_dialog_attributes) do %>
<%= tag.div(**modal_wrapper_attributes) do %>
<%= tag.div(**modal_dialog_attributes) do %>
<%= yield %>
<% end %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/trestle/application/_tabs.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% if tabs.any? || render_sidebar_as_tab? -%>
<%= content_tag :ul, class: "nav nav-tabs", data: local_assigns.fetch(:data, {}) do %>
<%= tag.ul(class: "nav nav-tabs", data: local_assigns.fetch(:data, {})) do %>
<% tabs.each do |name, tab| %>
<li class="nav-item">
<%= link_to tab.label, "##{tab.id(("modal" if modal_request?))}", class: ["nav-link", ("active" if name == tabs.keys.first)], role: "tab", data: { bs_toggle: "tab" } %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/trestle/resource/_scopes.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= content_tag(:dl, class: admin.scopes.classes) do %>
<%= tag.dl(class: admin.scopes.classes) do %>
<% admin.scopes.grouped.each do |group, scopes| %>
<%= content_tag(:dt, group, class: ["scope-group", ("scope-group-empty" if group.blank?)]) if admin.scopes.grouped? %>
<%= tag.dt(group, class: ["scope-group", ("scope-group-empty" if group.blank?)]) if admin.scopes.grouped? %>

<dd>
<ul class="scope-list">
Expand Down
8 changes: 4 additions & 4 deletions app/views/trestle/shared/_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
<div class="app-sidebar-inner" data-sidebar-target="inner">
<nav class="app-nav" data-controller="navigation">
<% Trestle.navigation(self).each do |group, items| %>
<%= content_tag(:ul, class: ("collapsed" if group.present? && navigation_group_collapsed?(group)), data: { group: group.id }) do %>
<%= tag.ul(class: ("collapsed" if group.present? && navigation_group_collapsed?(group)), data: { group: group.id }) do %>
<% if group.present? %>
<li class="nav-header"><%= link_to content_tag(:span, group.label), "##{group.id}", data: { action: "navigation#toggle" } %></li>
<li class="nav-header"><%= link_to tag.span(group.label), "##{group.id}", data: { action: "navigation#toggle" } %></li>
<% end %>

<% items.each do |item| %>
<%= content_tag(:li, class: ["nav-item", ("active" if current_navigation_item?(item))]) do %>
<%= tag.li(class: ["nav-item", ("active" if current_navigation_item?(item))]) do %>
<%= link_to item.path, item.html_options.merge(data: { controller: "navigation-tooltip" }) do %>
<%= icon("nav-icon", item.icon) %>
<span class="nav-label" data-navigation-tooltip-target="label"><%= item.label %></span>

<%= content_tag(:span, item.badge.text, class: ["badge", item.badge.html_class]) if item.badge? %>
<%= tag.span(item.badge.text, class: ["badge", item.badge.html_class]) if item.badge? %>
<% end %>
<% end %>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/trestle/table/_table.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<% table = table.renderer(self) %>

<div class="table-container">
<%= content_tag(:table, id: table.id, class: table.classes, data: table.data) do %>
<%= tag.table(id: table.id, class: table.classes, data: table.data) do %>
<% if table.header? %>
<thead>
<tr>
<% table.columns.each do |column| %>
<%= content_tag(:th, column.header, class: column.classes, data: column.data) %>
<%= tag.th(column.header, class: column.classes, data: column.data) %>
<% end %>
</tr>
</thead>
Expand Down
2 changes: 1 addition & 1 deletion lib/trestle/form/automatic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def initialize(admin, options={})
if associated_instance = instance.public_send(attribute.association_name)
admin_link_to format_value(associated_instance), associated_instance
else
content_tag(:span, I18n.t("admin.format.blank"), class: "blank")
tag.span(I18n.t("admin.format.blank"), class: "blank")
end
end
else
Expand Down
2 changes: 1 addition & 1 deletion lib/trestle/form/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Form
class Field
attr_reader :builder, :template, :name, :options, :block

delegate :admin, :content_tag, :concat, :safe_join, :icon, to: :template
delegate :admin, :tag, :content_tag, :concat, :safe_join, :icon, to: :template

def initialize(builder, template, name, options={}, &block)
@builder, @template, @name, @block = builder, template, name, block
Expand Down
2 changes: 1 addition & 1 deletion lib/trestle/form/fields/check_box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def field
wrapper_class = options.delete(:class)
wrapper_class = default_wrapper_class if wrapper_class.empty?

content_tag(:div, class: wrapper_class) do
tag.div(class: wrapper_class) do
safe_join([
builder.raw_check_box(name, options.merge(class: input_class), checked_value, unchecked_value),
builder.label(name, options[:label] || admin.human_attribute_name(name), class: label_class, value: (checked_value if options[:multiple]))
Expand Down
2 changes: 1 addition & 1 deletion lib/trestle/form/fields/collection_check_boxes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def field
if block
block.call(b)
else
content_tag(:div, class: default_wrapper_class) do
tag.div(class: default_wrapper_class) do
b.check_box(class: input_class) + b.label(class: label_class) { b.text }
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/trestle/form/fields/collection_radio_buttons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def field
if block
block.call(b)
else
content_tag(:div, class: default_wrapper_class) do
tag.div(class: default_wrapper_class) do
b.radio_button(class: input_class) + b.label(class: label_class) { b.text }
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/trestle/form/fields/date_select.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(builder, template, name, options={}, html_options={}, &block)
end

def field
content_tag(:div, class: "date-select") do
tag.div(class: "date-select") do
builder.raw_date_select(name, options, html_options, &block)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/trestle/form/fields/datetime_select.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(builder, template, name, options={}, html_options={}, &block)
end

def field
content_tag(:div, class: "datetime-select") do
tag.div(class: "datetime-select") do
builder.raw_datetime_select(name, options, html_options, &block)
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/trestle/form/fields/form_control.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def render

def input_group
if @prepend || @append
content_tag(:div, class: "input-group") do
tag.div(class: "input-group") do
concat input_group_addon(@prepend) if @prepend
concat yield
concat input_group_addon(@append) if @append
Expand All @@ -24,7 +24,7 @@ def input_group

def input_group_addon(addon)
if addon[:wrap]
content_tag(:span, addon[:content], class: "input-group-text")
tag.span(addon[:content], class: "input-group-text")
else
addon[:content]
end
Expand Down
8 changes: 4 additions & 4 deletions lib/trestle/form/fields/form_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(builder, template, name=nil, options={}, &block)
end

def render
content_tag(:div, options.except(*WRAPPER_OPTIONS)) do
tag.div(**options.except(*WRAPPER_OPTIONS)) do
concat label if name && options[:label] != false
concat template.capture(&block) if block
concat help_message if options[:help]
Expand All @@ -30,13 +30,13 @@ def help_message
message = options[:help]
end

content_tag(:p, message, class: classes)
tag.p(message, class: classes)
end

def error_messages
content_tag(:ul, class: "invalid-feedback") do
tag.ul(class: "invalid-feedback") do
safe_join(errors.map { |error|
content_tag(:li, safe_join([icon("fa fa-warning"), error], " "))
tag.li(safe_join([icon("fa fa-warning"), error], " "))
}, "\n")
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/trestle/form/fields/radio_button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def field
wrapper_class = options.delete(:class)
wrapper_class = default_wrapper_class if wrapper_class.empty?

content_tag(:div, class: wrapper_class) do
tag.div(class: wrapper_class) do
safe_join([
builder.raw_radio_button(name, tag_value, options.merge(class: input_class)),
builder.label(name, options[:label] || tag_value.to_s.humanize, value: tag_value, class: label_class)
Expand Down
2 changes: 1 addition & 1 deletion lib/trestle/form/fields/static_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def field
if block
template.capture(&block)
else
content_tag(:p, value || default_value, class: "form-control-static")
tag.p(value || default_value, class: "form-control-static")
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/trestle/form/fields/time_select.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(builder, template, name, options={}, html_options={}, &block)
end

def field
content_tag(:div, class: "time-select") do
tag.div(class: "time-select") do
builder.raw_time_select(name, options, html_options, &block)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/trestle/tab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def label
end

def badge
content_tag(:span, options[:badge], class: "badge") if options[:badge]
tag.span(options[:badge], class: "badge") if options[:badge]
end
end
end
2 changes: 1 addition & 1 deletion lib/trestle/table/column.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def initialize(column, table:, template:)
end

def render(instance)
@template.content_tag(:td, content(instance), class: classes, data: data)
@template.tag.td(content(instance), class: classes, data: data)
end

def render?
Expand Down
2 changes: 1 addition & 1 deletion lib/trestle/table/row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def columns
end

def render(instance)
@template.content_tag(:tr, options(instance)) do
@template.tag.tr(**options(instance)) do
@template.safe_join(columns.map { |column| column.render(instance) }, "\n")
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/trestle/toolbar/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Toolbar
class Item
attr_reader :label, :menu

delegate :admin_link_to, :button_tag, :content_tag, :safe_join, :icon, to: :@template
delegate :admin_link_to, :button_tag, :tag, :safe_join, :icon, to: :@template

def initialize(template, label, options={}, &block)
@template = template
Expand All @@ -22,7 +22,7 @@ def ==(other)

def to_s
if menu.items.any?
content_tag(:div, class: "btn-group", role: "group") do
tag.div(class: "btn-group", role: "group") do
safe_join([render, render_menu], "\n")
end
else
Expand Down Expand Up @@ -54,7 +54,7 @@ def button_classes

def button_label(content, options)
icon = icon(@icon) if @icon
label = content_tag(:span, content, class: "btn-label")
label = tag.span(content, class: "btn-label")

safe_join([icon, label].compact, " ")
end
Expand Down Expand Up @@ -102,7 +102,7 @@ def options

def label
safe_join([
super, content_tag(:span, "", class: "caret")
super, tag.span("", class: "caret")
], " ")
end

Expand Down
16 changes: 8 additions & 8 deletions lib/trestle/toolbar/menu.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Trestle
class Toolbar
class Menu
delegate :content_tag, :safe_join, to: :@template
delegate :tag, :safe_join, to: :@template

attr_reader :items

Expand All @@ -18,17 +18,17 @@ def build(&block)
end

def render_toggle(options={})
content_tag(:button, type: "button", class: Array(options[:class]) + ["dropdown-toggle dropdown-toggle-split"], data: { bs_toggle: "dropdown" }, aria: { expanded: false }) do
content_tag(:span, I18n.t("trestle.ui.toggle_dropdown", default: "Toggle dropdown"), class: "visually-hidden")
tag.button(type: "button", class: Array(options[:class]) + ["dropdown-toggle dropdown-toggle-split"], data: { bs_toggle: "dropdown" }, aria: { expanded: false }) do
tag.span(I18n.t("trestle.ui.toggle_dropdown", default: "Toggle dropdown"), class: "visually-hidden")
end
end

def render_items
content_tag(:ul, safe_join(items, "\n"), class: "dropdown-menu dropdown-menu-end", role: "menu")
tag.ul(safe_join(items, "\n"), class: "dropdown-menu dropdown-menu-end", role: "menu")
end

class Builder
delegate :admin_link_to, :content_tag, :tag, to: :@template
delegate :admin_link_to, :tag, to: :@template

def initialize(menu, template)
@menu, @template = menu, template
Expand All @@ -46,15 +46,15 @@ def link(content, instance_or_url=nil, options={}, &block)
end

def header(text)
item { content_tag(:h6, text, class: "dropdown-header") }
item { tag.h6(text, class: "dropdown-header") }
end

def divider
item { tag(:hr, class: "dropdown-divider") }
item { tag.hr(class: "dropdown-divider") }
end

def item(options={}, &block)
item = block_given? ? content_tag(:li, options, &block) : content_tag(:li, "", options)
item = block_given? ? tag.li(**options, &block) : tag.li("", **options)

@menu.items << item

Expand Down
2 changes: 1 addition & 1 deletion sandbox/app/fields/custom_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ def initialize(builder, template, name, options={}, &block)
end

def field
content_tag(:div, "Custom Field", class: "p-2 text-white bg-info font-weight-bold")
tag.div("Custom Field", class: "p-2 text-white bg-info font-weight-bold")
end
end
4 changes: 2 additions & 2 deletions spec/trestle/form/fields/form_control_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
end

context "when options[:prepend!] is present" do
let(:button) { template.content_tag(:button, "Label", class: "btn btn-primary") }
let(:button) { template.tag.button("Label", class: "btn btn-primary") }
let(:options) { { prepend!: button } }

it "prepends the addon within an input group without wrapping" do
Expand All @@ -37,7 +37,7 @@
end

context "when options[:append!] is present" do
let(:button) { template.content_tag(:button, "Label", class: "btn btn-primary") }
let(:button) { template.tag.button("Label", class: "btn btn-primary") }
let(:options) { { append!: button } }

it "appends the addon within an input group without wrapping" do
Expand Down
2 changes: 1 addition & 1 deletion spec/trestle/form/fields/static_field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

context "when passed a block" do
subject do
builder.static_field(:title) { content_tag(:span, "Title from block") }
builder.static_field(:title) { tag.span("Title from block") }
end

it "renders the given block" do
Expand Down