Esempio n. 1
0
        public void DevMode_is_false()
        {
            FubuMode.Detector.SetMode("Production");
            FubuMode.InDevelopment().ShouldBeFalse();

            FubuMode.Mode().ShouldEqual("Production");
        }
Esempio n. 2
0
        protected override void beforeEach()
        {
            theEtag = "12345";

            theFiles = new[] { new AssetFile("a"), new AssetFile("b") };

            theAssetPath = new AssetPath("scripts/something")
            {
                ResourceHash = Guid.NewGuid().ToString()
            };

            theHeaders = new Header[] {
                new Header("a", "1"),
                new Header("b", "2"),
                new Header("c", "3"),
            };

            MockFor <IAssetCacheHeaders>().Stub(x => x.HeadersFor(theFiles)).Return(theHeaders);

            MockFor <IContentWriter>().Expect(x => x.Write(theAssetPath))
            .Return(theFiles);

            MockFor <IETagGenerator <IEnumerable <AssetFile> > >()
            .Stub(x => x.Create(theFiles))
            .Return(theEtag);

            FubuMode.ClearEnvironmentVariable();
            FubuMode.InDevelopment().ShouldBeFalse();

            ClassUnderTest.Write(theAssetPath);
        }
Esempio n. 3
0
        public SparkEngineSettings()
        {
            defaultSearch();
            defaultComposer();

            _precompileViews = () => !FubuMode.InDevelopment();
        }
Esempio n. 4
0
        public void DevMode_as_is_is_true()
        {
            FubuMode.Detector.SetMode("Development");
            FubuMode.InDevelopment().ShouldBeTrue();

            FubuMode.Mode().ShouldEqual("Development");
        }
Esempio n. 5
0
        public void fubu_mode_should_default_to_false_if_environment_doesnt_exist_with_file()
        {
            FubuMode.Detector = new FubuModeFileDetector();
            FubuModeFileDetector.Clear();

            FubuMode.InDevelopment().ShouldBeFalse();
        }
Esempio n. 6
0
        private static void addBuiltInDiagnostics(BehaviorGraph graph)
        {
            var settings = graph.Settings.Get <DiagnosticsSettings>();

            if (FubuMode.InDevelopment() || settings.TraceLevel != TraceLevel.None)
            {
                var chains = new DiagnosticChainsSource().BuildChains(graph).ToArray();

                // Apply authorization rules to the diagnostic chains
                chains.Each(x => x.Authorization.AddPolicies(settings.AuthorizationRights));

                graph.AddChains(chains);
            }


            if (FubuMode.InDevelopment() || settings.TraceLevel == TraceLevel.Verbose)
            {
                graph.Services.Clear(typeof(IBindingLogger));
                graph.Services.AddService <IBindingLogger, RecordingBindingLogger>();

                graph.Services.Clear(typeof(IBindingHistory));
                graph.Services.AddService <IBindingHistory, BindingHistory>();

                graph.Services.AddService <ILogListener, RequestTraceListener>();
            }
            else if (settings.TraceLevel == TraceLevel.Production)
            {
                graph.Services.AddService <ILogListener, ProductionModeTraceListener>();
            }
        }
Esempio n. 7
0
        public void DevMode_is_false()
        {
            Environment.SetEnvironmentVariable("FubuMode", "Production", EnvironmentVariableTarget.Machine);
            FubuMode.Reset();
            FubuMode.InDevelopment().ShouldBeFalse();

            FubuMode.Mode().ShouldEqual("Production");
        }
Esempio n. 8
0
        public void DevMode_as_is_is_true()
        {
            Environment.SetEnvironmentVariable("FubuMode", "Development", EnvironmentVariableTarget.Machine);
            FubuMode.Reset();
            FubuMode.InDevelopment().ShouldBeTrue();

            FubuMode.Mode().ShouldEqual("Development");
        }
Esempio n. 9
0
 private static void addBuiltInDiagnostics(BehaviorGraph graph)
 {
     if (FubuMode.InDevelopment())
     {
         graph.AddChain(RoutedChain.For <AboutDiagnostics>(x => x.get__about(), "_about"));
         graph.AddChain(RoutedChain.For <AboutDiagnostics>(x => x.get__loaded(), "_loaded"));
     }
 }
