shindig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject svn commit: r1152402 - in /shindig/trunk/java/gadgets/src: main/java/org/apache/shindig/gadgets/js/ConfigInjectionProcessor.java test/java/org/apache/shindig/gadgets/js/ConfigInjectionProcessorTest.java
Date Sat, 30 Jul 2011 00:17:04 GMT
Author: johnh
Date: Sat Jul 30 00:17:03 2011
New Revision: 1152402

URL: http://svn.apache.org/viewvc?rev=1152402&view=rev
Log:
Abstract out config code injection methods for ConfigInjectionProcessor.

Patch provided by Chris Song.


Modified:
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/ConfigInjectionProcessor.java
    shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/js/ConfigInjectionProcessorTest.java

Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/ConfigInjectionProcessor.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/ConfigInjectionProcessor.java?rev=1152402&r1=1152401&r2=1152402&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/ConfigInjectionProcessor.java
(original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/ConfigInjectionProcessor.java
Sat Jul 30 00:17:03 2011
@@ -46,6 +46,9 @@ public class ConfigInjectionProcessor im
   static final String GLOBAL_CONFIG_KEY_TPL = "window['___cfg']=%s;\n";
   @VisibleForTesting
   static final String CONFIG_FEATURE = "core.config.base";
+  @VisibleForTesting
+  static final String CONFIG_INJECT_CODE =
+      "(window['___jsl']['ci'] = (window['___jsl']['ci'] || [])).push(%s);";
 
   private final FeatureRegistryProvider registryProvider;
   private final ConfigProcessor configProcessor;
@@ -82,15 +85,24 @@ public class ConfigInjectionProcessor im
         String configJson = JsonSerializer.serialize(config);
         if (allReq.contains(CONFIG_FEATURE) || loaded.contains(CONFIG_FEATURE)) {
           // config lib is present: pass it data
-          builder.appendJs(String.format(CONFIG_INIT_TPL, configJson), CONFIG_INIT_ID);
+          injectBaseConfig(configJson, builder);
         } else {
           // config lib not available: use global variable
-          builder.appendJs(String.format(GLOBAL_CONFIG_KEY_TPL, configJson), CONFIG_INIT_ID);
+          injectGlobalConfig(configJson, builder);
         }
       }
     }
     return true;
   }
+  
+  protected void injectBaseConfig(String configJson, JsResponseBuilder builder) {
+    builder.prependJs(String.format(CONFIG_INJECT_CODE, configJson), CONFIG_INIT_ID);
+    builder.appendJs(String.format(CONFIG_INIT_TPL, configJson), CONFIG_INIT_ID);
+  }
+
+  protected void injectGlobalConfig(String configJson, JsResponseBuilder builder) {
+    builder.appendJs(String.format(GLOBAL_CONFIG_KEY_TPL, configJson), CONFIG_INIT_ID);
+  }
 
   private List<String> subtractCollection(Collection<String> root, Collection<String>
subtracted) {
     Set<String> result = Sets.newHashSet(root);

Modified: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/js/ConfigInjectionProcessorTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/js/ConfigInjectionProcessorTest.java?rev=1152402&r1=1152401&r2=1152402&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/js/ConfigInjectionProcessorTest.java
(original)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/js/ConfigInjectionProcessorTest.java
Sat Jul 30 00:17:03 2011
@@ -212,7 +212,7 @@ public class ConfigInjectionProcessorTes
     assertTrue(processor.process(request, builder));
     control.verify();
     String jsCode = builder.build().toJsString();
-    String baseMatch = BASE_CODE + "gadgets.config.init(";
+    String baseMatch = "(window['___jsl']['ci'] = (window['___jsl']['ci'] || [])).push(";
     assertTrue(jsCode.startsWith(baseMatch));
     String endMatch = ");\n";
     assertTrue(jsCode.endsWith(endMatch));



Mime
View raw message