Skip to content

Commit ea1af70

Browse files
committed
Fully move section data retrieval logic into section
1 parent e4fbafb commit ea1af70

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

lib/tram/page.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def section(name, options = {})
1616
raise "Section #{n} already exists" if @__sections.key?(n)
1717

1818
section = Section.new(n, options)
19-
define_section_method(n, options[:value]) if options[:value]
19+
define_section_method(n, section) if options[:value]
2020
@__sections[n] = section
2121
end
2222

@@ -27,8 +27,8 @@ def url_helper(name)
2727

2828
private
2929

30-
def define_section_method(n, value)
31-
define_method(n) { instance_exec(&value) }
30+
def define_section_method(n, section)
31+
define_method(n) { section.value(self) }
3232
end
3333

3434
def inherited(subclass)

lib/tram/page/section.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class Tram::Page::Section
44
extend Dry::Initializer
55

66
param :name
7+
option :value, optional: true, as: :getter
78
option :if, optional: true, as: :positive
89
option :unless, optional: true, as: :negative
910

@@ -12,12 +13,12 @@ def call(page)
1213
show?(page) ? { name => value(page) } : {}
1314
end
1415

15-
private
16-
1716
def value(page)
18-
page.public_send(name)
17+
getter ? page.instance_exec(&getter) : page.public_send(name)
1918
end
2019

20+
private
21+
2122
def show?(page)
2223
condition = true
2324
condition &= page.send(positive) if positive

0 commit comments

Comments
 (0)