-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
106 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,26 @@ | ||
module ScopeHelper | ||
def build_scopes(scopes, api) | ||
scopes_tree = {} | ||
scopes.each do |scope| | ||
splitted_scope = humanize_scope(scope, api).split('||').map(&:strip) | ||
build_scopes_parts(scopes_tree, splitted_scope) | ||
end | ||
scopes_tree | ||
end | ||
|
||
private | ||
|
||
def humanize_scope(scope, api) | ||
I18n.t("api_#{api}.tokens.token.scope.#{scope}.label", default: scope.humanize) | ||
end | ||
|
||
def build_scopes_parts(scopes_tree, splitted_scope) | ||
if splitted_scope.size > 2 | ||
scopes_tree[splitted_scope[0]] ||= {} | ||
build_scopes_parts(scopes_tree[splitted_scope[0]], splitted_scope[1..]) | ||
elsif splitted_scope.size > 1 | ||
scopes_tree[splitted_scope[0]] ||= [] | ||
scopes_tree[splitted_scope[0]].push(splitted_scope[1]) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<% if scopes.is_a?(Array) %> | ||
<ul> | ||
<% scopes.each do |scope| %> | ||
<li><%= scope %></li> | ||
<% end %> | ||
</ul> | ||
<% else %> | ||
<% scopes.each_pair do |key, values| %> | ||
<section class="fr-accordion"> | ||
<span class="fr-accordion__title" tabindex="0" > | ||
<button class="fr-accordion__btn" aria-expanded="false" aria-controls="accordion-<%= key %>"> | ||
<%= key %> | ||
</button> | ||
</span> | ||
<div class="fr-collapse" id="accordion-<%= key %>"> | ||
<%= render partial: 'shared/tokens/scopes', | ||
locals: { | ||
scopes: values, | ||
scope_type: key, | ||
} | ||
%> | ||
</div> | ||
</section> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters