Example #1
0
        public void TestCreateGetsContentTypes()
        {
            FileInfo targetFile = OpenXml4NetTestDataSamples.GetOutputFile("TestCreatePackageTMP.docx");

            // Zap the target file, in case of an earlier run
            if (File.Exists(targetFile.FullName))
            {
                File.Delete(targetFile.FullName);
                Assert.IsFalse(File.Exists(targetFile.FullName));
            }


            OPCPackage pkg = OPCPackage.Create(targetFile.FullName);

            // Check it has content types for rels and xml
            ContentTypeManager ctm = GetContentTypeManager(pkg);

            Assert.AreEqual(
                "application/xml",
                ctm.GetContentType(
                    PackagingUriHelper.CreatePartName("/foo.xml")
                    )
                );
            Assert.AreEqual(
                ContentTypes.RELATIONSHIPS_PART,
                ctm.GetContentType(
                    PackagingUriHelper.CreatePartName("/foo.rels")
                    )
                );
            Assert.IsNull(
                ctm.GetContentType(
                    PackagingUriHelper.CreatePartName("/foo.txt")
                    )
                );
        }
Example #2
0
        public void TestMixinExpansion()
        {
            var lessFactory = CssParserLocator.FindComponent(ContentTypeManager.GetContentType(LessContentTypeDefinition.LessContentType));
            var lessCode    = @"a {
                                .myMixin(@p) {
                                    b, code {
                                    }
                                }
                            }";

            var lessDoc    = lessFactory.CreateParser().Parse(lessCode, false);
            var lessBlocks = new CssItemAggregator <RuleSet>(true)
            {
                (RuleSet rs) => rs
            }.Crawl(lessDoc).ToList();

            // Remove all but the deepest blocks
            while (0 < lessBlocks.RemoveAll(c => lessBlocks.Any(c.IsParentOf)))
            {
                ;
            }

            var literalExpansions = lessBlocks.SelectMany(rs => LessDocument.GetSelectorNames(rs, LessMixinAction.Literal)).ToList();

            literalExpansions.Should().Equal(new[] { "a .myMixin(@p) b", "a .myMixin(@p) code" });

            var skipExpansions = lessBlocks.SelectMany(rs => LessDocument.GetSelectorNames(rs, LessMixinAction.Skip)).ToList();

            skipExpansions.Should().BeEmpty();

            var nestedExpansions = lessBlocks.SelectMany(rs => LessDocument.GetSelectorNames(rs, LessMixinAction.NestedOnly)).ToList();

            nestedExpansions.Should().Equal(new[] { "«mixin .myMixin» b", "«mixin .myMixin» code" });
        }
Example #3
0
        public string SortScss(string scss)
        {
            ICssParser parser     = CssParserLocator.FindComponent(ContentTypeManager.GetContentType(ScssContentTypeDefinition.ScssContentType)).CreateParser();
            StyleSheet stylesheet = parser.Parse(scss.Trim(), true);

            return(PreprocessorSorting(stylesheet));
        }
Example #4
0
 public static IEnumerable <IContentType> GetChainCompilationContentTypes()
 {
     return(new[] {
         ContentTypeManager.GetContentType("LESS"),
         ContentTypeManager.GetContentType("SCSS")
     });
 }
Example #5
0
        public void TestMixinExpansion()
        {
            var scssFactory = CssParserLocator.FindComponent(ContentTypeManager.GetContentType(ScssContentTypeDefinition.ScssContentType));
            var scssCode    = @"a {
                                @mixin myMixin($p) {
                                        b, code {
                                            width: $p+10+px;
                                        }
                                    }
                                    @include myMixin(1)
                                }
                            ";

            var scssDoc    = scssFactory.CreateParser().Parse(scssCode, false);
            var scssBlocks = new CssItemAggregator <RuleSet>(true)
            {
                (RuleSet rs) => rs
            }.Crawl(scssDoc).ToList();

            // Remove all but the deepest blocks
            while (0 < scssBlocks.RemoveAll(c => scssBlocks.Any(c.IsParentOf)))
            {
                ;
            }

            var literalExpansions = scssBlocks.SelectMany(rs => ScssDocument.GetSelectorNames(rs, ScssMixinAction.Literal)).ToList();

            literalExpansions.Should().Equal(new[] { "a b", "a code" });

            var skipExpansions = scssBlocks.SelectMany(rs => ScssDocument.GetSelectorNames(rs, ScssMixinAction.Skip)).ToList();

            skipExpansions.Should().BeEmpty();
        }
