Put templates into a proper scope

This commit is contained in:
Jack L. Frost 2016-09-29 15:27:42 +03:00
parent 8811476f9f
commit fcc9550fd5
2 changed files with 17 additions and 2 deletions

View File

@ -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

View File

@ -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