Author: echatellier Date: 2011-03-07 17:23:50 +0100 (Mon, 07 Mar 2011) New Revision: 549 Url: http://nuiton.org/repositories/revision/jrst/549 Log: #21 : Add parameter support for image directive (width, height, ...) Added: trunk/jrst/src/test/java/org/nuiton/jrst/bugs/DirectiveTest.java trunk/jrst/src/test/resources/bugs/testImages21.rst Modified: trunk/jrst/src/main/java/org/nuiton/jrst/JRSTLexer.java trunk/jrst/src/main/java/org/nuiton/jrst/directive/ImageDirective.java Modified: trunk/jrst/src/main/java/org/nuiton/jrst/JRSTLexer.java =================================================================== --- trunk/jrst/src/main/java/org/nuiton/jrst/JRSTLexer.java 2011-03-04 12:37:01 UTC (rev 548) +++ trunk/jrst/src/main/java/org/nuiton/jrst/JRSTLexer.java 2011-03-07 16:23:50 UTC (rev 549) @@ -1106,7 +1106,7 @@ directive.addAttribute(DIRECTIVE_TYPE, directiveType); directive.addAttribute(DIRECTIVE_VALUE, directiveValue); - String[] lines = readBlock(2); + String[] lines = readBlock(1); String text = joinBlock(lines, "\n", false); directive.setText(text); Modified: trunk/jrst/src/main/java/org/nuiton/jrst/directive/ImageDirective.java =================================================================== --- trunk/jrst/src/main/java/org/nuiton/jrst/directive/ImageDirective.java 2011-03-04 12:37:01 UTC (rev 548) +++ trunk/jrst/src/main/java/org/nuiton/jrst/directive/ImageDirective.java 2011-03-07 16:23:50 UTC (rev 549) @@ -50,6 +50,10 @@ */ public class ImageDirective implements JRSTDirective { + protected static final String SCALE = "scale"; + protected static final String WIDTH = "width"; + protected static final String HEIGHT = "height"; + /* * (non-Javadoc) * @@ -73,6 +77,14 @@ if (matcher.matches()) { String name = matcher.group(1); String value = matcher.group(2); + if (SCALE.equalsIgnoreCase(name)) { + if (!result.asXML().matches(".*" + WIDTH + "=\".*\".*")) { + result.addAttribute(WIDTH, value + (value.matches(".*%") ? "" : "%")); + } + if (!result.asXML().matches(".*" + HEIGHT + "=\".*\".*")) { + result.addAttribute(HEIGHT, value + (value.matches(".*%") ? "" : "%")); + } + } result.addAttribute(name, value); } } Added: trunk/jrst/src/test/java/org/nuiton/jrst/bugs/DirectiveTest.java =================================================================== --- trunk/jrst/src/test/java/org/nuiton/jrst/bugs/DirectiveTest.java (rev 0) +++ trunk/jrst/src/test/java/org/nuiton/jrst/bugs/DirectiveTest.java 2011-03-07 16:23:50 UTC (rev 549) @@ -0,0 +1,68 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.nuiton.jrst.bugs; + +import java.io.File; + +import org.apache.commons.io.FileUtils; +import org.junit.Assert; +import org.junit.Test; +import org.nuiton.jrst.JRST; + +/** + * Test concernant les directives. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class DirectiveTest { + + /** + * Test que les options des directives images sont correctement + * parsées. + * + * @throws Exception + */ + @Test + public void testImageDirectiveOption() throws Exception { + File in = new File("src/test/resources/bugs/testImages21.rst"); + File out = File.createTempFile("jrst-testImages", ".html"); + out.deleteOnExit(); + JRST.generate(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME); + + String content = FileUtils.readFileToString(out); + Assert.assertTrue(content.indexOf("alt=\"alternate text\"") > 0); + Assert.assertTrue(content.indexOf("width=\"200 px\"") > 0); + Assert.assertTrue(content.indexOf("align=\"center\"") > 0); + Assert.assertTrue(content.indexOf("alt=\"tab alternate text\"") > 0); + // scale + Assert.assertTrue(content.indexOf("alt=\"tab alternate text\"") > 0); + Assert.assertTrue(content.indexOf("width=\"49%\" height=\"49%\"") > 0); + } +} Property changes on: trunk/jrst/src/test/java/org/nuiton/jrst/bugs/DirectiveTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/jrst/src/test/resources/bugs/testImages21.rst =================================================================== --- trunk/jrst/src/test/resources/bugs/testImages21.rst (rev 0) +++ trunk/jrst/src/test/resources/bugs/testImages21.rst 2011-03-07 16:23:50 UTC (rev 549) @@ -0,0 +1,20 @@ +Test attribut image +=================== + +.. image:: picture.jpeg + :height: 100px + :width: 200 px + :scale: 50 % + :alt: alternate text + :align: center + +.. image:: picturetab.jpeg + :height: 100px + :width: 200 px + :scale: 50 % + :alt: tab alternate text + :align: center + +.. image:: picturescale.jpeg + :scale: 49% + :alt: scale alternate text