1# -*- coding: utf-8 -*-2# Copyright 2011 Takeshi KOMIYA3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.1516import re1718from blockdiag import plugins192021class AutoLane(plugins.NodeHandler):22 def on_created(self, node):23 if node.id is None:24 return2526 for lane in self.diagram.lanes:27 pattern = "^%s_" % re.escape(lane.id)2829 if re.search(pattern, node.id) and node.lane is None:30 node.label = re.sub(pattern, '', node.id)31 node.lane = lane32 lane.nodes.append(node)333435def setup(self, diagram, **kwargs):36 plugins.install_node_handler(AutoLane(diagram, **kwargs))