Splitting compiled GSS files in multiple files

177 views
Skip to first unread message

Hugo G. Fierro

unread,
Mar 12, 2012, 7:57:30 PM3/12/12
to closure-stylesheets-discuss
Hi

I need to generate separate CSS files that will be loaded on the same
page at different times (so renamed class names can't be reused). I
use both the closure templates and closure compiler.

For instance, here's what I'm looking for:
file1.gss: .class1{}
file2.gss: .class2{}
is compiled to:
.a{}.b{}
and separately:
file3.gss: .class3{}
is compiled to:
.d{} (and NOT .a{})

Is there currently a way to accomplish this with the GSS compiler?
If so, awesome, after going through all the docs I could not find it!

If not, I'll throw a couple of ideas to start the discussion:

1. Generate a global renaming map (from all the GSS files) then use it
to compute each CSS file.
Is there a way to specify a renaming map file as an input to the GSS
compiler (rather than just an output)?

2. Add --excluded-class-prefixes-from-renaming (or something similar).
For instance, the example with the flag set to "module1,module2":
file1.gss: .module1-class1{}
file2.gss: .module1-class2{}
is compiled to:
.module1-a{}.module1-b{}
and separately:
file3.gss: .module2-class3{}
is compiled to:
.module2-a{}
I think this can be accomplished by using two classes
(.module1 .class1 instead of .module1-class1) where the first one is
not renamed but the second one is.

Thanks,

Hugo

Hugo

unread,
Mar 18, 2012, 1:35:30 PM3/18/12
to closure-style...@googlegroups.com
Hi all

Just a quick update. I've accomplished something similar to idea (2) by exposing some existing compiler functionality via a command line flag. In particular, the JobDescriptionBuilder has a setCssRenamingPrefix method which simply appends a prefix to all renamed CSS classes. For each CSS file I generate, I would just use a different prefix to guarantee I get no CSS class conflicts when loading multiple CSS files that have been compiled separately.

Quick question: Is there any reason why such flag does not currently exist?

Here's a small patch if you are interested:

--- a/src/com/google/common/css/compiler/commandline/ClosureCommandLineCompiler.java
+++ b/src/com/google/common/css/compiler/commandline/ClosureCommandLineCompiler.java
@@ -172,6 +172,10 @@ public class ClosureCommandLineCompiler extends DefaultCommandLineCompiler {
         "com.google.common.css.compiler.gssfunctions."
         + "DefaultGssFunctionMapProvider";
 
+    @Option(name = "--css-renaming-prefix",
+        usage = "A prefix for all the renamed CSS classes.")
+    private String cssRenamingPrefix = "";
+
     /**
      * All remaining arguments are considered input CSS files.
      */
@@ -202,6 +206,7 @@ public class ClosureCommandLineCompiler extends DefaultCommandLineCompiler {
       builder.setEliminateDeadStyles(true);
       builder.setCssSubstitutionMapProvider(renamingType
           .getCssSubstitutionMapProvider());
+      builder.setCssRenamingPrefix(cssRenamingPrefix);
 
       GssFunctionMapProvider gssFunctionMapProvider =
           getGssFunctionMapProviderForName(gssFunctionMapProviderClassName);

Ian Flanigan

unread,
Mar 20, 2012, 1:27:21 PM3/20/12
to closure-style...@googlegroups.com
Hi Hugo,

I'm glad you found a solution. I think that the prefix was originally intended for something similar, so it seems like a good fit. Perhaps we'll expose it as a flag in the future, as you suggest.

Ian

tomonori...@gmail.com

unread,
Jun 3, 2013, 10:37:27 PM6/3/13
to closure-style...@googlegroups.com
I'm still looking forward this option being implemented!!



2012年3月21日水曜日 2時27分21秒 UTC+9 Ian Flanigan:
Reply all
Reply to author
Forward
0 new messages