html: add controller & action attributes to <body> tag (#3844).
This commit is contained in:
@@ -192,12 +192,27 @@ module ApplicationHelper
|
||||
attributes = [:id, :name, :level, :level_string, :can_approve_posts?, :can_upload_free?]
|
||||
attributes += User::Roles.map { |role| :"is_#{role}?" }
|
||||
|
||||
controller_param = params[:controller].parameterize.dasherize
|
||||
action_param = params[:action].parameterize.dasherize
|
||||
|
||||
{
|
||||
lang: "en",
|
||||
class: "c-#{controller_param} a-#{action_param}",
|
||||
data: {
|
||||
controller: controller_param,
|
||||
action: action_param,
|
||||
**data_attributes_for(user, "user", attributes)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def data_attributes_for(record, prefix, attributes)
|
||||
attributes.map do |attr|
|
||||
name = attr.to_s.dasherize.delete("?")
|
||||
value = user.send(attr)
|
||||
value = record.send(attr)
|
||||
|
||||
%{data-user-#{name}="#{h(value)}"}
|
||||
end.join(" ").html_safe
|
||||
[:"#{prefix}-#{name}", value]
|
||||
end.to_h
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
@@ -117,7 +117,7 @@ PostModeMenu.change = function() {
|
||||
return;
|
||||
}
|
||||
var $body = $(document.body);
|
||||
$body.removeClass();
|
||||
$body.removeClass((i, classNames) => classNames.split(/ /).filter(name => /^mode-/.test(name)).join(" "));
|
||||
$body.addClass("mode-" + s);
|
||||
Cookie.put("mode", s, 1);
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body lang="en" <%= body_attributes(CurrentUser.user) %>>
|
||||
<%= tag.body **body_attributes(CurrentUser.user) do %>
|
||||
<header id="top">
|
||||
<%= render "news_updates/listing" %>
|
||||
|
||||
@@ -137,5 +137,5 @@
|
||||
</div>
|
||||
|
||||
<%= render "static/footer" %>
|
||||
</body>
|
||||
<% end %>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user