~ s/PageRecipe/Recipe/
authorAlexandre Bertails <bertails@w3.org>
Wed, 27 Jul 2011 16:35:09 -0400
changeset 5 70417e3eadfd
parent 4 3ec91d41505e
child 6 7e0ad96e9467
~ s/PageRecipe/Recipe/
src/main/scala/FragmentDependencies.scala
src/test/scala/Test.scala
--- a/src/main/scala/FragmentDependencies.scala	Wed Jul 27 16:33:13 2011 -0400
+++ b/src/main/scala/FragmentDependencies.scala	Wed Jul 27 16:35:09 2011 -0400
@@ -12,11 +12,11 @@
   override def toString:String = url.toString
 
   /** tells is this page is concerned by the given recipe */
-  def isConcernedBy(recipe:PageRecipe):Boolean =
+  def isConcernedBy(recipe:Recipe):Boolean =
     recipe.regex findFirstIn url.toString isDefined
   
   /** returns the pages depending on this page through the given recipe */
-  def dependentPages(recipe:PageRecipe):Seq[Page] = {
+  def dependentPages(recipe:Recipe):Seq[Page] = {
     val optMatcher:Option[Regex.Match] = recipe.regex findFirstMatchIn url.toString
     val ruleDeps:Seq[Page] = optMatcher.toSeq flatMap {
       matcher => {
@@ -28,7 +28,7 @@
   }
 
   /** returns the pages impacted by this page through the given recipe */
-  def impactedPage(recipe:PageRecipe):Seq[Page] =
+  def impactedPage(recipe:Recipe):Seq[Page] =
     recipe impactedPage this
 
   /** GETs this page and extracts the pages that it contains
@@ -50,7 +50,7 @@
   * @param template an optional link to the template used to bake the target
   * @param rules the rules where the backward dependencies are found
   */
-case class PageRecipe (
+case class Recipe (
   val definedIn:Option[String],
   val regex: Regex,
   val template: Option[URL],
@@ -106,32 +106,32 @@
 
 }
 
-object PageRecipe {
+object Recipe {
 
-  def fromElem(e:Elem, from:Option[String] = None):PageRecipe = {
+  def fromElem(e:Elem, from:Option[String] = None):Recipe = {
     val regex = new Regex(e.attrs get "regexp" orElse (e.attrs get "href") getOrElse error("couldn't find regexp attribute in " + (from getOrElse "<unknown>")))
     val template = (e \ "template").headOption flatMap ( _.attrs get "src" ) map ( new URL(_) )
     val rules = e \ "rule" map ( rule => Rule.fromNode(rule) )
-    PageRecipe(from, regex, template, rules)
+    Recipe(from, regex, template, rules)
   }
 
-  def fromXML(xml:Elem, from:Option[String] = None):Seq[PageRecipe] = {
+  def fromXML(xml:Elem, from:Option[String] = None):Seq[Recipe] = {
     xml \ "page" map ( fromElem(_, from) )
   }
 
-  def fromSource(source:Source, from:Option[String] = None):Seq[PageRecipe] =
+  def fromSource(source:Source, from:Option[String] = None):Seq[Recipe] =
     fromXML(XML.fromSource(source), from)
 
-  def fromFile(file:String):Seq[PageRecipe] =
+  def fromFile(file:String):Seq[Recipe] =
     fromSource(Source.fromFile(file), Some(file))
 
-  def fromFile(file:java.io.File):Seq[PageRecipe] =
+  def fromFile(file:java.io.File):Seq[Recipe] =
     fromSource(Source.fromFile(file), Some(file.getAbsolutePath))
 
-  def fromURL(url:String):Seq[PageRecipe] =
+  def fromURL(url:String):Seq[Recipe] =
    fromURL(new URL(url)) 
 
-  def fromURL(url:URL):Seq[PageRecipe] =
+  def fromURL(url:URL):Seq[Recipe] =
    fromSource(Source.fromURL(url), Some(url.toString)) 
 
 }
@@ -149,7 +149,7 @@
 
 
 /** a sequence of recipes */
-case class Recipes(val recipes:Seq[PageRecipe]) {
+case class Recipes(val recipes:Seq[Recipe]) {
 
   def dependencies(pages:Seq[Page]):Seq[Page] = {
     val dependencies =
@@ -190,8 +190,8 @@
     //     page <- Page(uri).extractPages
     //   } yield page
 
-    val recipes:Seq[PageRecipe] =
-      docs flatMap { case(url, xml) => PageRecipe.fromXML(xml, Some(url)) }
+    val recipes:Seq[Recipe] =
+      docs flatMap { case(url, xml) => Recipe.fromXML(xml, Some(url)) }
     
     Recipes(recipes)
   }
--- a/src/test/scala/Test.scala	Wed Jul 27 16:33:13 2011 -0400
+++ b/src/test/scala/Test.scala	Wed Jul 27 16:35:09 2011 -0400
@@ -7,7 +7,7 @@
 
 class GeneratorSpec extends FunSuite with ShouldMatchers {
 
-  val tr_techs = PageRecipe.fromURL("http://www.w3.org/Web/fragments/tr-techs.xml")
+  val tr_techs = Recipe.fromURL("http://www.w3.org/Web/fragments/tr-techs.xml")
   val list_status = Page("http://www.w3.org/Web/fragments/list-status")
   val pages = list_status.extractPages