Initial development #1

Merged
danieljsummers merged 2 commits from initial-dev into main 2025-01-29 03:52:24 +00:00
7 changed files with 191 additions and 0 deletions
Showing only changes of commit 7e013f8225 - Show all commits

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
src/.idea
src/**/bin
src/**/obj

18
src/Directory.Build.props Normal file
View 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
View 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

View 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
View 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"

View 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
View File

@ -0,0 +1,2 @@
// For more information see https://aka.ms/fsharp-console-apps
printfn "Hello from F#"