From fcc9550fd5a318bc185fbcad086f5f635ebd85c2 Mon Sep 17 00:00:00 2001 From: fbt Date: Thu, 29 Sep 2016 15:27:42 +0300 Subject: [PATCH] Put templates into a proper scope --- mod/bspwm_taskbar | 3 ++- moltenbar | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/mod/bspwm_taskbar b/mod/bspwm_taskbar index 4b30192..5f936ae 100644 --- a/mod/bspwm_taskbar +++ b/mod/bspwm_taskbar @@ -9,7 +9,8 @@ class BspwmTaskbar < Worker if line == "\n" self.write "" else - self.write @config['mod']['bspwm_taskbar']['begin'].erb + line.chomp + @config['mod']['bspwm_taskbar']['end'].erb + "\n" + tmpl = Template.new(@config['mod']['bspwm_taskbar']['begin'] + line.chomp + @config['mod']['bspwm_taskbar']['end']) + self.write tmpl.render(@config, nil) end end end diff --git a/moltenbar b/moltenbar index 02e98e8..0c59369 100755 --- a/moltenbar +++ b/moltenbar @@ -79,6 +79,19 @@ module Modules end end +class Template + def initialize(template) + @template = template + end + + def render(config, data) + @config = config + @panel_data = data + + return ERB.new(@template).result(binding) + end +end + # Kill the workers. def cleanup(workers) for w in workers do @@ -164,6 +177,7 @@ IO.popen(lemonbar_cmd, "w+") do |pipe_lb| mod_name, data = line.chomp.split("\0") panel_data[mod_name] = data - pipe_lb.puts config['format'].erb + t = Template.new(config['format']) + pipe_lb.puts t.render(config, panel_data) end end