Esempio n. 10
0
 public void Activate(IEnumerable <IPackageInfo> packages, IPackageLog log)
 {
     if (FubuMode.InDevelopment())
     {
         return;
     }
     _activation(log);
 }
Esempio n. 11
0
        public FubuApplication BuildApplication()
        {
            FubuMode.Mode(FubuMode.Development);
            if (!FubuMode.InDevelopment())
            {
                throw new InvalidOperationException("You can't be here without development mode!");
            }

            return(FubuApplication.For <HarnessRegistry>().StructureMap(new Container()));
        }
Esempio n. 12
0
        public static bool ShouldRenderAuthoringTopic(this IFubuPage page)
        {
            if (!FubuMode.InDevelopment())
            {
                return(false);
            }

            var context = page.Get <ITopicContext>();

            return(!context.File.Contains("fubu-content"));
        }
Esempio n. 13
0
        public void DevMode_is_false_with_file()
        {
            Environment.SetEnvironmentVariable("FubuMode", "Development", EnvironmentVariableTarget.Machine);

            FubuMode.Detector = new FubuModeFileDetector();
            FubuMode.Detector.SetMode("Production");

            FubuMode.InDevelopment().ShouldBeFalse();

            FubuMode.Mode().ShouldEqual("Production");
        }
        private static void apply <T>(IEnumerable <IContentExtension <T> > extensions, IFubuPage <T> page, string tag)
            where T : class
        {
            var extensionOutput = extensions.SelectMany(ex => ex.GetExtensions(page)).Where(o => o != null).ToArray();

            if (extensionOutput.Length == 0 && FubuMode.InDevelopment())
            {
                page.Write("<!-- Content extensions '{1}' for {0} would be rendered here -->".ToFormat(typeof(T).Name,
                                                                                                       tag));
            }
            extensionOutput.Each(o => page.Write(o));
        }
Esempio n. 15
0
        public void DevMode_as_is_is_true_with_file()
        {
            Environment.SetEnvironmentVariable("FubuMode", "", EnvironmentVariableTarget.Machine);

            FubuMode.Detector = new FubuModeFileDetector();

            FubuMode.Detector.SetMode("Development");

            FubuMode.InDevelopment().ShouldBeTrue();

            FubuMode.Mode().ShouldEqual("Development");
        }
Esempio n. 16
0
        public AutoReloadingTag(string url, int interval)
            : base("script")
        {
            if (!FubuMode.InDevelopment())
            {
                Render(false);
            }

            Attr("language", "javascript");

            Encoded(false);

            var js = @"
      function FubuAppWatcher(url, interval){
        var self = this;

        self.lastValue = null;
        
        self.check = function(){
          xhr.open('GET', url, true);
          xhr.send();
        };
        
        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function(){
          if (xhr.readyState==4 && xhr.status==200){
            if (self.lastValue == null){
              self.lastValue = xhr.responseText;
            }
            else if (self.lastValue != xhr.responseText){
              location.reload(true);
              return;
            }
            
            window.setTimeout(self.check, interval);
          }
        };
        
        
        window.setTimeout(self.check, interval);
        return self;
      }

      var watcher = new FubuAppWatcher('{URL}', {INTERVAL});
      watcher.start();
";

            js = js.Replace("{URL}", url).Replace("{INTERVAL}", interval.ToString());


            Text(js);
        }
Esempio n. 17
0
        private void processAssetFiles(AssetPath path, IEnumerable <AssetFile> files)
        {
            string etag = _eTagGenerator.Create(files);

            _cache.LinkFilesToResource(path.ResourceHash, files);

            _output.AppendHeader(HttpResponseHeader.ETag, etag);

            if (!FubuMode.InDevelopment())
            {
                _cachingHeaders.HeadersFor(files).Each(x => x.Write(_output));
            }
        }
Esempio n. 18
0
        public void override_devmode()
        {
            string isDev = FubuMode.Development;

            FubuMode.Mode(() => isDev);

            FubuMode.InDevelopment().ShouldBeTrue();

            isDev = "something else";

            FubuMode.Reset();
            FubuMode.InDevelopment().ShouldBeFalse();
        }
