com.google.caja.plugin
Class CssRuleRewriter

java.lang.Object
  extended by com.google.caja.plugin.CssRuleRewriter

public final class CssRuleRewriter
extends java.lang.Object

Compiles CSS style-sheets to JavaScript which outputs the same CSS, but with rules only affecting nodes that are children of a class whose name contains the gadget id.

Author:
mikesamuel@gmail.com

Field Summary
private static java.lang.String GADGET_ID_PLACEHOLDER
          A string that will not pass CssRewriter.removeForbiddenIdents(com.google.caja.parser.AncestorChain), but which can be used as a suffix for identifiers and class literals that need to be dynamically generated at ___.loadModule time.
private  java.lang.String gadgetNameSuffix
           
 
Constructor Summary
CssRuleRewriter(PluginMeta meta)
           
 
Method Summary
static ArrayConstructor cssToJs(CssTree.StyleSheet ss)
          Returns an array containing chunks of CSS text that can be joined on a CSS identifier to yield sandboxed CSS.
private  void restrictRulesToSubtreeWithGadgetClass(CssTree.StyleSheet ss)
           
 void rewriteCss(CssTree.StyleSheet ss)
           
private  void rewriteIds(CssTree.StyleSheet ss)
           
private static boolean selectorMatchesElement(CssTree.SimpleSelector t, java.lang.String elementName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GADGET_ID_PLACEHOLDER

private static final java.lang.String GADGET_ID_PLACEHOLDER
A string that will not pass CssRewriter.removeForbiddenIdents(com.google.caja.parser.AncestorChain), but which can be used as a suffix for identifiers and class literals that need to be dynamically generated at ___.loadModule time.

See Also:
Constant Field Values

gadgetNameSuffix

private final java.lang.String gadgetNameSuffix
Constructor Detail

CssRuleRewriter

public CssRuleRewriter(PluginMeta meta)
Method Detail

rewriteCss

public void rewriteCss(CssTree.StyleSheet ss)
Parameters:
ss - modified destructively.

rewriteIds

private void rewriteIds(CssTree.StyleSheet ss)

restrictRulesToSubtreeWithGadgetClass

private void restrictRulesToSubtreeWithGadgetClass(CssTree.StyleSheet ss)

cssToJs

public static ArrayConstructor cssToJs(CssTree.StyleSheet ss)
Returns an array containing chunks of CSS text that can be joined on a CSS identifier to yield sandboxed CSS. This can be used client side with the emitCss___ method defined in "domita.js".

Parameters:
ss - a rewritten stylesheet.

selectorMatchesElement

private static boolean selectorMatchesElement(CssTree.SimpleSelector t,
                                              java.lang.String elementName)


Copyright (C) 2008 Google Inc.
Licensed under the Apache License, Version 2.0