Skip to content

Commit f3ccf31

Browse files
committed
#46: add a navigation label override for models
1 parent f029f8a commit f3ccf31

File tree

11 files changed

+27
-17
lines changed

11 files changed

+27
-17
lines changed

app/controllers/tolaria/resource_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def create
3232
display_name = Tolaria.display_name(@resource)
3333

3434
if @resource.save
35-
flash[:success] = "#{random_blingword} You created the #{@managed_class.model_name.human}#{display_name}”."
35+
flash[:success] = "#{random_blingword} You created the #{@managed_class.navigation_label.singularize}#{display_name}”."
3636
return redirect_to form_completion_redirect_path(@managed_class, @resource)
3737
else
3838
log_validation_errors!
@@ -54,7 +54,7 @@ def update
5454
display_name = Tolaria.display_name(@resource)
5555

5656
if @resource.save
57-
flash[:success] = "#{random_blingword} You updated the #{@managed_class.model_name.human.downcase}#{display_name}”."
57+
flash[:success] = "#{random_blingword} You updated the #{@managed_class.navigation_label.singularize.downcase}#{display_name}”."
5858
return redirect_to form_completion_redirect_path(@managed_class, @resource)
5959
else
6060
log_validation_errors!
@@ -76,7 +76,7 @@ def destroy
7676
return redirect_to form_completion_redirect_path(@managed_class, @resource)
7777
end
7878

79-
flash[:destructive] = "You deleted the #{@managed_class.model_name.human.downcase}#{display_name}”."
79+
flash[:destructive] = "You deleted the #{@managed_class.navigation_label.singularize.downcase}#{display_name}”."
8080
return redirect_to form_completion_redirect_path(@managed_class)
8181

8282
end

app/views/admin/shared/_navigation.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<% if managed_class.allows?(:index) %>
1010
<li>
1111
<%= tolaria_navigation_link(
12-
managed_class.model_name.human.pluralize.titleize,
12+
managed_class.navigation_label,
1313
managed_class.icon,
1414
url_for(action:"index", controller:managed_class.plural)
1515
) %>

app/views/admin/tolaria_resource/_index_table.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
<div class="blank-slate">
66
<span class="blank-slate-icons"><%= fontawesome_icon @managed_class.icon %></span>
77
<h3 class="blank-slate-header">
8-
No <%= @managed_class.model_name.human.pluralize.titleize %> live here.
8+
No <%= @managed_class.navigation_label %> live here.
99
</h3>
1010
<% if @managed_class.allows?(:new) %>
1111
<p class="blank-slate-text">Get started on the first one:</p>
1212
<%= link_to url_for(action:"new"), class:"button -primary" do %>
1313
<%= fontawesome_icon :plus %>
14-
New <%= @managed_class.model_name.human.titleize %>
14+
New <%= @managed_class.navigation_label.singularize %>
1515
<% end %>
1616
<% end %>
1717
</div>
@@ -23,7 +23,7 @@
2323
<div class="blank-slate">
2424
<span class="blank-slate-icons"><%= fontawesome_icon :search %></span>
2525
<h3 class="blank-slate-header">
26-
Your search didn't find any <%= @managed_class.model_name.human.pluralize.titleize %>.
26+
Your search didn't find any <%= @managed_class.navigation_label %>.
2727
</h3>
2828
<p class="blank-slate-text">
2929
You can <%= link_to "clear the search form", url_for([:admin, @managed_class.klass]) %>

app/views/admin/tolaria_resource/_search_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<div class="search-form-controlls">
2020
<%= f.button type:"submit", class:"button -primary", name:nil do %>
2121
<%= fontawesome_icon :search %>
22-
Search <%= @managed_class.model_name.human.pluralize.titleize %>
22+
Search <%= @managed_class.navigation_label %>
2323
<% end %>
2424
<%= link_to url_for([:admin, @managed_class.klass]), class:"button" do %>
2525
<%= fontawesome_icon :close %>

app/views/admin/tolaria_resource/_show_buttons.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
<% if @managed_class.allows?(:edit) %>
99
<%= link_to url_for(action:"edit", id:@resource.id), class:"button -primary" do %>
1010
<%= fontawesome_icon :pencil %>
11-
Edit This <%= @managed_class.model_name.human.titleize %>
11+
Edit This <%= @managed_class.navigation_label.singularize %>
1212
<% end %>
1313
<% end %>