Esempio n. 19
0
        public DefaultConfigurationPack()
        {
            For(ConfigurationType.Discovery);
            if (FubuMode.InDevelopment())
            {
                Add <RegisterAbout>();
            }

            For(ConfigurationType.Attributes);
            Add <UrlPatternAttributeOnViewModelPolicy>();
            Add <ModifyChainAttributeConvention>();

            For(ConfigurationType.ModifyRoutes);
            Add <ResourcePathRoutePolicy>();
            Add <MissingRouteInputPolicy>();

            For(ConfigurationType.InjectNodes);
            Add <ContinuationHandlerConvention>();
            Add <AsyncContinueWithHandlerConvention>();
            Add <CachedPartialConvention>();
            Add <CacheAttributePolicy>();

            For(ConfigurationType.Conneg);
            Add <JsonMessageInputConvention>();
            Add <AjaxContinuationPolicy>();
            Add <DictionaryOutputConvention>();
            Add <HtmlStringOutputPolicy>();
            Add <StringOutputPolicy>();
            Add <HtmlTagOutputPolicy>();

            For(ConfigurationType.Attachment);
            Add <DefaultOutputPolicy>();
            Add <AttachAuthorizationPolicy>();
            Add <AttachInputPolicy>();
            Add <AttachOutputPolicy>();

            For(ConfigurationType.Reordering);
            Add <OutputBeforeAjaxContinuationPolicy>();

            Add(new ReorderBehaviorsPolicy
            {
                WhatMustBeBefore = node => node.Category == BehaviorCategory.Authentication,
                WhatMustBeAfter  = node => node.Category == BehaviorCategory.Authorization
            });

            Add(new ReorderBehaviorsPolicy
            {
                WhatMustBeBefore = node => node is OutputCachingNode,
                WhatMustBeAfter  = node => node is OutputNode
            });
        }
 public static void ApplyInjection(OwinSettings settings)
 {
     if (FubuMode.InDevelopment() || FubuMode.Mode().EqualsIgnoreCase("diagnostics"))
     {
         var injectedContent = PackageRegistry.Properties[TEXT_PROPERTY];
         if (injectedContent.IsNotEmpty())
         {
             settings.AddMiddleware <HtmlHeadInjectionMiddleware>().Arguments.With(new InjectionOptions
             {
                 Content = _ => injectedContent
             });
         }
     }
 }
Esempio n. 21
0
        public void override_devmode()
        {
            string isDev = FubuMode.Development;

            FubuMode.Mode(() => isDev);

            FubuMode.InDevelopment().ShouldBeTrue();

            isDev = "something else";

            FubuMode.Detector = new EnvironmentVariableDetector();
            FubuMode.Detector.SetMode("");

            FubuMode.InDevelopment().ShouldBeFalse();
        }
Esempio n. 22
0
        public void set_to_dev_mode()
        {
            theCommand.Execute(new ModeInput
            {
                ClearFlag = true
            });

            theCommand.Execute(new ModeInput
            {
                DevFlag = true
            });

            FubuMode.Reset();

            FubuMode.InDevelopment().ShouldBeTrue();
        }
Esempio n. 23
0
        public AssetSettings()
        {
            if (!FubuMode.InDevelopment())
            {
                var cacheHeader = "private, max-age={0}".ToFormat(MaxAgeInSeconds);
                Headers[HttpResponseHeaders.CacheControl] = () => cacheHeader;
                Headers[HttpResponseHeaders.Expires]      = () => DateTime.UtcNow.AddSeconds(MaxAgeInSeconds).ToString("R");
            }

            Exclude("node_modules/*");

            Mode         = SearchMode.Anywhere;
            PublicFolder = "public";

            TemplateDestination = "_templates";
        }
        private static IHtmlString apply <T>(IEnumerable <IContentExtension <T> > extensions, IFubuPage <T> page, string tag)
            where T : class
        {
            var extensionOutput = extensions.SelectMany(ex => ex.GetExtensions(page)).Where(o => o != null).ToArray();

            if (extensionOutput.Length == 0 && FubuMode.InDevelopment())
            {
                page.Write("<!-- Content extensions '{1}' for {0} would be rendered here -->".ToFormat(typeof(T).Name,
                                                                                                       tag));
            }

            var output = new StringBuilder();

            extensionOutput.Each(o => output.Append(o).AppendLine());

            return(new HtmlString(output.ToString()));
        }
