Initial development #1
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
src/.idea
|
||||
src/**/bin
|
||||
src/**/obj
|
18
src/Directory.Build.props
Normal file
18
src/Directory.Build.props
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
|
||||
<VersionPrefix>0.2.2</VersionPrefix>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PackageReleaseNotes>Initial version</PackageReleaseNotes>
|
||||
<Authors>danieljsummers</Authors>
|
||||
<Company>Bit Badger Solutions</Company>
|
||||
<PackageProjectUrl>https://git.bitbadger.solutions/bit-badger/Giraffe.Fixi</PackageProjectUrl>
|
||||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
|
||||
<RepositoryUrl>https://git.bitbadger.solutions/bit-badger/Giraffe.Fixi</RepositoryUrl>
|
||||
<RepositoryType>Git</RepositoryType>
|
||||
<Copyright>MIT License</Copyright>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<PackageTags>Giraffe fixi</PackageTags>
|
||||
</PropertyGroup>
|
||||
</Project>
|
28
src/Giraffe.Fixi.sln
Normal file
28
src/Giraffe.Fixi.sln
Normal file
@ -0,0 +1,28 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.31903.59
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Giraffe.Fixi", "Library\Giraffe.Fixi.fsproj", "{E450411F-C6F9-4373-B9B3-9788CBA3CA36}"
|
||||
EndProject
|
||||
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Giraffe.Fixi.Tests", "Tests\Giraffe.Fixi.Tests.fsproj", "{4C327E9B-3340-4608-8444-05770274285C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{E450411F-C6F9-4373-B9B3-9788CBA3CA36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E450411F-C6F9-4373-B9B3-9788CBA3CA36}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E450411F-C6F9-4373-B9B3-9788CBA3CA36}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E450411F-C6F9-4373-B9B3-9788CBA3CA36}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4C327E9B-3340-4608-8444-05770274285C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4C327E9B-3340-4608-8444-05770274285C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4C327E9B-3340-4608-8444-05770274285C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4C327E9B-3340-4608-8444-05770274285C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
12
src/Library/Giraffe.Fixi.fsproj
Normal file
12
src/Library/Giraffe.Fixi.fsproj
Normal file
@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="Library.fs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Giraffe" Version="7.0.2" />
|
||||
<PackageReference Include="Giraffe.ViewEngine" Version="1.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
116
src/Library/Library.fs
Normal file
116
src/Library/Library.fs
Normal file
@ -0,0 +1,116 @@
|
||||
namespace Giraffe.Fixi
|
||||
|
||||
open Microsoft.AspNetCore.Http
|
||||
open Microsoft.Extensions.Primitives
|
||||
|
||||
/// Module to hold extensions
|
||||
[<AutoOpen>]
|
||||
module Extensions =
|
||||
|
||||
/// Extensions to the header dictionary
|
||||
type IHeaderDictionary with
|
||||
|
||||
/// <summary>Indicates that the request was generated from fixi</summary>
|
||||
member this.FxRequest
|
||||
with get () = not (this["FX-Request"] = StringValues.Empty)
|
||||
|
||||
/// <summary>Valid values for the <c>fx-swap</c> attribute</summary>
|
||||
type FxSwap =
|
||||
|
||||
/// <summary>Replace the entire target element with the response (the default)</summary>
|
||||
| OuterHtml
|
||||
|
||||
/// <summary>Replace the inner HTML of the target element</summary>
|
||||
| InnerHtml
|
||||
|
||||
/// <summary>Insert the response before the target element</summary>
|
||||
| BeforeBegin
|
||||
|
||||
/// <summary>Insert the response before the first child of the target element</summary>
|
||||
| AfterBegin
|
||||
|
||||
/// <summary>Insert the response after the last child of the target element</summary>
|
||||
| BeforeEnd
|
||||
|
||||
/// <summary>Insert the response after the target element</summary>
|
||||
| AfterEnd
|
||||
|
||||
override this.ToString() =
|
||||
match this with
|
||||
| OuterHtml -> "outerHTML"
|
||||
| InnerHtml -> "innerHTML"
|
||||
| BeforeBegin -> "beforebegin"
|
||||
| AfterBegin -> "afterbegin"
|
||||
| BeforeEnd -> "beforeend"
|
||||
| AfterEnd -> "afterend"
|
||||
|
||||
|
||||
open Giraffe.ViewEngine
|
||||
|
||||
/// <summary>Attributes and flags for fixi</summary>
|
||||
[<AutoOpen>]
|
||||
module FixiAttrs =
|
||||
|
||||
/// <summary>Issue a request to the given URL</summary>
|
||||
/// <param name="url">The URL to which the request should be issued</param>
|
||||
/// <returns>A configured <c>fx-action</c> attribute</returns>
|
||||
let _fxAction url =
|
||||
attr "fx-action" url
|
||||
|
||||
/// <summary>Exclude this element (and below) from fixi's behavior</summary>
|
||||
let _fxIgnore =
|
||||
flag "fx-ignore"
|
||||
|
||||
/// <summary>Specify the HTTP method for the fixi request</summary>
|
||||
/// <param name="it">The HTTP method to use for the request</param>
|
||||
/// <returns>A configured <c>fx-method</c> attribute</returns>
|
||||
/// <remarks>Consider <c>_fxGet</c>, <c>_fxPost</c>, etc.</remarks>
|
||||
let _fxMethod (it: string) =
|
||||
attr "fx-method" (it.ToUpperInvariant())
|
||||
|
||||
/// <summary>Specify the swap strategy</summary>
|
||||
/// <param name="swap">The swap strategy to use</param>
|
||||
/// <returns>A configured <c>fx-swap</c> attribute</returns>
|
||||
let _fxSwap (swap: FxSwap) =
|
||||
attr "fx-swap" (string swap)
|
||||
|
||||
/// <summary>Specify the target for the swap</summary>
|
||||
/// <param name="selector">The CSS selector for the swap target</param>
|
||||
/// <returns>A configured <c>fx-target</c> attribute</returns>
|
||||
let _fxTarget selector =
|
||||
attr "fx-target" selector
|
||||
|
||||
/// <summary>The event which should trigger this request</summary>
|
||||
/// <param name="event">The name of the event</param>
|
||||
/// <returns>A configured <c>fx-trigger</c> attribute</returns>
|
||||
/// <remarks>The event should not start with "on"; use "click", not "onclick"</remarks>
|
||||
let _fxTrigger event =
|
||||
attr "fx-trigger" event
|
||||
|
||||
/// <summary>Canned <c>fx-method</c> attributes for common HTTP methods</summary>
|
||||
[<AutoOpen>]
|
||||
module FixiMethods =
|
||||
|
||||
/// <summary>An <c>fx-method="DELETE"</c> attribute</summary>
|
||||
let _fxDelete =
|
||||
_fxMethod "DELETE"
|
||||
|
||||
/// <summary>An <c>fx-method="HEAD"</c> attribute</summary>
|
||||
let _fxHead =
|
||||
_fxMethod "HEAD"
|
||||
|
||||
/// <summary>An <c>fx-method="GET"</c> attribute</summary>
|
||||
let _fxGet =
|
||||
_fxMethod "GET"
|
||||
|
||||
/// <summary>An <c>fx-method="PATCH"</c> attribute</summary>
|
||||
let _fxPatch =
|
||||
_fxMethod "PATCH"
|
||||
|
||||
/// <summary>An <c>fx-method="POST"</c> attribute</summary>
|
||||
let _fxPost =
|
||||
_fxMethod "POST"
|
||||
|
||||
/// <summary>An <c>fx-method="PUT"</c> attribute</summary>
|
||||
let _fxPut =
|
||||
_fxMethod "PUT"
|
12
src/Tests/Giraffe.Fixi.Tests.fsproj
Normal file
12
src/Tests/Giraffe.Fixi.Tests.fsproj
Normal file
@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.fs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
2
src/Tests/Program.fs
Normal file
2
src/Tests/Program.fs
Normal file
@ -0,0 +1,2 @@
|
||||
// For more information see https://aka.ms/fsharp-console-apps
|
||||
printfn "Hello from F#"
|
Loading…
x
Reference in New Issue
Block a user