Ejemplo n.º 1
0
        public static object Deserialize(string input)
        {
            var deserializer = new TestDeserializer();

            TomlParser.ParseInput(input, deserializer);
            return(deserializer.value);
        }
Ejemplo n.º 2
0
        public void DetectTomlTest()
        {
            var input = @"
+++
title =  ""About"" 
+++ 
Lorem ipsum";

            var converter    = new StringToStreamConverter(input);
            var typeDetector = new TypeDetector(new StreamReader(converter.GetStreamFromString()));

            using TextReader sr = new StringReader(input);
            var parser = new TomlParser <SinglePage>(sr, string.Empty);
            var single = parser.GetAsSinglePage();

            Assert.Equal(FrontMatterType.Toml, typeDetector.GetFrontMatterType());
            Assert.Equal("About", single.Title);
            Assert.Equal("Lorem ipsum", single.Content);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            //var toml = Console.In.ReadToEnd();

            var toml = @"
[[albums.songs]]
name = ""Glory Days""
";

            try
            {
                var deserializer = new TestDeserializer();
                TomlParser.ParseInput(toml, deserializer);
                Console.Write(deserializer.Value);
                Environment.Exit(0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Environment.Exit(1);
            }
        }
Ejemplo n.º 4
0
        public bool TryLoadConfig()
        {
            try
            {
                if (!File.Exists(CONFIG_PATH))
                {
                    return(false);
                }

                var document = TomlParser.ParseFile(CONFIG_PATH);
                foreach (var key in document.Keys)
                {
                    var config = ConfigManager.ConfigElements[key];
                    config.BoxedValue = StringToConfigValue(document.GetValue(key).StringValue, config.ElementType);
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 5
0
        public void SummaryFromFileWithTomlFrontMatterTest()
        {
            string input = @"
 +++
title =  ""About"" 
 categories = [""Development"", ""VIM""]
date = ""2012-04-06""
description = ""spf13-vim is a cross platform distribution of vim plugins and resources for Vim.""
slug = ""spf13-vim-3-0-release-and-new-website""
testint = 1
+++
Summary.

That can be on another line.
<!--more-->
Lorem ipsum";

            using TextReader sr = new StringReader(input);
            var parser = new TomlParser <SinglePage>(sr, string.Empty);
            var single = parser.GetAsSinglePage();

            var converter = new StringToStreamConverter(input);
            var extractor = new SummaryExtractor(new StreamReader(converter.GetStreamFromString()));

            var summary = extractor.GetSummaryFromContent();

            Assert.Equal(@"Summary.

That can be on another line.
", summary);

            Assert.Equal(@"Summary.

That can be on another line.
<!--more-->
Lorem ipsum", single.Content);
        }
Ejemplo n.º 6
0
        public bool TryLoadConfig()
        {
            try
            {
                if (!File.Exists(CONFIG_PATH))
                {
                    return(false);
                }

                TomlDocument document = TomlParser.ParseFile(CONFIG_PATH);
                foreach (var key in document.Keys)
                {
                    var panelKey = (UIManager.Panels)Enum.Parse(typeof(UIManager.Panels), key);
                    ConfigManager.GetPanelSaveData(panelKey).Value = document.GetString(key);
                }

                return(true);
            }
            catch (Exception ex)
            {
                ExplorerCore.LogWarning("Error loading internal data: " + ex.ToString());
                return(false);
            }
        }
Ejemplo n.º 7
0
        private TomlDocument GetDocument(string resource)
        {
            var parser = new TomlParser();

            return(parser.Parse(resource));
        }
Ejemplo n.º 8
0
        public void ParserTest()
        {
            string input = @"
 +++
title =  ""About"" 
 categories = [""Development"", ""VIM""]
date = ""2012-04-06""
description = ""spf13-vim is a cross platform distribution of vim plugins and resources for Vim.""
slug = ""spf13-vim-3-0-release-and-new-website""
weight = 1
testint = 1
images = [""site-feature-image.jpg""]
testbool = false
teststring = ""What?""
testdate = ""2012-04-06""
testarray = [""Development"", ""VIM""]
tags = ["".vimrc"", ""plugins"", ""spf13-vim"", ""vim""]

[[resources]]
  name = ""header""
  src = ""images/sunset.jpg""

[[resources]]
  src = ""documents/photo_specs.pdf""
  title = ""Photo Specifications""
  [resources.params]
    icon = ""photo""

[[resources]]
  src = ""documents/guide.pdf""
  title = ""Instruction Guide""

[[resources]]
  src = ""documents/checklist.pdf""
  title = ""Document Checklist""

[[resources]]
  src = ""documents/payment.docx""
  title = ""Proof of Payment""

[[resources]]
  name = ""pdf-file-:counter""
  src = ""**.pdf""
  [resources.params]
    icon = ""pdf""

[[resources]]
  src = ""**.docx""
  [resources.params]
    icon = ""word""

[cascade]
  banner = ""images/typewriter.jpg""
  tags = ["".vimrc"", ""plugins"", ""spf13-vim"", ""vim""]
+++ 
Lorem ipsum";

            using TextReader sr = new StringReader(input);
            var parser = new TomlParser <SinglePage>(sr, string.Empty);
            var single = parser.GetAsSinglePage();

            Assert.Equal("About", single.Title);
            Assert.Equal("Development", single.Categories[0]);
            Assert.Equal("VIM", single.Categories[1]);
            Assert.Equal(new DateTime(2012, 4, 6).Date, single.Date.Date);
            Assert.Equal("spf13-vim is a cross platform distribution of vim plugins and resources for Vim.", single.Description);
            Assert.Equal("spf13-vim-3-0-release-and-new-website", single.Slug);
            Assert.Equal("1", single.CustomStringProperties["testint"]);
            Assert.Equal("False", single.CustomStringProperties["testbool"], StringComparer.OrdinalIgnoreCase);
            Assert.Equal("What?", single.CustomStringProperties["teststring"]);
            Assert.Equal("2012-04-06", single.CustomStringProperties["testdate"]);
            Assert.Equal("Development", single.CustomArrayProperties["testarray"][0]);
            Assert.Equal("VIM", single.CustomArrayProperties["testarray"][1]);
            Assert.Equal(".vimrc", single.Tags[0]);
            Assert.Equal("plugins", single.Tags[1]);
            Assert.Equal("spf13-vim", single.Tags[2]);
            Assert.Equal("vim", single.Tags[3]);
            Assert.Equal("images/typewriter.jpg", single.Cascade.CustomStringProperties["banner"]);
            Assert.Equal(".vimrc", single.Cascade.CustomArrayProperties["tags"][0]);
            Assert.Equal("Lorem ipsum", single.Content);
        }