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 / 74 / 74646d64b0858dd62aa32241e9f5deb66f244cbc.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (2.27 KB)
| 1 |
# Redmine - project management software |
|---|---|
| 2 |
# Copyright (C) 2006-2011 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 |
def initialize |
| 25 |
@struct = [{}]
|
| 26 |
end |
| 27 |
|
| 28 |
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 |
|
| 36 |
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 |
|
| 53 |
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 |
|
| 69 |
def output |
| 70 |
raise "Need to implement #{self.class.name}#output"
|
| 71 |
end |
| 72 |
end |
| 73 |
end |
| 74 |
end |
| 75 |
end |