Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from elm-land/layouts
Feature: Layouts
- Loading branch information
Showing
18 changed files
with
553 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
module Commands.AddLayout exposing (run) | ||
|
||
import CodeGen | ||
import CodeGen.Annotation | ||
import CodeGen.Argument | ||
import CodeGen.Declaration | ||
import CodeGen.Expression | ||
import CodeGen.Import | ||
import CodeGen.Module | ||
import Json.Decode | ||
|
||
|
||
run : Json.Decode.Value -> List CodeGen.Module | ||
run json = | ||
case Json.Decode.decodeValue decoder json of | ||
Ok data -> | ||
[ newLayoutModule data ] | ||
|
||
Err _ -> | ||
[] | ||
|
||
|
||
|
||
-- DATA | ||
|
||
|
||
type alias Data = | ||
{ name : String | ||
} | ||
|
||
|
||
decoder : Json.Decode.Decoder Data | ||
decoder = | ||
Json.Decode.map Data | ||
(Json.Decode.field "name" Json.Decode.string) | ||
|
||
|
||
|
||
-- CODEGEN | ||
|
||
|
||
{-| | ||
module Layouts.Sidebar exposing (layout) | ||
import Html exposing (Html) | ||
import Html.Attributes as Attr | ||
layout : { page : Html msg } -> Html msg | ||
layout { page } = | ||
Html.div | ||
[ Attr.class "layout" ] | ||
[ page ] | ||
-} | ||
newLayoutModule : Data -> CodeGen.Module | ||
newLayoutModule data = | ||
CodeGen.Module.new | ||
{ name = [ "Layouts", data.name ] | ||
, exposing_ = [ "layout" ] | ||
, imports = | ||
[ CodeGen.Import.new [ "Html" ] | ||
|> CodeGen.Import.withExposing [ "Html" ] | ||
, CodeGen.Import.new [ "Html", "Attributes" ] | ||
|> CodeGen.Import.withAlias "Attr" | ||
] | ||
, declarations = | ||
[ CodeGen.Declaration.function | ||
{ name = "layout" | ||
, annotation = | ||
CodeGen.Annotation.function | ||
[ CodeGen.Annotation.record | ||
[ ( "page", CodeGen.Annotation.type_ "Html msg" ) | ||
] | ||
, CodeGen.Annotation.type_ "Html msg" | ||
] | ||
, arguments = [ CodeGen.Argument.new "{ page }" ] | ||
, expression = | ||
CodeGen.Expression.multilineFunction | ||
{ name = "Html.div" | ||
, arguments = | ||
[ CodeGen.Expression.list | ||
[ CodeGen.Expression.function | ||
{ name = "Attr.class" | ||
, arguments = [ CodeGen.Expression.string "layout" ] | ||
} | ||
] | ||
, CodeGen.Expression.list | ||
[ CodeGen.Expression.value "page" | ||
] | ||
] | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.