app/views/admin/tolaria_resource/edit.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<% if @resource.persisted? %>
22
<%= content_for :title, "#{Tolaria.display_name(@resource)}" %>
33
<% else %>
4-
<%= content_for :title, "New #{@managed_class.model_name.human.titleize}" %>
4+
<%= content_for :title, "New #{@managed_class.navigation_label.singularize}" %>
55
<% end %>
66

77
<%= form_for [:admin, @resource], url:contextual_form_url, builder:Admin::FormBuilder, html:{class:"resource-form"} do |form_builder| %>
@@ -18,9 +18,9 @@
1818
<span class="crumb">
1919
<%= fontawesome_icon @managed_class.icon %>
2020
<% if @managed_class.allows? :index %>
21-
<%= link_to @managed_class.model_name.human.pluralize.titleize, url_for(action:"index", controller:@managed_class.plural, q:params[:q]) %>
21+
<%= link_to @managed_class.navigation_label, url_for(action:"index", controller:@managed_class.plural, q:params[:q]) %>
2222
<% else %>
23-
<%= @managed_class.model_name.human.pluralize.titleize %>
23+
<%= @managed_class.navigation_label %>
2424
<% end %>
2525
</span>
2626
<%= content_for :title %>

app/views/admin/tolaria_resource/index.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%= content_for :title, "#{@managed_class.model_name.human.pluralize.titleize}" %>
1+
<%= content_for :title, "#{@managed_class.navigation_label}" %>
22

33
<div class="main-controls">
44

@@ -28,7 +28,7 @@
2828
<% if @managed_class.allows?(:new) %>
2929
<%= link_to url_for(action:"new", q:params[:q]), class:"button -primary" do %>
3030
<%= fontawesome_icon :plus %>
31-
New <%= @managed_class.model_name.human.titleize %>
31+
New <%= @managed_class.navigation_label.singularize %>
3232
<% end %>
3333
<% end %>
3434

app/views/admin/tolaria_resource/show.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<span class="crumb">
88
<%= fontawesome_icon @managed_class.icon %>
99
<% if @managed_class.allows? :index %>
10-
<%= link_to @managed_class.model_name.human.pluralize.titleize, url_for(action:"index", controller:@managed_class.plural, q:params[:q]) %>
10+
<%= link_to @managed_class.navigation_label, url_for(action:"index", controller:@managed_class.plural, q:params[:q]) %>
1111
<% else %>
12-
<%= @managed_class.model_name.human.pluralize.titleize %>
12+
<%= @managed_class.navigation_label %>
1313
<% end %>
1414
</span>
1515
<%= content_for :title %>

lib/tolaria/active_record.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class ActiveRecord::Base
3636
# Tolaria will pass this array as the `only:` option to the router.
3737
# The default includes all CRUD actions:
3838
# `[:index, :show, :new, :create, :edit, :update, :destroy]`
39+
# - `:navigation_label` - The navigation label to use for this resource.
40+
# The default is `self.model_name.human.pluralize.titleize`.
3941
#
4042
# #### Example
4143
#

lib/tolaria/managed_class.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ class ManagedClass
3434
# A stored symbol for the `params.permit` key for this resource
3535
attr_accessor :param_key
3636

37+
# A String to override the model's label in the primary admin navigation
38+
attr_accessor :navigation_label
39+
3740
# A factory method that registers a new model in Tolaria and configures
3841
# its menu and param settings. Developers should use `ActiveRecord::Base.manage_with_tolaria`
39-
def self.create(klass, icon:"file-o", permit_params:[], priority:10, category:"Settings", default_order:"id DESC", paginated:true, allowed_actions:[:index, :show, :new, :create, :edit, :update, :destroy])
42+
def self.create(klass, icon:"file-o", permit_params:[], priority:10, category:"Settings", default_order:"id DESC", paginated:true, allowed_actions:[:index, :show, :new, :create, :edit, :update, :destroy], navigation_label: klass.model_name.human.pluralize.titleize)
4043

4144
managed_class = self.new
4245
managed_class.klass = klass
@@ -49,6 +52,7 @@ def self.create(klass, icon:"file-o", permit_params:[], priority:10, category:"S
4952
managed_class.paginated = paginated.present?
5053
managed_class.permitted_params = permit_params.freeze
5154
managed_class.allowed_actions = allowed_actions.freeze
55+
managed_class.navigation_label = navigation_label.freeze
5256

5357
# Set auto-generated attributes
5458
managed_class.controller_name = "#{managed_class.model_name.collection.camelize}Controller".freeze

0 commit comments

Comments
 (0)