To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / lib / redmine / views / builders / structure.rb @ 912:5e80956cc792
History | View | Annotate | Download (2.27 KB)
| 1 | 119:8661b858af72 | Chris | # Redmine - project management software
|
|---|---|---|---|
| 2 | 909:cbb26bc654de | Chris | # Copyright (C) 2006-2011 Jean-Philippe Lang
|
| 3 | 119:8661b858af72 | Chris | #
|
| 4 | # This program is free software; you can redistribute it and/or
|
||
| 5 | # modify it under the terms of the GNU General Public License
|
||
| 6 | # as published by the Free Software Foundation; either version 2
|
||
| 7 | # of the License, or (at your option) any later version.
|
||
| 8 | 909:cbb26bc654de | Chris | #
|
| 9 | 119:8661b858af72 | Chris | # This program is distributed in the hope that it will be useful,
|
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
| 12 | # GNU General Public License for more details.
|
||
| 13 | 909:cbb26bc654de | Chris | #
|
| 14 | 119:8661b858af72 | Chris | # You should have received a copy of the GNU General Public License
|
| 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.
|
||
| 17 | |||
| 18 | require 'blankslate'
|
||
| 19 | |||
| 20 | module Redmine |
||
| 21 | module Views |
||
| 22 | module Builders |
||
| 23 | class Structure < BlankSlate |
||
| 24 | def initialize |
||
| 25 | @struct = [{}]
|
||
| 26 | end
|
||
| 27 | 909:cbb26bc654de | Chris | |
| 28 | 119:8661b858af72 | Chris | def array(tag, options={}, &block) |
| 29 | @struct << []
|
||
| 30 | block.call(self)
|
||
| 31 | ret = @struct.pop
|
||
| 32 | @struct.last[tag] = ret
|
||
| 33 | @struct.last.merge!(options) if options |
||
| 34 | end
|
||
| 35 | 909:cbb26bc654de | Chris | |
| 36 | 119:8661b858af72 | Chris | def method_missing(sym, *args, &block) |
| 37 | if args.any?
|
||
| 38 | if args.first.is_a?(Hash) |
||
| 39 | if @struct.last.is_a?(Array) |
||
| 40 | @struct.last << args.first unless block |
||
| 41 | else
|
||
| 42 | @struct.last[sym] = args.first
|
||
| 43 | end
|
||
| 44 | else
|
||
| 45 | if @struct.last.is_a?(Array) |
||
| 46 | @struct.last << (args.last || {}).merge(:value => args.first) |
||
| 47 | else
|
||
| 48 | @struct.last[sym] = args.first
|
||
| 49 | end
|
||
| 50 | end
|
||
| 51 | end
|
||
| 52 | 909:cbb26bc654de | Chris | |
| 53 | 119:8661b858af72 | Chris | if block
|
| 54 | @struct << (args.first.is_a?(Hash) ? args.first : {}) |
||
| 55 | block.call(self)
|
||
| 56 | ret = @struct.pop
|
||
| 57 | if @struct.last.is_a?(Array) |
||
| 58 | @struct.last << ret
|
||
| 59 | else
|
||
| 60 | if @struct.last.has_key?(sym) && @struct.last[sym].is_a?(Hash) |
||
| 61 | @struct.last[sym].merge! ret
|
||
| 62 | else
|
||
| 63 | @struct.last[sym] = ret
|
||
| 64 | end
|
||
| 65 | end
|
||
| 66 | end
|
||
| 67 | end
|
||
| 68 | 909:cbb26bc654de | Chris | |
| 69 | 119:8661b858af72 | Chris | def output |
| 70 | raise "Need to implement #{self.class.name}#output"
|
||
| 71 | end
|
||
| 72 | end
|
||
| 73 | end
|
||
| 74 | end
|
||
| 75 | end |