Example #6
0
        private void AddHtmlFiles()
        {
            var paths       = ProjectHelpers.GetSelectedItemPaths(_dte);
            var contentType = ContentTypeManager.GetContentType("Markdown");
            var compiler    = Mef.GetImport <ICompilerRunnerProvider>(contentType).GetCompiler(contentType);

            Parallel.ForEach(paths, f => compiler.CompileToDefaultOutputAsync(f).DoNotWait("compiling " + f));
        }
Example #7
0
        private void AddHtmlFiles()
        {
            var paths    = ProjectHelpers.GetSelectedItemPaths(_dte);
            var compiler = WebEditor.ExportProvider.GetExport <ICompilerRunnerProvider>()
                           .Value.GetCompiler(ContentTypeManager.GetContentType("Markdown"));

            Parallel.ForEach(paths, f => compiler.CompileToDefaultOutputAsync(f).DontWait("compiling " + f));
        }
        public TypeScriptCompilationNotifier(ITextDocument doc)
        {
            Document = doc;
            Document.FileActionOccurred += Document_FileActionOccurred;

            _listeners = Mef.GetAllImports <IFileSaveListener>(ContentTypeManager.GetContentType("JavaScript"));

            _watcher        = new FileSystemWatcher(Path.GetDirectoryName(TargetFilePath));
            _watcher.Filter = Path.GetFileName(TargetFilePath);
            _watcher.EnableRaisingEvents = true;
            _watcher.Created            += FileTouched;
            _watcher.Changed            += FileTouched;
        }
        private void FileTouched(object sender, FileSystemEventArgs e)
        {
            // The check for _isReady is in place to deal with the issue where
            // FileSystemWatcher fires twice per file change.
            if (!_isReady)
            {
                _isReady = true;
                return;
            }

            if (File.Exists(TargetFilePath))
            {
                RaiseReady();

                foreach (var listener in _listeners)
                {
                    listener.FileSaved(ContentTypeManager.GetContentType("JavaScript"), TargetFilePath, false, false);
                }
            }
            _isReady = false;
        }
Example #10
0
        private void Minify()
        {
            _dte.StatusBar.Text = "Web Essentials: Minifying files...";
            var extensions = new HashSet <string>(
                Mef.GetSupportedExtensions <IFileMinifier>(),
                StringComparer.OrdinalIgnoreCase
                );

            var files = ProjectHelpers.GetAllProjects()
                        .Select(ProjectHelpers.GetRootFolder)
                        .SelectMany(p => Directory.EnumerateFiles(p, "*", SearchOption.AllDirectories))
                        .Where(f => extensions.Contains(Path.GetExtension(f)));

            // Perform expensive blocking work in parallel
            Parallel.ForEach(files, file =>
                             MinificationSaveListener.ReMinify(
                                 ContentTypeManager.GetContentType(Path.GetExtension(file).TrimStart('.')),
                                 file,
                                 false
                                 )
                             );

            EditorExtensionsPackage.DTE.StatusBar.Clear();
        }
Example #11
0
 public TemplateBufferGenerator(HtmlEditorTree editorTree, LanguageBlockCollection languageBlocks)
     : base(editorTree, languageBlocks, ContentTypeManager.GetContentType(TemplateTagContentType.ContentTypeName))
 {
 }
Example #12
0
 public TemplateBlockHandler(HtmlEditorTree editorTree)
     : base(editorTree, ContentTypeManager.GetContentType(TemplateHtmlContentType.ContentTypeName))
 {
 }
Example #13
0
        public void SubjectBuffersConnected(IWpfTextView textView, ConnectionReason reason, Collection <ITextBuffer> subjectBuffers)
        {
            ITextDocument document;

            if (TextDocumentFactoryService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out document))
            {
                textView.Properties.GetOrCreateSingletonProperty("HandlebarsCompilationNotifier", () =>
                                                                 Mef.GetImport <ICompilationNotifierProvider>(ContentTypeManager.GetContentType("Handlebars"))
                                                                 .GetCompilationNotifier(document));
            }
        }
Example #14
0
 public IJSONFormatter CreateFormatter()
 {
     return(JSONFormatterLocator.FindComponent(ContentTypeManager.GetContentType("JSON")).CreateFormatter());
 }
