Implement `layout' run control keyword

Allow configuration of the layout by specifying either a class or an
instance.
This commit is contained in:
Thibault Jouan 2015-04-26 00:59:24 +00:00
parent 7c06b52664
commit bf6f08e848
5 changed files with 69 additions and 10 deletions

View File

@ -0,0 +1,27 @@
Feature: `layout' run control keyword
Background:
Given a file named my_layout.rb with:
"""
class MyLayout
def register *_
puts "testing_rc_layout"
end
end
"""
Scenario: configures a layout class
Given a run control file with:
"""
layout MyLayout
"""
When I run uhwm with options -r./my_layout
Then the output must contain "testing_rc_layout"
Scenario: configures a layout instance
Given a run control file with:
"""
layout MyLayout.new
"""
When I run uhwm with options -r./my_layout
Then the output must contain "testing_rc_layout"

View File

@ -21,8 +21,8 @@ module Uh
def_delegators :@output, :print, :puts def_delegators :@output, :print, :puts
attr_reader :output, :keybinds attr_reader :output, :keybinds
attr_accessor :verbose, :debug, :rc_path, :layout_class, :modifier, attr_accessor :verbose, :debug, :rc_path, :modifier, :worker,
:worker :layout, :layout_class
def initialize output def initialize output
@output = output @output = output

View File

@ -32,6 +32,14 @@ module Uh
@env.keybinds[translate_keysym *keysyms] = block @env.keybinds[translate_keysym *keysyms] = block
end end
def layout obj
if obj.is_a? Class
@env.layout_class = obj
else
@env.layout = obj
end
end
def worker type, **options def worker type, **options
@env.worker = [type, options] @env.worker = [type, options]
end end

View File

@ -70,19 +70,27 @@ module Uh
end end
describe '#layout' do describe '#layout' do
context 'when a layout class is set' do let(:some_layout_class) { Class.new }
let(:some_layout) { Class.new }
before { env.layout_class = some_layout } it 'returns the default layout' do
expect(env.layout).to be_an_instance_of ::Uh::Layout
end
context 'when a layout is set' do
let(:some_layout) { some_layout_class.new }
before { env.layout = some_layout }
it 'returns the assigned layout' do
expect(env.layout).to be some_layout
end
end
context 'when a layout class is set' do
before { env.layout_class = some_layout_class }
it 'returns a new instance of this layout class' do it 'returns a new instance of this layout class' do
expect(env.layout).to be_an_instance_of some_layout expect(env.layout).to be_an_instance_of some_layout_class
end
end
context 'when a layout class is not set' do
it 'returns an instance of the default layout' do
expect(env.layout).to be_an_instance_of ::Uh::Layout
end end
end end
end end

View File

@ -85,6 +85,22 @@ module Uh
end end
end end
describe '#layout' do
context 'when given a class' do
it 'sets a layout class in the env' do
rc.layout layout_class = Class.new
expect(env.layout_class).to be layout_class
end
end
context 'when given an object' do
it 'sets a layout instance in the env' do
rc.layout layout = Object.new
expect(env.layout).to eq layout
end
end
end
describe '#worker' do describe '#worker' do
it 'sets the worker type in the env' do it 'sets the worker type in the env' do
rc.worker :some_worker rc.worker :some_worker