Allow layout options configuration from run control
This commit is contained in:
parent
70fe9bdb03
commit
7c2712924a
@ -4,8 +4,12 @@ Feature: `layout' run control keyword
|
|||||||
Given a file named my_layout.rb with:
|
Given a file named my_layout.rb with:
|
||||||
"""
|
"""
|
||||||
class MyLayout
|
class MyLayout
|
||||||
def register *_
|
def initialize **options
|
||||||
puts "testing_rc_layout"
|
puts "testing_rc_layout_#{options.inspect}" if options.any?
|
||||||
|
end
|
||||||
|
|
||||||
|
def register *_, **options
|
||||||
|
puts "testing_rc_layout_register"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
"""
|
"""
|
||||||
@ -16,7 +20,15 @@ Feature: `layout' run control keyword
|
|||||||
layout MyLayout
|
layout MyLayout
|
||||||
"""
|
"""
|
||||||
When I run uhwm with options -r./my_layout
|
When I run uhwm with options -r./my_layout
|
||||||
Then the output must contain "testing_rc_layout"
|
Then the output must contain "testing_rc_layout_register"
|
||||||
|
|
||||||
|
Scenario: configures a layout class with options
|
||||||
|
Given a run control file with:
|
||||||
|
"""
|
||||||
|
layout MyLayout, foo: :bar
|
||||||
|
"""
|
||||||
|
When I run uhwm with options -r./my_layout
|
||||||
|
Then the output must contain "testing_rc_layout_{:foo=>:bar}"
|
||||||
|
|
||||||
Scenario: configures a layout instance
|
Scenario: configures a layout instance
|
||||||
Given a run control file with:
|
Given a run control file with:
|
||||||
@ -24,4 +36,4 @@ Feature: `layout' run control keyword
|
|||||||
layout MyLayout.new
|
layout MyLayout.new
|
||||||
"""
|
"""
|
||||||
When I run uhwm with options -r./my_layout
|
When I run uhwm with options -r./my_layout
|
||||||
Then the output must contain "testing_rc_layout"
|
Then the output must contain "testing_rc_layout_register"
|
||||||
|
@ -32,11 +32,15 @@ module Uh
|
|||||||
@env.keybinds[translate_keysym *keysyms] = block
|
@env.keybinds[translate_keysym *keysyms] = block
|
||||||
end
|
end
|
||||||
|
|
||||||
def layout obj
|
def layout arg, **options
|
||||||
if obj.is_a? Class
|
if arg.is_a? Class
|
||||||
@env.layout_class = obj
|
if options.any?
|
||||||
|
@env.layout = arg.new options
|
||||||
else
|
else
|
||||||
@env.layout = obj
|
@env.layout_class = arg
|
||||||
|
end
|
||||||
|
else
|
||||||
|
@env.layout = arg
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -87,10 +87,19 @@ module Uh
|
|||||||
|
|
||||||
describe '#layout' do
|
describe '#layout' do
|
||||||
context 'when given a class' do
|
context 'when given a class' do
|
||||||
|
let(:layout_class) { Class.new }
|
||||||
|
|
||||||
it 'sets a layout class in the env' do
|
it 'sets a layout class in the env' do
|
||||||
rc.layout layout_class = Class.new
|
rc.layout layout_class
|
||||||
expect(env.layout_class).to be layout_class
|
expect(env.layout_class).to be layout_class
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when given options' do
|
||||||
|
it 'instantiates the class with given options' do
|
||||||
|
expect(layout_class).to receive(:new).with(foo: :bar)
|
||||||
|
rc.layout layout_class, foo: :bar
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when given an object' do
|
context 'when given an object' do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user