Samples => lazySamples.Value;
+
+ [Route("/Samples/Run/{name}")]
+ public IActionResult Run (string name)
+ {
+ if (string.IsNullOrWhiteSpace (name) || name.Length > 32)
+ return BadRequest ();
+
+ var s = Samples.FirstOrDefault (x => x.Title == name);
+ if (s == null)
+ return NotFound ();
+
+ return new ElementResult (s.CreateElement ());
+ }
}
}
diff --git a/PlatformSamples/AspNetCoreMvc/Views/Home/Index.cshtml b/PlatformSamples/AspNetCoreMvc/Views/Home/Index.cshtml
index 3461f7c..53b984e 100644
--- a/PlatformSamples/AspNetCoreMvc/Views/Home/Index.cshtml
+++ b/PlatformSamples/AspNetCoreMvc/Views/Home/Index.cshtml
@@ -16,8 +16,9 @@
diff --git a/PlatformSamples/AspNetCoreMvc/Views/_ViewImports.cshtml b/PlatformSamples/AspNetCoreMvc/Views/_ViewImports.cshtml
index 2ceef29..2b7dee4 100644
--- a/PlatformSamples/AspNetCoreMvc/Views/_ViewImports.cshtml
+++ b/PlatformSamples/AspNetCoreMvc/Views/_ViewImports.cshtml
@@ -1,3 +1,4 @@
@using AspNetCoreMvc
@using AspNetCoreMvc.Models
+@using AspNetCoreMvc.Controllers
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
diff --git a/Samples/ButtonSample.cs b/Samples/ButtonSample.cs
index 2ae5a28..2a2d685 100644
--- a/Samples/ButtonSample.cs
+++ b/Samples/ButtonSample.cs
@@ -3,8 +3,10 @@ using Ooui;
namespace Samples
{
- public class ButtonSample
+ public class ButtonSample : ISample
{
+ public string Title => "Button that count clicks";
+
Button MakeButton ()
{
var button = new Button ("Click me!");
@@ -23,6 +25,11 @@ namespace Samples
UI.Publish ("/shared-button", b);
UI.Publish ("/button", MakeButton);
}
+
+ public Element CreateElement ()
+ {
+ return MakeButton ();
+ }
}
}
diff --git a/Samples/DrawSample.cs b/Samples/DrawSample.cs
index 1b54c79..e6db2bd 100644
--- a/Samples/DrawSample.cs
+++ b/Samples/DrawSample.cs
@@ -5,9 +5,16 @@ using Ooui;
namespace Samples
{
- public class DrawSample
+ public class DrawSample : ISample
{
+ public string Title => "Collaborative Drawing";
+
public void Publish ()
+ {
+ UI.Publish ("/draw", CreateElement ());
+ }
+
+ public Element CreateElement ()
{
var heading = new Heading ("Draw");
var subtitle = new Paragraph ("Click to draw a collaborative masterpiece");
@@ -41,9 +48,7 @@ namespace Samples
app.AppendChild (subtitle);
app.AppendChild (canvas);
app.AppendChild (clearbtn);
- UI.Publish ("/draw", app);
+ return app;
}
}
}
-
-
diff --git a/Samples/FilesSample.cs b/Samples/FilesSample.cs
index 4adecbb..d1bdfa8 100644
--- a/Samples/FilesSample.cs
+++ b/Samples/FilesSample.cs
@@ -6,24 +6,13 @@ using Ooui;
namespace Samples
{
- public class FilesSample
+ public class FilesSample : ISample
{
+ public string Title => "Upload files";
+
public void Publish ()
{
- var heading = new Heading ("Upload Files");
- var subtitle = new Paragraph ("Upload files to the app");
-
- var uploadForm = new Form ();
- uploadForm.Action = "/files/upload";
- uploadForm.Method = "POST";
- uploadForm.EncodingType = "multipart/form-data";
- uploadForm.AppendChild (new Input (InputType.File) { Name = "file" });
- uploadForm.AppendChild (new Input (InputType.Submit) { Value = "Upload" });
-
- var app = new Div ();
- app.AppendChild (heading);
- app.AppendChild (subtitle);
- app.AppendChild (uploadForm);
+ var app = CreateElement ();
UI.Publish ("/files", app);
@@ -133,5 +122,25 @@ namespace Samples
}
return -1;
}
- }
+
+ public Element CreateElement ()
+ {
+ var heading = new Heading ("Upload Files");
+ var subtitle = new Paragraph ("Upload files to the app");
+
+ var uploadForm = new Form ();
+ uploadForm.Action = "/files/upload";
+ uploadForm.Method = "POST";
+ uploadForm.EncodingType = "multipart/form-data";
+ uploadForm.AppendChild (new Input (InputType.File) { Name = "file" });
+ uploadForm.AppendChild (new Input (InputType.Submit) { Value = "Upload" });
+
+ var app = new Div ();
+ app.AppendChild (heading);
+ app.AppendChild (subtitle);
+ app.AppendChild (uploadForm);
+
+ return app;
+ }
+ }
}
diff --git a/Samples/ISample.cs b/Samples/ISample.cs
new file mode 100644
index 0000000..5f6e6ab
--- /dev/null
+++ b/Samples/ISample.cs
@@ -0,0 +1,11 @@
+using System;
+using Ooui;
+
+namespace Samples
+{
+ public interface ISample
+ {
+ string Title { get; }
+ Element CreateElement ();
+ }
+}
diff --git a/Samples/TodoSample.cs b/Samples/TodoSample.cs
index d560366..7f58ac7 100644
--- a/Samples/TodoSample.cs
+++ b/Samples/TodoSample.cs
@@ -5,8 +5,10 @@ using Ooui;
namespace Samples
{
- public class TodoSample
+ public class TodoSample : ISample
{
+ public string Title => "Global TODO list";
+
List items = new List () {
ClassName = "list-group",
};
@@ -106,6 +108,11 @@ namespace Samples
UI.Publish ("/todo", MakeTodo);
}
+
+ public Element CreateElement ()
+ {
+ return MakeTodo ();
+ }
}
}
diff --git a/Samples/XamarinFormsSample.cs b/Samples/XamarinFormsSample.cs
index a15a850..bb8b4f2 100644
--- a/Samples/XamarinFormsSample.cs
+++ b/Samples/XamarinFormsSample.cs
@@ -4,8 +4,10 @@ using Ooui.Forms;
namespace Samples
{
- public class XamarinFormsSample
+ public class XamarinFormsSample : ISample
{
+ public string Title => "Xamarin.Forms Button Counter";
+
Page MakePage ()
{
Forms.Init ();
@@ -46,5 +48,10 @@ namespace Samples
Ooui.UI.Publish ("/xamarin-forms", () => MakePage ().CreateElement ());
}
- }
+
+ public Ooui.Element CreateElement ()
+ {
+ return MakePage ().CreateElement ();
+ }
+ }
}