jav_madmin 2.6.4 → 2.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42d91356c371216c4e08343abcd8e7c4d3a882bc1e1993c771d538e0b0043f0f
4
- data.tar.gz: 651a12e2e8630370b245eccee8d971aab0defc877901d80e0054d2bd094330d6
3
+ metadata.gz: b1651894f25b331e5c9d9bed393706adba9f6b70e778cff5b2964b2fb024ed45
4
+ data.tar.gz: fd60a4567983f6fe2b2f544478f5282f759eb9dbbbfe61de604ac2a5d66d389c
5
5
  SHA512:
6
- metadata.gz: 0722c8fdb86a609e163a64badc2d699be91cd68603d8bd2f7bf24fd40b1f223a1f5838e47bd3a514d77d5b7fe6be921976ac9fd7e09d980fdbcb390d04538ef5
7
- data.tar.gz: 71cd257d6d538a7e858eb5d582a92558b8e1769e378e2008de169774559dee841c54f0cc926a6532eac4c174bb6110f71bd287a51f2ec920e2f2ca99a8b7059a
6
+ metadata.gz: 55b210975d68220711efd74200abf015dff2c67e25bc2bb84dd5c58a405d7701fbc4bd6e2ffdb58876e795b871317d26930bef6d956710d0ff12a3bdd141f472
7
+ data.tar.gz: 1e6e97d1ddcf1c7efda7af2cd98e1e28f79327e41483da2f0f745b6b994740a4732480976858dc34aad38d787187c4553008668efc3385440ec6c48655a286f6
@@ -27,13 +27,4 @@ module Madmin::NavHelper
27
27
 
28
28
  link_to name, url, html_options
29
29
  end
30
-
31
- # label default is model i18n_key, is a Symbol
32
- def menu_label(label)
33
- if label.is_a?(Symbol)
34
- I18n.t("activerecord.models.#{label}", count: 2, default: [:"madmin.navigation.#{label}", label.to_s.pluralize(I18n.locale).titleize])
35
- else
36
- label
37
- end
38
- end
39
30
  end
@@ -3,13 +3,13 @@
3
3
 
4
4
  <% Madmin.menu.render do |item| %>
5
5
  <% if item.url %>
6
- <%= nav_link_to menu_label(item.label), item.url, starts_with: item.url %>
6
+ <%= nav_link_to item.human_label, item.url, starts_with: item.url %>
7
7
  <% else %>
8
- <h4><%= menu_label(item.label) %></h4>
8
+ <h4><%= item.human_label %></h4>
9
9
  <% end %>
10
10
 
11
11
  <% item.items.each do |item| %>
12
- <%= nav_link_to menu_label(item.label), item.url, starts_with: item.url %>
12
+ <%= nav_link_to item.human_label, item.url, starts_with: item.url %>
13
13
  <% end %>
14
14
  <% end %>
15
15
  </nav>
@@ -2,7 +2,7 @@
2
2
 
3
3
  <header class="header">
4
4
  <h1>
5
- <%= link_to resource.friendly_name(count: 2, default: resource.model_name.pluralize(I18n.locale)), resource.index_path %>
5
+ <%= link_to resource.friendly_name(count: 2), resource.index_path %>
6
6
  /
7
7
  <strong><%= t("madmin.actions.edit") %> <%= link_to resource.display_name(@record), resource.show_path(@record) %></strong>
8
8
  </h1>
@@ -1,7 +1,7 @@
1
- <%= content_for :title, resource.friendly_name(count: 2, default: resource.model_name.pluralize(I18n.locale)) %>
1
+ <%= content_for :title, resource.friendly_name(count: 2) %>
2
2
 
3
3
  <header class="header">
4
- <h1><%= resource.friendly_name(count: 2, default: resource.model_name.pluralize(I18n.locale)) %></h1>
4
+ <h1><%= resource.friendly_name(count: 2) %></h1>
5
5
 
6
6
  <div class="actions">
7
7
  <form class="search">
@@ -2,7 +2,7 @@
2
2
 
3
3
  <header class="header">
4
4
  <h1>
5
- <%= link_to resource.friendly_name(count: 2, default: resource.model_name.pluralize(I18n.locale)) , resource.index_path %>
5
+ <%= link_to resource.friendly_name(count: 2) , resource.index_path %>
6
6
  /
7
7
  <strong><%= t("madmin.titles.new", name: resource.friendly_name) %></strong>
8
8
  </h1>
@@ -2,7 +2,7 @@
2
2
 
3
3
  <header class="header">
4
4
  <h1>
5
- <%= link_to resource.friendly_name(count: 2, default: resource.model_name.pluralize(I18n.locale)), resource.index_path %>
5
+ <%= link_to resource.friendly_name(count: 2), resource.index_path %>
6
6
  /
7
7
  <%= resource.display_name(@record) %>
8
8
  </h1>
data/lib/madmin/menu.rb CHANGED
@@ -44,7 +44,7 @@ module Madmin
44
44
  def items
