本文整理汇总了Java中com.google.common.css.compiler.ast.GssParser类的典型用法代码示例。如果您正苦于以下问题:Java GssParser类的具体用法?Java GssParser怎么用?Java GssParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GssParser类属于com.google.common.css.compiler.ast包,在下文中一共展示了GssParser类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseAndPrint
import com.google.common.css.compiler.ast.GssParser; //导入依赖的package包/类
/**
* Helper method for parsing and outputting the result.
*/
private void parseAndPrint(StringBuilder result, GssParser parser)
throws GssParserException {
cssTree = parser.parse();
if (job.outputFormat != OutputFormat.DEBUG) {
passRunner.runPasses(cssTree);
}
if (job.outputFormat == OutputFormat.COMPRESSED) {
CompactPrinter compactPrinterPass = new CompactPrinter(cssTree, gssSourceMapGenerator);
compactPrinterPass.setPreserveMarkedComments(job.preserveImportantComments);
compactPrinterPass.runPass();
result.append(compactPrinterPass.getCompactPrintedString());
} else {
PrettyPrinter prettyPrinterPass = new PrettyPrinter(cssTree
.getVisitController(),
null /* use external buffer */,
gssSourceMapGenerator);
prettyPrinterPass
.setPreserveComments(job.preserveComments)
.runPass();
result.append(prettyPrinterPass.getPrettyPrintedString());
}
}
示例2: parse
import com.google.common.css.compiler.ast.GssParser; //导入依赖的package包/类
/**
* Parses GSS style sheets and returns one tree containing everything.
*
* @param fileNameToGss a map connecting names to GSS style sheets
* @return the CSS tree created by the parser
* @throws GssParserException
*/
protected CssTree parse(ImmutableMap<String, String> fileNameToGss)
throws GssParserException {
ImmutableList.Builder<SourceCode> builder = ImmutableList.builder();
for (Map.Entry<String, String> entry : fileNameToGss.entrySet()) {
builder.add(new SourceCode(entry.getKey(), entry.getValue()));
}
return new GssParser(builder.build()).parse();
}
示例3: normalizeExpectedCss
import com.google.common.css.compiler.ast.GssParser; //导入依赖的package包/类
/**
* Normalizes the expected CSS to a pretty-printed form that can be compared
* with the result of {@link #getCompiledCss()}.
*/
private static String normalizeExpectedCss(String expectedCss)
throws GssParserException {
List<SourceCode> inputs = ImmutableList.of(
new SourceCode("expectedCss", expectedCss));
CssTree tree = new GssParser(inputs).parse();
PrettyPrinter prettyPrinterPass = new PrettyPrinter(tree
.getVisitController());
prettyPrinterPass.runPass();
return prettyPrinterPass.getPrettyPrintedString();
}
示例4: parse
import com.google.common.css.compiler.ast.GssParser; //导入依赖的package包/类
private void parse(String styleSheet, RecordingSubstitutionMap map) {
SourceCode input = new SourceCode("test-input", styleSheet);
GssParser parser = new GssParser(input);
CssTree cssTree;
try {
cssTree = parser.parse();
} catch (GssParserException e) {
throw new RuntimeException(e);
}
JobDescription job = new JobDescriptionBuilder().getJobDescription();
ErrorManager errorManager = new DummyErrorManager();
PassRunner passRunner = new PassRunner(job, errorManager, map);
passRunner.runPasses(cssTree);
}
示例5: testPassResult
import com.google.common.css.compiler.ast.GssParser; //导入依赖的package包/类
@Test
public void testPassResult() throws Exception {
CssTree tree = new GssParser(new SourceCode(null, lines(
"@-moz-document url-prefix() {",
" foo {",
" padding: 6px;",
" }",
" bar {",
" padding: 6px;",
" }",
"}",
"foo {",
" padding: 5px;",
"}",
"bar {",
" padding: 5px;",
"}"))).parse();
assertThat(tree.getRoot().getBody().toString())
.isEqualTo(
"[@-moz-document[url-prefix()]{[[foo]{[padding:[6px]]}, [bar]{[padding:[6px]]}]}, "
+ "[foo]{[padding:[5px]]}, [bar]{[padding:[5px]]}]");
MergeAdjacentRulesetNodesWithSameDeclarations pass =
new MergeAdjacentRulesetNodesWithSameDeclarations(tree);
pass.runPass();
assertThat(tree.getRoot().getBody().toString())
.isEqualTo(
"[@-moz-document[url-prefix()]{[[foo, bar]{[padding:[6px]]}, [bar]{[padding:[6px]]}]}, "
+ "[foo, bar]{[padding:[5px]]}, [bar]{[padding:[5px]]}]");
}
开发者ID:google,项目名称:closure-stylesheets,代码行数:32,代码来源:MergeAdjacentRulesetNodesWithSameDeclarationsTest.java
示例6: testDoNotMergePseudoElements
import com.google.common.css.compiler.ast.GssParser; //导入依赖的package包/类
@Test
public void testDoNotMergePseudoElements() throws Exception {
CssTree tree = new GssParser(new SourceCode(null, lines(
"foo {",
" padding: 5px;",
"}",
".bar {",
" padding: 5px;",
"}",
"baz::-ms-clear {",
" padding: 5px;",
"}",
".bez {",
" padding: 5px;",
"}",
"biz {",
" padding: 5px;",
"}"))).parse();
MergeAdjacentRulesetNodesWithSameDeclarations pass =
new MergeAdjacentRulesetNodesWithSameDeclarations(tree);
pass.runPass();
assertThat(tree.getRoot().getBody().toString())
.isEqualTo(
"[[foo, .bar]{[padding:[5px]]}, [.bar]{[padding:[5px]]}, "
+ "[baz::-ms-clear]{[padding:[5px]]}, "
+ "[.bez, biz]{[padding:[5px]]}, [biz]{[padding:[5px]]}]");
}
开发者ID:google,项目名称:closure-stylesheets,代码行数:29,代码来源:MergeAdjacentRulesetNodesWithSameDeclarationsTest.java
示例7: parseStyleSheet
import com.google.common.css.compiler.ast.GssParser; //导入依赖的package包/类
private CssTree parseStyleSheet(String sourceCode) {
SourceCode input = new SourceCode("testInput", sourceCode);
GssParser parser = new GssParser(input);
try {
return parser.parse();
} catch (GssParserException e) {
throw new RuntimeException(e);
}
}
示例8: testPassResult
import com.google.common.css.compiler.ast.GssParser; //导入依赖的package包/类
@Test
public void testPassResult() throws Exception {
CssTree tree = new GssParser(new SourceCode(null, lines(
"@-moz-document url-prefix() {",
" foo {",
" padding: 6px;",
" }",
" foo {",
" margin: 4px;",
" }",
"}",
"foo, .bar #id {",
" padding: 5px;",
"}",
"foo, .bar #id {",
" margin: 2px;",
"}"))).parse();
assertThat(AstPrinter.print(tree))
.isEqualTo(
"[@-moz-document [url-prefix()]"
+ "{[foo]{[padding:[[6px]];]}[foo]{[margin:[[4px]];]}}"
+ "[foo,.bar #id]{[padding:[[5px]];]}"
+ "[foo,.bar #id]{[margin:[[2px]];]}]");
MergeAdjacentRulesetNodesWithSameSelector pass =
new MergeAdjacentRulesetNodesWithSameSelector(tree);
pass.runPass();
// As the elimination pass is not run here, we still have the one of the old
// rulesets in each place.
assertThat(AstPrinter.print(tree))
.isEqualTo(
"[@-moz-document [url-prefix()]"
+ "{[foo]{[padding:[[6px]];margin:[[4px]];]}[foo]{[margin:[[4px]];]}}"
+ "[foo,.bar #id]{[padding:[[5px]];margin:[[2px]];]}"
+ "[foo,.bar #id]{[margin:[[2px]];]}]");
}
开发者ID:google,项目名称:closure-stylesheets,代码行数:38,代码来源:MergeAdjacentRulesetNodesWithSameSelectorTest.java
示例9: visit
import com.google.common.css.compiler.ast.GssParser; //导入依赖的package包/类
@Override
public boolean visit(CssProperty x, Context ctx) {
maybePrintOpenBrace();
StringBuilder propertyBuilder = new StringBuilder();
if (noFlip) {
propertyBuilder.append(NO_FLIP);
propertyBuilder.append(' ');
}
propertyBuilder.append(x.getName());
propertyBuilder.append(": ");
propertyBuilder.append(printValuesList(x.getValues().getValues()));
if (x.isImportant()) {
propertyBuilder.append(IMPORTANT);
}
String cssProperty = propertyBuilder.toString();
if (lenient) {
// lenient mode: Try to parse the css rule and if an error occurs,
// print a warning message and don't print the rule.
try {
new GssParser(new SourceCode(null, "body{" + cssProperty + "}")).parse();
} catch (GssParserException e) {
treeLogger.log(Type.WARN, "The following property is not valid and will be skipped: " +
cssProperty);
return false;
}
}
out.print(cssProperty);
semiColon();
return true;
}
示例10: parse
import com.google.common.css.compiler.ast.GssParser; //导入依赖的package包/类
/**
* Parses GSS style sheets and returns one tree containing everything.
*
* @return the CSS tree created by the parser
*/
public CssTree parse() throws GssParserException {
tree = new GssParser(sources).parse();
runPasses(tree);
return tree;
}
示例11: parse
import com.google.common.css.compiler.ast.GssParser; //导入依赖的package包/类
private CssTree parse(String source) throws GssParserException {
return new GssParser(new SourceCode(null, source)).parse();
}