Esempio n. 25
0
        protected override void beforeEach()
        {
            theAssetPath = new AssetPath("scripts/something")
            {
                ResourceHash = Guid.NewGuid().ToString()
            };

            MockFor <IContentWriter>().Expect(x => x.Write(theAssetPath, null))
            .Constraints(Is.Equal(theAssetPath), Is.NotNull())
            .Return(false);


            FubuMode.Reset();
            FubuMode.InDevelopment().ShouldBeFalse();

            ClassUnderTest.Write(theAssetPath);
        }
Esempio n. 26
0
        public static void ApplyInjection(OwinSettings settings)
        {
            if (!FubuMode.InDevelopment())
            {
                return;
            }

            var injectedContent = PackageRegistry.Properties[TEXT_PROPERTY];

            if (injectedContent.IsNotEmpty())
            {
                settings.AddMiddleware <HtmlHeadInjectionMiddleware>().Arguments.With(new InjectionOptions
                {
                    Content = _ => injectedContent
                });
            }
        }
Esempio n. 27
0
        protected override void beforeEach()
        {
            theEtag = "12345";

            theFiles = Enumerable.Empty <AssetFile>();

            theAssetPath = new AssetPath("scripts/something")
            {
                ResourceHash = Guid.NewGuid().ToString()
            };

            MockFor <IContentWriter>().Expect(x => x.Write(theAssetPath))
            .Return(theFiles);


            FubuMode.ClearEnvironmentVariable();
            FubuMode.InDevelopment().ShouldBeFalse();

            ClassUnderTest.Write(theAssetPath);
        }
Esempio n. 28
0
        public static HtmlTag AuthoringTopic(this IFubuPage page)
        {
            var tag     = new HtmlTag("div").AddClass("authoring");
            var context = page.Get <ITopicContext>();

            if (FubuMode.InDevelopment() && context.Current != null)
            {
                var url   = page.Urls.UrlFor <FileRequest>();
                var topic = context.Current;

                if (context.File != null)
                {
                    tag.Add("div").Add("a")
                    .Data("url", url)
                    .Data("key", topic.Key)
                    .Attr("href", "#")
                    .AddClass("edit-link")
                    .Text("Edit File")
                    .Attr("title", context.File);

                    var lastUpdated = File.GetLastWriteTimeUtc(context.File).ToLocalTime();
                    tag.Add("div")
                    .AddClass("last-updated")
                    .Text("File changed at: " + lastUpdated)
                    .AddClass("file-changed");
                }

                var projectUrl = page.Urls.UrlFor(new ProjectRequest {
                    Name = context.Project.Name
                });
                tag.Add("div").Add("a").Text(context.Project.Name + " Project Page").Attr("href", projectUrl);
            }
            else
            {
                tag.Render(false);
            }



            return(tag);
        }
Esempio n. 29
0
        public ScriptTag(Func <string, string> toFullUrl, Asset asset, string defaultUrl = null)
            : base("script")
        {
            // http://stackoverflow.com/a/1288319/75194
            Attr("type", "text/javascript");

            if (asset == null)
            {
                Attr("src", toFullUrl(defaultUrl));
                return;
            }

            if (asset.CdnUrl.IsNotEmpty())
            {
                Attr("src", asset.CdnUrl);
                if (asset.FallbackTest.IsNotEmpty() && asset.File != null)
                {
                    Next = new HtmlTag("script");
                    var text = "if ({0}) document.write(unescape(\"%3Cscript src='{1}' type='text/javascript'%3E%3C/script%3E\"));".ToFormat(asset.FallbackTest, asset.Url);

                    Next.Encoded(false);
                    Next.Text(text);
                }

                return;
            }

            var url = asset.Url;

            if (FubuMode.InDevelopment() && asset.File != null)
            {
                url += "?Etag=" + asset.File.Etag();
            }

            Attr("src", toFullUrl(url));
        }
Esempio n. 30
0
        public void Configure(BehaviorGraph graph)
        {
            // Do nothing
            if (graph.Settings.Get <DiagnosticsSettings>().TraceLevel == TraceLevel.None && !FubuMode.InDevelopment())
            {
                return;
            }

            new TracingServices().As <IServiceRegistration>().Apply(graph.Services);

            foreach (BehaviorChain chain in graph.Behaviors.Where(ShouldApply).ToArray())
            {
                ApplyToChain(chain);
            }
        }