Skip to content

Commit 90a0574

Browse files
authored
Merge pull request #21 from blocknotes/feat/config-improvements
feat: config improvements
2 parents 9a42b97 + 90ae238 commit 90a0574

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

lib/tiny_admin/settings.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,14 @@ def convert_value(key, value)
8282

8383
def prepare_navbar(sections, logout:)
8484
items = sections.each_with_object({}) do |section, list|
85-
slug = section[:slug]
85+
unless section.is_a?(Hash)
86+
section_class = Object.const_get(section)
87+
next unless section_class.respond_to?(:to_h)
88+
89+
section = section_class.to_h
90+
end
91+
92+
slug = section[:slug].to_s
8693
case section[:type]&.to_sym
8794
when :url
8895
list[slug] = add_url_section(slug, section)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module SectionGithubLink
2+
def to_h
3+
{
4+
slug: :github,
5+
name: 'GitHub',
6+
type: :url,
7+
url: 'https://www.github.com',
8+
options: {
9+
target: '_blank'
10+
}
11+
}
12+
end
13+
14+
module_function :to_h
15+
end

spec/dummy/config/tiny_admin.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ sections:
1515
url: https://www.google.it
1616
options:
1717
target: _blank
18+
- SectionGithubLink
1819
- slug: sample
1920
name: Sample page
2021
type: page

0 commit comments

Comments
 (0)