cmor_core_frontend 0.0.33.pre → 0.0.34.pre
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 +4 -4
- data/app/breadcrumbs/cmor/core/frontend/breadcrumb/base.rb +20 -0
- data/app/view_helpers/cmor/core/frontend/breadcrumbs_view_helper.rb +42 -22
- data/lib/cmor/core/frontend/configuration.rb +4 -0
- data/lib/generators/cmor/core/frontend/install/templates/initializer.rb +6 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cac22dcf3ca45849904fe9f317d1fd94ec3d573837e1164564bc49433fd5c76f
|
4
|
+
data.tar.gz: d921cd757e6d7a53eb93379b2d8166463bb21680d829db5211a8133937255fe9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec65f2aae3fa1b769f6b951db30c6a7e791410f8db21b09f0604502e1ddf380433067346d05cfaccd65d5422edcc4ebd381856d1e6b66fa1b8f30340484cb3a6
|
7
|
+
data.tar.gz: 2e782987e5675c9ed4f0e590e548969e27aac29ea3392be9874d2fa37a756f4c2212ea9f07ff11cfdf50135261815b6d6839044792fca9f8475368904d1e81bb
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Cmor
|
2
|
+
module Core
|
3
|
+
module Frontend
|
4
|
+
module Breadcrumb
|
5
|
+
class Base
|
6
|
+
extend ActiveModel::Model
|
7
|
+
|
8
|
+
attr_accessor :label, :url, :link_html_options, :li_html_options
|
9
|
+
|
10
|
+
def initialize(attrs)
|
11
|
+
attrs.reverse_merge!(link_html_options: {}, li_html_options: {})
|
12
|
+
attrs.each do |k, v|
|
13
|
+
self.send("#{k}=", v)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -17,15 +17,25 @@ module Cmor
|
|
17
17
|
# %body
|
18
18
|
# = breadcrumbs_helper(self).render_breadcrumbs
|
19
19
|
#
|
20
|
-
|
20
|
+
# Excluding elements:
|
21
|
+
#
|
22
|
+
# You can exclude breadcrumbs by passing the exclude option by index or :last or :first:
|
23
|
+
#
|
24
|
+
# = breadcrumbs_helper(self).render_breadcrumbs(exclude: :first)
|
25
|
+
#
|
26
|
+
# You can configure the first breadcrumb in the initializer by setting the first_breadcrumb options.
|
27
|
+
#
|
28
|
+
def render_breadcrumbs(options = {})
|
29
|
+
options.reverse_merge!(exclude: [])
|
30
|
+
exclude = options.delete(:exclude)
|
21
31
|
breadcrumbs = [].tap do |b|
|
22
32
|
# Add breadcrumb to home page
|
23
|
-
b.push(
|
33
|
+
b.push(instance_exec(&Cmor::Core::Frontend::Configuration.first_breadcrumb))
|
24
34
|
|
25
35
|
# Are we showing a cms page?
|
26
36
|
if c.controller.class.name == 'Cmor::Cms::PageController' && c.action_name == 'respond' && c.params[:page] != 'home'
|
27
37
|
# Add breadcrumb for this page
|
28
|
-
b.push(Breadcrumb.new(label: c.content_for(:title), url: c.url_for()))
|
38
|
+
b.push(Cmor::Core::Frontend::Breadcrumb::Base.new(label: c.content_for(:title), url: c.url_for()))
|
29
39
|
end
|
30
40
|
|
31
41
|
# Are we inside a resources controller?
|
@@ -34,14 +44,14 @@ module Cmor
|
|
34
44
|
b.push(breadcrumb_for_current_engine)
|
35
45
|
|
36
46
|
# Add a breadrumb for collection page
|
37
|
-
b.push(Breadcrumb.new(label: c.controller.class.resource_class.model_name.human(count: :other), url: c.url_for(action: :index, page: nil)))
|
47
|
+
b.push(Cmor::Core::Frontend::Breadcrumb::Base.new(label: c.controller.class.resource_class.model_name.human(count: :other), url: c.url_for(action: :index, page: nil)))
|
38
48
|
|
39
49
|
# Are we showing a single resource?
|
40
50
|
if r = c.instance_variable_get(:@resource).presence
|
41
51
|
# Is it persisted?
|
42
52
|
if r.persisted?
|
43
53
|
# Add breadcrumb to this specific resource
|
44
|
-
b.push(Breadcrumb.new(label: label_for(r), url: c.url_for(action: :show, id: r.to_param)))
|
54
|
+
b.push(Cmor::Core::Frontend::Breadcrumb::Base.new(label: label_for(r), url: c.url_for(action: :show, id: r.to_param)))
|
45
55
|
end
|
46
56
|
end
|
47
57
|
|
@@ -50,7 +60,7 @@ module Cmor
|
|
50
60
|
# Are we paginating?
|
51
61
|
if c.params.has_key?(:page)
|
52
62
|
# Ass breadcrumb for this page
|
53
|
-
b.push(Breadcrumb.new(label: c.controller.class.resource_class.model_name.human(count: :other), url: c.url_for()))
|
63
|
+
b.push(Cmor::Core::Frontend::Breadcrumb::Base.new(label: c.controller.class.resource_class.model_name.human(count: :other), url: c.url_for()))
|
54
64
|
end
|
55
65
|
end
|
56
66
|
end
|
@@ -61,10 +71,22 @@ module Cmor
|
|
61
71
|
b.push(breadcrumb_for_current_engine)
|
62
72
|
|
63
73
|
# Add a text breadcrumb for the service name
|
64
|
-
b.push(Breadcrumb.new(label: c.controller.class.service_class.model_name.human))
|
74
|
+
b.push(Cmor::Core::Frontend::Breadcrumb::Base.new(label: c.controller.class.service_class.model_name.human))
|
65
75
|
end
|
66
76
|
end
|
77
|
+
|
67
78
|
breadcrumbs.last.url = nil
|
79
|
+
|
80
|
+
if exclude.any?
|
81
|
+
if exclude.include?(:last)
|
82
|
+
breadcrumbs.pop
|
83
|
+
end
|
84
|
+
exclude.keep_if{ |e| e.is_a?(Integer) }.sort.reverse.each { |index| breadcrumbs.delete_at(index) }
|
85
|
+
if exclude.include?(:first)
|
86
|
+
breadcrumbs.shift
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
68
90
|
render breadcrumbs: breadcrumbs
|
69
91
|
end
|
70
92
|
|
@@ -76,7 +98,7 @@ module Cmor
|
|
76
98
|
end
|
77
99
|
|
78
100
|
def breadcrumb_for_engine(engine)
|
79
|
-
Breadcrumb.new(label: I18n.t("classes.#{engine.name.underscore}"))
|
101
|
+
Cmor::Core::Frontend::Breadcrumb::Base.new(label: I18n.t("classes.#{engine.name.underscore}"))
|
80
102
|
end
|
81
103
|
|
82
104
|
def current_engine
|
@@ -91,26 +113,24 @@ module Cmor
|
|
91
113
|
def t(identifier, options = {})
|
92
114
|
if identifier.start_with?('.')
|
93
115
|
prefix = self.class.name.underscore
|
94
|
-
|
116
|
+
|
117
|
+
# Check if we are in a proc by matching the caller string
|
118
|
+
caller_method = if caller[0] =~ /\(required\)>/
|
119
|
+
# If yes omit the last call (that has to be instance_exec) and
|
120
|
+
# fetch the previous one that should be the method that is really
|
121
|
+
# calling us.
|
122
|
+
caller[2].split(' ').last.gsub("'", '').gsub("`", '')
|
123
|
+
else
|
124
|
+
# Otherwise take the first caller
|
125
|
+
caller[0].split(' ').last.gsub("'", '').gsub("`", '')
|
126
|
+
end
|
127
|
+
|
95
128
|
I18n.t("#{prefix}.#{caller_method}.#{identifier}", options)
|
96
129
|
else
|
97
130
|
I18n.t(identifier, options)
|
98
131
|
end
|
99
132
|
end
|
100
133
|
|
101
|
-
class Breadcrumb
|
102
|
-
extend ActiveModel::Model
|
103
|
-
|
104
|
-
attr_accessor :label, :url, :link_html_options, :li_html_options
|
105
|
-
|
106
|
-
def initialize(attrs)
|
107
|
-
attrs.reverse_merge!(link_html_options: {}, li_html_options: {})
|
108
|
-
attrs.each do |k, v|
|
109
|
-
self.send("#{k}=", v)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
134
|
private
|
115
135
|
|
116
136
|
def label_for(resource)
|
@@ -6,6 +6,10 @@ module Cmor
|
|
6
6
|
yield self
|
7
7
|
end
|
8
8
|
|
9
|
+
mattr_accessor(:first_breadcrumb) do
|
10
|
+
->() { Cmor::Core::Frontend::Breadcrumb::Base.new(label: t('.home'), url: c.main_app.root_path) }
|
11
|
+
end
|
12
|
+
|
9
13
|
mattr_accessor(:resource_label_methods) do
|
10
14
|
%i(human name email to_s)
|
11
15
|
end
|
@@ -4,4 +4,10 @@ Cmor::Core::Frontend.configure do |config|
|
|
4
4
|
# Default: config.resource_label_methods = %i(human name email to_s)
|
5
5
|
#
|
6
6
|
config.resource_label_methods = %i(human name email to_s)
|
7
|
+
|
8
|
+
# Sets the first breadcrumb. This is usually the home link.
|
9
|
+
#
|
10
|
+
# Default: config.first_breadcrumb = ->() { Cmor::Core::Frontend::Breadcrumb::Base.new(label: t('.home'), url: c.main_app.root_path) }
|
11
|
+
#
|
12
|
+
config.first_breadcrumb = ->() { Cmor::Core::Frontend::Breadcrumb::Base.new(label: t('.home'), url: c.main_app.root_path) }
|
7
13
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cmor_core_frontend
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.34.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Vasquez Angel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.0.
|
33
|
+
version: 0.0.34.pre
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.0.
|
40
|
+
version: 0.0.34.pre
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: sqlite3
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -313,6 +313,7 @@ extra_rdoc_files: []
|
|
313
313
|
files:
|
314
314
|
- MIT-LICENSE
|
315
315
|
- Rakefile
|
316
|
+
- app/breadcrumbs/cmor/core/frontend/breadcrumb/base.rb
|
316
317
|
- app/view_helpers/cmor/core/frontend/breadcrumbs_view_helper.rb
|
317
318
|
- app/views/cmor/core/frontend/breadcrumbs_view_helper/_render_breadcrumbs.html.haml
|
318
319
|
- config/locales/de.yml
|