To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / 21 / 21b08aea1ac3dbc27c974e37d3d3c4f6952cdffd.svn-base @ 1298:4f746d8966dd
History | View | Annotate | Download (2.53 KB)
| 1 | 1295:622f24f53b42 | Chris | # Redmine - project management software |
|---|---|---|---|
| 2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
||
| 3 | # |
||
| 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 | # |
||
| 9 | # 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 | # |
||
| 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 |
||
| 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 | attr_accessor :request, :response |
||
| 25 | |||
| 26 | def initialize(request, response) |
||
| 27 | @struct = [{}]
|
||
| 28 | self.request = request |
||
| 29 | self.response = response |
||
| 30 | end |
||
| 31 | |||
| 32 | 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 | |||
| 40 | 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 | 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 | else |
||
| 56 | @struct.last[sym] = args.first |
||
| 57 | end |
||
| 58 | end |
||
| 59 | end |
||
| 60 | |||
| 61 | 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 | |||
| 77 | def output |
||
| 78 | raise "Need to implement #{self.class.name}#output"
|
||
| 79 | end |
||
| 80 | end |
||
| 81 | end |
||
| 82 | end |
||
| 83 | end |