zoukankan      html  css  js  c++  java
  • 【kooboo】代码块

    image

    namespace Kooboo.CMS.Sites.Services
    {
        public class CodeSnippetManager
        {
            protected string BasePath
            {
                get
                {
                    return Kooboo.Web.Mvc.AreaHelpers.CombineAreaFilePhysicalPath("Sites", "CodeSnippets");
                }
            }
            protected virtual string FileExtension
            {
                get
                {
                    return ".txt";
                }
            }
     
            public virtual CodeSnippetGroup All(string viewEngine)
            {
                var physicalPath = Path.Combine(BasePath, viewEngine);
                CodeSnippetGroup root = new CodeSnippetGroup() { Name = "root", Parent = null, ViewEngine = viewEngine };
                if (Directory.Exists(physicalPath))
                {
                    root.ChildGroups = AllGroups(viewEngine, root, physicalPath);
                    root.CodeSnippets = AllCodeSnippet(root, physicalPath);
                }
                return root;
            }
            private IEnumerable<CodeSnippetGroup> AllGroups(string viewEngine, CodeSnippetGroup parent, string physicalPath)
            {
                var dir = Directory.GetDirectories(physicalPath);
                if (dir.Length != 0)
                {
                    foreach (var item in dir.ExcludeSvn())
                    {
                        var group = new CodeSnippetGroup()
                        {
                            ViewEngine = viewEngine,
                            Name = Path.GetFileNameWithoutExtension(item),
                            Parent = parent
                        };
                        group.ChildGroups = AllGroups(viewEngine, parent, item);
                        group.CodeSnippets = AllCodeSnippet(group, item);
                        yield return group;
                    }
                }
            }
     
            private IEnumerable<CodeSnippet> AllCodeSnippet(CodeSnippetGroup group, string physicalPath)
            {
                return Directory.EnumerateFiles(physicalPath, "*" + FileExtension).Select(it =>
                    new CodeSnippet()
                    {
                        Group = group,
                        ViewEngine = group.ViewEngine,
                        Name = Path.GetFileNameWithoutExtension(it),
                        Code = IO.IOUtility.ReadAsString(it)
                    });
            }       
        }
    }
  • 相关阅读:
    自定义导航全屏滑动返回上一页
    快速tab应用
    一种透明效果的view
    10.11 pod 安装
    GIT本地操作
    Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/dyld_sim is not owned by root.
    bt5r3开启远程登录
    神奇的脚本1
    pt-table-checksum和pt-table-sync
    http://blog.sae.sina.com.cn/archives/881
  • 原文地址:https://www.cnblogs.com/zbw911/p/2867579.html
Copyright © 2011-2022 走看看