Example #15
0
        public async Task SelectorExpansionTest()
        {
            #region LESS sources
            var testSources = new[] {
                @"
@media all {
    a {
        @media all {
            @media all {
                b {
                    color: goldenrod;
                    em {
                        color: goldenrod;
                    }
                }
            }
        }
    }
}
",
                @"  // Taken from http://blog.slaks.net/2013-09-29/less-css-secrets-of-the-ampersand/
a {
    color: blue;
    &:hover {
        color: green;
    }
}
form a {
    color: purple;
    body.QuietMode & {
        color: black;
    }
}
.quoted-source {
    background: #fcc;
    blockquote& {
        background: #fdc;
    }
}
.btn.btn-primary.btn-lg[disabled] {
    & + & + & {
        margin-left: 10px;
    }
}
p, blockquote, ul, li {
    border-top: 1px solid gray;
    & + & {
        border-top: 0;
    }
}
",
                @"  // Taken from https://github.com/less/less.js/blob/master/test/less/selectors.less
h1, h2, h3 {
  a, p {
    &:hover {
      color: red;
    }
  }
}

#all { color: blue; }
#the { color: blue; }
#same { color: blue; }

ul, li, div, q, blockquote, textarea {
  margin: 0;
}

td {
  margin: 0;
  padding: 0;
}

td, input {
  line-height: 1em;
}

a {
  color: red;

  &:hover { color: blue; }

  div & { color: green; }

  p & span { color: yellow; }
}

.foo {
  .bar, .baz {
    & .qux {
      display: block;
    }
    .qux & {
      display: inline;
    }
    .qux& {
      display: inline-block;
    }
    .qux & .biz {
      display: none;
    }
  }
}

.b {
 &.c {
  .a& {
   color: red;
  }
 }
}

.b {
 .c & {
  &.a {
   color: red;
  }
 }
}

.p {
  .foo &.bar {
    color: red;
  }
}

.p {
  .foo&.bar {
    color: red;
  }
}

.foo {
  .foo + & {
    background: amber;
  }
  & + & {
    background: amber;
  }
}

.foo, .bar {
  & + & {
    background: amber;
  }
}

.foo, .bar {
  a, b {
    & > & {
      background: amber;
    }
  }
}

.other ::fnord { color: red }
.other::fnord { color: red }
.other {
  ::bnord {color: red }
  &::bnord {color: red }
}
",
                @"// Taken from https://github.com/less/less.js/blob/master/test/less/rulesets.less
#first > .one {
  > #second .two > #deux {
    width: 50%;
    #third {
      &:focus {
        color: black;
        #fifth {
          > #sixth {
            .seventh #eighth {
              + #ninth {
                color: purple;
              }
            }
          }
        }
      }
      height: 100%;
    }
    #fourth, #five, #six {
      color: #110000;
      .seven, .eight > #nine {
        border: 1px solid black;
      }
      #ten {
        color: red;
      }
    }
  }
  font-size: 2em;
}
"
            };
            #endregion

            var lessFactory = CssParserLocator.FindComponent(ContentTypeManager.GetContentType(LessContentTypeDefinition.LessContentType));
            foreach (var lessCode in testSources)
            {
                var cssCode = await new LessCompiler().CompileSourceAsync(lessCode, ".less");
                var lessDoc = lessFactory.CreateParser().Parse(lessCode, false);
                var cssDoc  = new CssParser().Parse(cssCode, false);

                var cssSelectors = new CssItemAggregator <string>(false)
                {
                    (Selector s) => CssExtensions.SelectorText(s)
                }.Crawl(cssDoc);

                var lessSelectors = new CssItemAggregator <RuleSet>(true)
                {
                    (RuleSet rs) => rs
                }.Crawl(lessDoc)
                .Where(rs => rs.Block.Declarations.Any())                                   // Skip selectors that don't have any rules; these won't end up in the CSS
                .SelectMany(rs => LessDocument.GetSelectorNames(rs, LessMixinAction.Literal))
                .ToList();

                lessSelectors.Should().Equal(cssSelectors);
            }
        }
Example #16
0
 public void SetupCommands()
 {
     _mcs.AddCommand(new MinifyFileCommand(ContentTypeManager.GetContentType("Css"), MinifyCommandId.MinifyCss).Command);
     _mcs.AddCommand(new MinifyFileCommand(ContentTypeManager.GetContentType("HTMLX"), MinifyCommandId.MinifyHtml).Command);
     _mcs.AddCommand(new MinifyFileCommand(ContentTypeManager.GetContentType("JavaScript"), MinifyCommandId.MinifyJs).Command);
 }