Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use kwargs within Navigation classes #478

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions lib/trestle/navigation/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ def default_path
@admin ? @admin.path : nil
end

def item(name, path=nil, options={})
if path.is_a?(Hash)
options = path
path = nil
end

def item(name, path=nil, **options)
if options[:group]
group = Group.new(options[:group])
elsif @current_group
Expand All @@ -43,11 +38,11 @@ def item(name, path=nil, options={})
options = options.merge(group: group) if group
options = options.merge(admin: @admin) if @admin

items << Item.new(name, path || default_path, options)
items << Item.new(name, path || default_path, **options)
end

def group(name, options={})
@current_group = Group.new(name, options)
def group(name, **options)
@current_group = Group.new(name, **options)
yield
ensure
@current_group = nil
Expand Down
4 changes: 2 additions & 2 deletions lib/trestle/navigation/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Navigation
class Group
attr_reader :name, :options

def initialize(name, options={})
def initialize(name, **options)
@name, @options = name.to_s, options
end

Expand All @@ -26,7 +26,7 @@ def <=>(other)
end

def merge(other)
self.class.new(name, options.merge(other.options))
self.class.new(name, **options.merge(other.options))
end

def priority
Expand Down
2 changes: 1 addition & 1 deletion lib/trestle/navigation/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Navigation
class Item
attr_reader :name, :path, :options

def initialize(name, path=nil, options={})
def initialize(name, path=nil, **options)
@name, @path, @options = name.to_s, path, options
end

Expand Down