Return-Path: X-Original-To: apmail-incubator-isis-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-isis-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 40BEB4727 for ; Fri, 27 May 2011 12:32:16 +0000 (UTC) Received: (qmail 28002 invoked by uid 500); 27 May 2011 12:32:16 -0000 Delivered-To: apmail-incubator-isis-commits-archive@incubator.apache.org Received: (qmail 27987 invoked by uid 500); 27 May 2011 12:32:16 -0000 Mailing-List: contact isis-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: isis-dev@incubator.apache.org Delivered-To: mailing list isis-commits@incubator.apache.org Received: (qmail 27980 invoked by uid 99); 27 May 2011 12:32:16 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 May 2011 12:32:16 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 May 2011 12:32:13 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id D82382388897; Fri, 27 May 2011 12:31:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1128279 - /incubator/isis/trunk/updateiconlibrary.groovy Date: Fri, 27 May 2011 12:31:51 -0000 To: isis-commits@incubator.apache.org From: danhaywood@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110527123151.D82382388897@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: danhaywood Date: Fri May 27 12:31:51 2011 New Revision: 1128279 URL: http://svn.apache.org/viewvc?rev=1128279&view=rev Log: adding groovy script to autogenerate icon library Added: incubator/isis/trunk/updateiconlibrary.groovy Added: incubator/isis/trunk/updateiconlibrary.groovy URL: http://svn.apache.org/viewvc/incubator/isis/trunk/updateiconlibrary.groovy?rev=1128279&view=auto ============================================================================== --- incubator/isis/trunk/updateiconlibrary.groovy (added) +++ incubator/isis/trunk/updateiconlibrary.groovy Fri May 27 12:31:51 2011 @@ -0,0 +1,155 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +def baseDir=new File("src/site/resources") +def iconsDir=new File(baseDir, "images/icons") +def iconPageDir=new File(baseDir, "icons") + +def icons = [] +def extensions = ["png","gif"] + +def iconsByCategoryByPage = [:] + + +def getExtensionFromFilename(filename) { + def m = (filename =~ /(\.[^\.]*)$/) + if (m.size()>0) { + return (m[0][0].size()>0 ? m[0][0].substring(1).trim().toLowerCase() : "") + } + "" +} + +def getMap(map, key) { + def value = map[key] + if (!value) { + value = [:] + map[key] = value + } + value +} + +def getList(map, key) { + def value = map[key] + if (!value) { + value = [] + map[key] = value + } + value +} + +def asList(list) { + def buf = new StringBuilder() + list.each { + buf.append(it).append("/") + } + buf.deleteCharAt(buf.length()-1) + buf.toString() +} + +iconsDir.eachFileRecurse { file -> + def fileExtension = getExtensionFromFilename(file.name) + if (extensions.contains(fileExtension)) { + def parts = file.path.split("[\\/\\\\]") + def filePath = asList(parts[3..-1]) + parts = parts[5..-1] // strip off 'src/site/resources/images/icons' + + def pageName = parts[0] + def iconSize = parts[1] + + parts = parts[2..-1] // strip off pageName & iconSize + + def hasCategory = parts.size() == 2 + def categoryName = hasCategory? parts[0]: "all" + parts = parts[(hasCategory?1:0)..-1] // strip off category if exists + def iconName = parts[0] + + def iconsByCategory = getMap(iconsByCategoryByPage, pageName) + + def iconsByName = getMap(iconsByCategory,categoryName) + + def iconList = getList(iconsByName, iconName) + + iconList.add(filePath) + } +} + +def appendImgRef(buf, fileName) { + buf.append("") + buf.append("") + buf.append("") + buf +} + +def colsPerRow = [ haywood: 8, nogl: 16, tango: 8] + +iconsByCategoryByPage.each { pageName, iconsByCategory -> + def pageFile = new File(iconPageDir, pageName + ".html") + println(pageFile.path) + + def numCols = colsPerRow[pageName] + def buf = new StringBuilder() + + buf.append("${pageName}") + buf.append("

Download zip

") + buf.append("\n") + + def numIcons = 0 + def rowStarted = false + + iconsByCategory.each { categoryName, iconsByName -> + + if (!categoryName.equals("all")) { + buf.append("

${categoryName}

") + } + + iconsByName.each { iconName, iconList -> + + if(!rowStarted) { + buf.append(" \n") + rowStarted = true + } + + buf.append("") + + numIcons++ + if(numIcons%numCols==0) { + buf.append("\n") + rowStarted = false + } + } + } + + if (rowStarted) { + def numCellsToCompleteRow = numIcons%4 + numCellsToCompleteRow.each { + buf.append("\n") + } + buf.append("
") + iconList.each { + appendImgRef(buf, "../" + it) + } + buf.append("
") + } + buf.append("
\n") + buf.append("") + + def pageFileText = buf.toString() + pageFile.text = pageFileText +} + +