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 = [:id, :name, :level, :level_string, :can_approve_posts?, :can_upload_free?]
|
||||||
attributes += User::Roles.map { |role| :"is_#{role}?" }
|
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|
|
attributes.map do |attr|
|
||||||
name = attr.to_s.dasherize.delete("?")
|
name = attr.to_s.dasherize.delete("?")
|
||||||
value = user.send(attr)
|
value = record.send(attr)
|
||||||
|
|
||||||
%{data-user-#{name}="#{h(value)}"}
|
[:"#{prefix}-#{name}", value]
|
||||||
end.join(" ").html_safe
|
end.to_h
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ PostModeMenu.change = function() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var $body = $(document.body);
|
var $body = $(document.body);
|
||||||
$body.removeClass();
|
$body.removeClass((i, classNames) => classNames.split(/ /).filter(name => /^mode-/.test(name)).join(" "));
|
||||||
$body.addClass("mode-" + s);
|
$body.addClass("mode-" + s);
|
||||||
Cookie.put("mode", s, 1);
|
Cookie.put("mode", s, 1);
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body lang="en" <%= body_attributes(CurrentUser.user) %>>
|
<%= tag.body **body_attributes(CurrentUser.user) do %>
|
||||||
<header id="top">
|
<header id="top">
|
||||||
<%= render "news_updates/listing" %>
|
<%= render "news_updates/listing" %>
|
||||||
|
|
||||||
@@ -137,5 +137,5 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= render "static/footer" %>
|
<%= render "static/footer" %>
|
||||||
</body>
|
<% end %>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user