comparison lib/redmine/views/builders/structure.rb @ 909:cbb26bc654de redmine-1.3

Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author Chris Cannam
date Fri, 24 Feb 2012 19:09:32 +0000
parents 8661b858af72
children 433d4f72a19b
comparison
equal deleted inserted replaced
908:c6c2cbd0afee 909:cbb26bc654de
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2010 Jean-Philippe Lang 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
8 # 8 #
9 # This program is distributed in the hope that it will be useful, 9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details. 12 # GNU General Public License for more details.
13 # 13 #
14 # You should have received a copy of the GNU General Public License 14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software 15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 require 'blankslate' 18 require 'blankslate'
22 module Builders 22 module Builders
23 class Structure < BlankSlate 23 class Structure < BlankSlate
24 def initialize 24 def initialize
25 @struct = [{}] 25 @struct = [{}]
26 end 26 end
27 27
28 def array(tag, options={}, &block) 28 def array(tag, options={}, &block)
29 @struct << [] 29 @struct << []
30 block.call(self) 30 block.call(self)
31 ret = @struct.pop 31 ret = @struct.pop
32 @struct.last[tag] = ret 32 @struct.last[tag] = ret
33 @struct.last.merge!(options) if options 33 @struct.last.merge!(options) if options
34 end 34 end
35 35
36 def method_missing(sym, *args, &block) 36 def method_missing(sym, *args, &block)
37 if args.any? 37 if args.any?
38 if args.first.is_a?(Hash) 38 if args.first.is_a?(Hash)
39 if @struct.last.is_a?(Array) 39 if @struct.last.is_a?(Array)
40 @struct.last << args.first unless block 40 @struct.last << args.first unless block
47 else 47 else
48 @struct.last[sym] = args.first 48 @struct.last[sym] = args.first
49 end 49 end
50 end 50 end
51 end 51 end
52 52
53 if block 53 if block
54 @struct << (args.first.is_a?(Hash) ? args.first : {}) 54 @struct << (args.first.is_a?(Hash) ? args.first : {})
55 block.call(self) 55 block.call(self)
56 ret = @struct.pop 56 ret = @struct.pop
57 if @struct.last.is_a?(Array) 57 if @struct.last.is_a?(Array)
63 @struct.last[sym] = ret 63 @struct.last[sym] = ret
64 end 64 end
65 end 65 end
66 end 66 end
67 end 67 end
68 68
69 def output 69 def output
70 raise "Need to implement #{self.class.name}#output" 70 raise "Need to implement #{self.class.name}#output"
71 end 71 end
72 end 72 end
73 end 73 end