-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change inheritance config from skipping to explicit inherit of sections
- Loading branch information
Showing
5 changed files
with
37 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
class Tram::Page::Section | ||
extend Dry::Initializer | ||
extend ::Dry::Initializer | ||
|
||
param :name | ||
option :value, optional: true, as: :getter | ||
option :if, optional: true, as: :positive | ||
option :unless, optional: true, as: :negative | ||
option :value, optional: true | ||
option :if, optional: true | ||
option :unless, optional: true | ||
|
||
# Takes the page instance and extracts a hash for the section | ||
def call(page) | ||
show?(page) ? { name => value(page) } : {} | ||
end | ||
|
||
def value(page) | ||
getter ? page.instance_exec(&getter) : page.public_send(name) | ||
if attributes[:value] | ||
page.instance_exec(&attributes[:value]) | ||
else | ||
page.public_send(name) | ||
end | ||
end | ||
|
||
private | ||
|
||
def attributes | ||
@attributes ||= self.class.dry_initializer.attributes(self) | ||
end | ||
|
||
def show?(page) | ||
condition = true | ||
condition &= page.send(positive) if positive | ||
condition &= !page.send(negative) if negative | ||
condition &= page.__send__(attributes[:if]) if attributes[:if] | ||
condition &= !page.__send__(attributes[:unless]) if attributes[:unless] | ||
condition | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
class InheritedPage < ExamplePage | ||
section :baz, skip: true | ||
inherit_section :foo | ||
inherit_section :bar, if: :no_bar | ||
section :bam | ||
|
||
def bam | ||
baz.upcase | ||
end | ||
|
||
def no_bar | ||
!bar | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters