From 7c2712924a198a4ed4344ac071786f797ecd00a9 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Sun, 26 Apr 2015 02:49:39 +0000 Subject: [PATCH] Allow layout options configuration from run control --- features/run_control/layout.feature | 20 ++++++++++++++++---- lib/uh/wm/run_control.rb | 12 ++++++++---- spec/uh/wm/run_control_spec.rb | 11 ++++++++++- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/features/run_control/layout.feature b/features/run_control/layout.feature index d66f615..44899f2 100644 --- a/features/run_control/layout.feature +++ b/features/run_control/layout.feature @@ -4,8 +4,12 @@ Feature: `layout' run control keyword Given a file named my_layout.rb with: """ class MyLayout - def register *_ - puts "testing_rc_layout" + def initialize **options + puts "testing_rc_layout_#{options.inspect}" if options.any? + end + + def register *_, **options + puts "testing_rc_layout_register" end end """ @@ -16,7 +20,15 @@ Feature: `layout' run control keyword layout MyLayout """ 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 Given a run control file with: @@ -24,4 +36,4 @@ Feature: `layout' run control keyword layout MyLayout.new """ 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" diff --git a/lib/uh/wm/run_control.rb b/lib/uh/wm/run_control.rb index ba5b218..6290677 100644 --- a/lib/uh/wm/run_control.rb +++ b/lib/uh/wm/run_control.rb @@ -32,11 +32,15 @@ module Uh @env.keybinds[translate_keysym *keysyms] = block end - def layout obj - if obj.is_a? Class - @env.layout_class = obj + def layout arg, **options + if arg.is_a? Class + if options.any? + @env.layout = arg.new options + else + @env.layout_class = arg + end else - @env.layout = obj + @env.layout = arg end end diff --git a/spec/uh/wm/run_control_spec.rb b/spec/uh/wm/run_control_spec.rb index cac60d9..a89475f 100644 --- a/spec/uh/wm/run_control_spec.rb +++ b/spec/uh/wm/run_control_spec.rb @@ -87,10 +87,19 @@ module Uh describe '#layout' do context 'when given a class' do + let(:layout_class) { Class.new } + 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 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 context 'when given an object' do