45
45
  @children.values.sort do |a, b|
46
46
  result = a.position <=> b.position
47
- result = a.label.to_s <=> b.label.to_s if result == 0 # sort alphabetically for the same position
47
+ result = a.human_label <=> b.human_label if result == 0 # sort alphabetically for the same position
48
48
  result
49
49
  end
50
50
  end
@@ -65,6 +65,14 @@ module Madmin
65
65
  @if = options.delete(:if)
66
66
  @children = {}
67
67
  end
68
+
69
+ def human_label
70
+ @human_label ||= if label.is_a?(Symbol)
71
+ I18n.t("activerecord.models.#{label}", count: 2, default: [:"madmin.navigation.#{label}", label.to_s.pluralize(I18n.locale).titleize])
72
+ else
73
+ label
74
+ end
75
+ end
68
76
  end
69
77
  end
70
78
  end
@@ -83,8 +83,8 @@ module Madmin
83
83
 
84
84
  # Returns singular name
85
85
  # For example: "Forum::Post" -> "Post"
86
- def friendly_name(count: 1, default: nil)
87
- model.model_name.human(count: count, default: default)
86
+ def friendly_name(count: 1)
87
+ model.model_name.human(count: count, default: model_name.titleize.pluralize(count, I18n.locale))
88
88
  end
89
89
 
90
90
  # Support for isolated namespaces
@@ -97,20 +97,43 @@ module Madmin
97
97
  @route_namespace = (namespace ? namespace.name.underscore.to_sym : nil)
98
98
  end
99
99
 
100
+ # ori_opts = Madmin.multi_locales ? {locale: I18n.locale} : {}
101
+
102
+ # [
103
+ # [:index_path, ori_opts, false],
104
+ # [:new_path, ori_opts.merge(action: :new), false],
105
+ # [:show_path, ori_opts, true],
106
+ # [:edit_path, ori_opts.merge(action: :edit), true]
107
+ # ].each do |item|
108
+ # if item[2]
109
+ # define_method item[0] do |record, options = item[1]|
110
+ # url_helpers.polymorphic_path([:madmin, route_namespace, becomes(record)], options)
111
+ # end
112
+ # else
113
+ # define_method item[0] do |options = item[1]|
114
+ # url_helpers.polymorphic_path([:madmin, route_namespace, model], options)
115
+ # end
116
+ # end
117
+ # end
118
+
100
119
  def index_path(options = {})
101
- url_helpers.polymorphic_path([:madmin, route_namespace, model], options)
120
+ ori_opts = Madmin.multi_locales ? {locale: I18n.locale} : {}
121
+ url_helpers.polymorphic_path([:madmin, route_namespace, model], options.merge(ori_opts))
102
122
  end
103
123
 
104
- def new_path
105
- url_helpers.polymorphic_path([:madmin, route_namespace, model], action: :new)
124
+ def new_path(options = {action: :new})
125
+ ori_opts = Madmin.multi_locales ? {locale: I18n.locale} : {}
126
+ url_helpers.polymorphic_path([:madmin, route_namespace, model], options.merge(ori_opts))
106
127
  end
107
128
 
108
- def show_path(record)
109
- url_helpers.polymorphic_path([:madmin, route_namespace, becomes(record)])
129
+ def show_path(record, options = {})
130
+ ori_opts = Madmin.multi_locales ? {locale: I18n.locale} : {}
131
+ url_helpers.polymorphic_path([:madmin, route_namespace, becomes(record)], options.merge(ori_opts))
110
132
  end
111
133
 
112
- def edit_path(record)
113
- url_helpers.polymorphic_path([:madmin, route_namespace, becomes(record)], action: :edit)
134
+ def edit_path(record, options = {action: :edit})
135
+ ori_opts = Madmin.multi_locales ? {locale: I18n.locale} : {}
136
+ url_helpers.polymorphic_path([:madmin, route_namespace, becomes(record)], options.merge(ori_opts))
114
137
  end
115
138
 
116
139
  def becomes(record)
@@ -1,3 +1,3 @@
1
1
  module Madmin
2
- VERSION = "2.6.4"
2
+ VERSION = "2.6.6"
3
3
  end
data/lib/madmin.rb CHANGED
@@ -44,6 +44,7 @@ module Madmin
44
44
  mattr_accessor :site_name
45
45
  mattr_accessor :stylesheets, default: []
46
46
  mattr_accessor :resource_locations, default: []
47
+ mattr_accessor :multi_locales, default: false, instance_accessor: false
47
48
 
48
49
  class MissingResource < StandardError
49
50
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jav_madmin
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.4
4
+ version: 2.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver
@@ -278,7 +278,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
278
278
  - !ruby/object:Gem::Version
279
279
  version: '0'
280
280
  requirements: []
281
- rubygems_version: 4.0.16
281
+ rubygems_version: 4.0.20
282
282
  specification_version: 4
283
283
  summary: A modern admin for Ruby on Rails apps
284
284
  test_files: []