Skip to content

Instantly share code, notes, and snippets.

@hikoz
Created June 26, 2012 12:46
Show Gist options
  • Save hikoz/2995613 to your computer and use it in GitHub Desktop.
Save hikoz/2995613 to your computer and use it in GitHub Desktop.
Reload problem for Rythm
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1937)
at com.greenlaw110.rythm.internal.CodeBuilder.setExtended_deprecated(CodeBuilder.java:280)
at com.greenlaw110.rythm.internal.CodeBuilder.setExtended(CodeBuilder.java:258)
at com.greenlaw110.rythm.internal.parser.build_in.ExtendsParser$1$1.call(ExtendsParser.java:67)
at com.greenlaw110.rythm.internal.CodeBuilder.invokeDirectives(CodeBuilder.java:388)
at com.greenlaw110.rythm.internal.CodeBuilder.build(CodeBuilder.java:365)
at com.greenlaw110.rythm.internal.compiler.TemplateClass.buildSourceCode(TemplateClass.java:320)
at com.greenlaw110.rythm.internal.compiler.TemplateClass.refresh(TemplateClass.java:417)
at com.greenlaw110.rythm.internal.compiler.TemplateClass.refresh(TemplateClass.java:311)
at com.greenlaw110.rythm.internal.compiler.TemplateClassLoader.detectChange(TemplateClassLoader.java:355)
at com.greenlaw110.rythm.internal.compiler.TemplateClassManager.checkUpdate(TemplateClassManager.java:91)
at com.greenlaw110.rythm.internal.compiler.TemplateClassManager.getByTemplate(TemplateClassManager.java:80)
at com.greenlaw110.rythm.RythmEngine.getTemplate(RythmEngine.java:407)
at com.greenlaw110.rythm.RythmEngine.render(RythmEngine.java:456)
at com.greenlaw110.rythm.Rythm.render(Rythm.java:94)
at rythm.test.ReloadTest.reload(ReloadTest.java:36)
package rythm.test;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.io.File;
import java.util.Properties;
import org.junit.Test;
import com.greenlaw110.rythm.Rythm;
import com.greenlaw110.rythm.utils.IO;
public class ReloadTest {
@Test
public void reload() throws Exception {
File d = new File(System.getProperty("java.io.tmpdir"));
Properties p = new Properties();
p.setProperty("rythm.root", d.getAbsolutePath());
p.setProperty("rythm.mode", "dev");
Rythm.init(p);
File f1 = new File(d, "f1.html");
IO.writeContent("@extends(f2)@set(title=\"foo\")", f1);
File f2 = new File(d, "f2.html");
IO.writeContent("@get(title)", f2);
assertThat(Rythm.render("f1.html"), is("foo\n"));
IO.writeContent("@extends(f2)@set(title=\"bar\")", f1);
assertThat(Rythm.render("f1.html"), is("foo\n"));
for (int i = 0; i < 5; ++i) {
sleep(6);
IO.writeContent("@extends(f2)@set(title=\"baz\")", f1);
assertThat(Rythm.render("f1.html"), is("baz\n"));
}
}
private void sleep(int n) throws InterruptedException {
for (int i = 0; i < n; ++i) {
Thread.sleep(1000L);
System.out.print(".");
}
System.out.println();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment