| -- @atlcompiler atl2006 |
| |
| -- ****************************************************************************** |
| -- Copyright (c) 2006 INRIA. |
| -- All rights reserved. This program and the accompanying materials |
| -- are made available under the terms of the Eclipse Public License v2.0 |
| -- which accompanies this distribution, and is available at |
| -- http://www.eclipse.org/legal/epl-v20.html |
| -- |
| -- Contributors: |
| -- INRIA - Initial implementation |
| -- |
| -- ****************************************************************************** |
| |
| --@name Table2HTML |
| --@version 1.0 |
| --@domains Table, HTML |
| --@authors Eric Vepa (eric.vepa <at> gmail.com) |
| --@date 2006/08/04 |
| --@description This transformation is used to transform generic tables into HTML model with tables. |
| |
| module Table2HTML; -- Module Template |
| create OUT : HTML from IN : Table; |
| |
| --@begin helper roundValue |
| --@comments for String with a Real content (a dot exists), returns the String with only one decimal after the dot |
| helper context Table!Cell def : roundValue() : String = |
| let point : Integer = self.content->indexOf('.') in |
| if point > 0 |
| then self.content->substring(1,point+2) |
| else self.content |
| endif; |
| --@end helper roundValue |
| |
| --@begin entrypoint rule HTML |
| --@comments only one HTML tag is created with one BODY tag |
| entrypoint rule HTML() { |
| to |
| h:HTML!HTML ( |
| head <- head, |
| body <- body |
| ), |
| head:HTML!HEAD ( |
| headElements <- title |
| ), |
| title:HTML!TITLE ( |
| value <- 'Generated Table(s)' |
| ), |
| body:HTML!BODY ( |
| bodyElements <- Table!Table.allInstances() |
| ->sortedBy(table|table.rows->first().cells->at(2).content) |
| ->collect(table | thisModule.Table2TABLE(table)) |
| ) |
| } |
| --@end entrypoint rule HTML |
| |
| --@begin lazy rule Table2TABLE |
| --@comments HTML TABLE are added in the BODY of the only HTML tag |
| lazy rule Table2TABLE { |
| from |
| tab:Table!Table |
| to |
| table:HTML!TABLE ( |
| border <- '1', |
| trs <- firstRow, |
| trs <- tab.rows->subSequence(2,tab.rows->size())->collect(row | thisModule.Row2TR(row)) |
| ), |
| firstRow:HTML!TR ( |
| tds <- tab.rows->first().cells->collect(cell | thisModule.Cell2TH(cell)) |
| ) |
| } |
| --@end lazy rule Table2TABLE |
| |
| --@begin lazy rule Cell2TH |
| lazy rule Cell2TH { |
| from |
| cell:Table!Cell |
| to |
| th:HTML!TH ( |
| value <- cell.roundValue() |
| ) |
| } |
| --@end lazy rule Cell2TH |
| |
| --@begin lazy rule Row2TR |
| lazy rule Row2TR { |
| from |
| row:Table!Row |
| to |
| tr:HTML!TR ( |
| tds <- row.cells->collect(cell | thisModule.Cell2TD(cell)) |
| ) |
| } |
| --@end lazy rule Row2TR |
| |
| --@begin lazy rule Cell2TD |
| lazy rule Cell2TD { |
| from |
| cell:Table!Cell |
| to |
| td:HTML!TD ( |
| value <- cell.roundValue() |
| ) |
| } |
| --@end lazy rule Cell2TD |