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 @ 1298:4f746d8966dd
History | View | Annotate | Download (2.53 KB)
| 1 | 119:8661b858af72 | Chris | # Redmine - project management software
|
|---|---|---|---|
| 2 | 1295:622f24f53b42 | Chris | # Copyright (C) 2006-2013 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 | 1115:433d4f72a19b | Chris | attr_accessor :request, :response |
| 25 | |||
| 26 | def initialize(request, response) |
||
| 27 | 119:8661b858af72 | Chris | @struct = [{}]
|
| 28 | 1115:433d4f72a19b | Chris | self.request = request
|
| 29 | self.response = response
|
||
| 30 | 119:8661b858af72 | Chris | end
|
| 31 | 909:cbb26bc654de | Chris | |
| 32 | 119:8661b858af72 | Chris | def array(tag, options={}, &block) |
| 33 | @struct << []
|
||
| 34 | block.call(self)
|
||
| 35 | ret = @struct.pop
|
||
| 36 | @struct.last[tag] = ret
|
||
| 37 | @struct.last.merge!(options) if options |
||
| 38 | end
|
||
| 39 | 909:cbb26bc654de | Chris | |
| 40 | 119:8661b858af72 | Chris | def method_missing(sym, *args, &block) |
| 41 | if args.any?
|
||
| 42 | if args.first.is_a?(Hash) |
||
| 43 | if @struct.last.is_a?(Array) |
||
| 44 | @struct.last << args.first unless block |
||
| 45 | else
|
||
| 46 | @struct.last[sym] = args.first
|
||
| 47 | end
|
||
| 48 | else
|
||
| 49 | if @struct.last.is_a?(Array) |
||
| 50 | 1115:433d4f72a19b | Chris | if args.size == 1 && !block_given? |
| 51 | @struct.last << args.first
|
||
| 52 | else
|
||
| 53 | @struct.last << (args.last || {}).merge(:value => args.first) |
||
| 54 | end
|
||
| 55 | 119:8661b858af72 | Chris | else
|
| 56 | @struct.last[sym] = args.first
|
||
| 57 | end
|
||
| 58 | end
|
||
| 59 | end
|
||
| 60 | 909:cbb26bc654de | Chris | |
| 61 | 119:8661b858af72 | Chris | if block
|
| 62 | @struct << (args.first.is_a?(Hash) ? args.first : {}) |
||
| 63 | block.call(self)
|
||
| 64 | ret = @struct.pop
|
||
| 65 | if @struct.last.is_a?(Array) |
||
| 66 | @struct.last << ret
|
||
| 67 | else
|
||
| 68 | if @struct.last.has_key?(sym) && @struct.last[sym].is_a?(Hash) |
||
| 69 | @struct.last[sym].merge! ret
|
||
| 70 | else
|
||
| 71 | @struct.last[sym] = ret
|
||
| 72 | end
|
||
| 73 | end
|
||
| 74 | end
|
||
| 75 | end
|
||
| 76 | 909:cbb26bc654de | Chris | |
| 77 | 119:8661b858af72 | Chris | def output |
| 78 | raise "Need to implement #{self.class.name}#output"
|
||
| 79 | end
|
||
| 80 | end
|
||
| 81 | end
|
||
| 82 | end
|
||
| 83 | end |