Skip to content

Commit

Permalink
Merge pull request #123 from digitallyinduced/laobiz/ch1606/fix-view-…
Browse files Browse the repository at this point in the history
…generator

Fixed and readded the view code generator
  • Loading branch information
mpscholten authored Jun 23, 2020
2 parents 8032499 + f0f4735 commit 1b47825
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
name: digitallyinduced
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: nix-shell ./NixSupport/shell.nix --run "runghc $(make -f lib/IHP/Makefile.dist print-ghc-extensions) Test/Main.hs
- run: nix-shell ./NixSupport/shell.nix --run "runghc $(make -f lib/IHP/Makefile.dist print-ghc-extensions) Test/Main.hs"
4 changes: 2 additions & 2 deletions IHP/IDE/CodeGen/Controller.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ instance Controller CodeGenController where

action CreateViewAction = do
let viewName = paramOrDefault "" "name"
let applicationName = paramOrDefault "" "Web"
let applicationName = "Web"
let controllerName = paramOrDefault "" "controllerName"
(Right plan) <- ViewGenerator.buildPlan viewName applicationName controllerName
executePlan plan
Expand Down Expand Up @@ -126,7 +126,7 @@ deleteTextFromFile filePath lineContent = do
addImport :: Text -> [Text] -> IO ()
addImport file importStatements = do
content :: Text <- Text.readFile (cs file)
case addImport' file importStatements of
case addImport' content importStatements of
Just newContent -> Text.writeFile (cs file) (cs newContent)
Nothing -> putStrLn ("Could not automatically add " <> tshow importStatements <> " to " <> file)
pure ()
Expand Down
2 changes: 1 addition & 1 deletion IHP/IDE/CodeGen/View/Generators.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ instance View GeneratorsView ViewContext where
<div class="generator-name">Action</div>
</div>

<a href="#" class="generator">
<a href={NewViewAction} class="generator">
<div class="generator-icon">{copyIcon}</div>
<div class="generator-name">View</div>
</a>
Expand Down
1 change: 1 addition & 0 deletions IHP/IDE/CodeGen/View/NewView.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ instance View NewViewView ViewContext where
<div class="object-name flex-grow-1">{controllerName}.{viewName}</div>

<input type="hidden" name="name" value={viewName}/>
<input type="hidden" name="controllerName" value={controllerName}/>

<button class="btn btn-primary" type="submit">Generate</button>
</form>
Expand Down
4 changes: 2 additions & 2 deletions IHP/IDE/CodeGen/ViewGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ buildPlan viewName applicationName controllerName =
-- E.g. qualifiedViewModuleName config "Edit" == "Web.View.Users.Edit"
qualifiedViewModuleName :: ViewConfig -> Text -> Text
qualifiedViewModuleName config viewName =
get #applicationName config <> ".View." <> Countable.pluralize (get #controllerName config) <> "." <> viewName
get #applicationName config <> ".View." <> get #controllerName config <> "." <> viewName

generateGenericView :: [Statement] -> ViewConfig -> [GeneratorAction]
generateGenericView schema config =
Expand Down Expand Up @@ -70,5 +70,5 @@ generateGenericView schema config =
in
[ EnsureDirectory { directory = get #applicationName config <> "/View/" <> controllerName }
, CreateFile { filePath = get #applicationName config <> "/View/" <> controllerName <> "/" <> name <> ".hs", fileContent = genericView }
, AddImport { filePath = get #applicationName config <> "/Controller/" <> controllerName <> ".hs", fileContent = qualifiedViewModuleName config name }
, AddImport { filePath = get #applicationName config <> "/Controller/" <> controllerName <> ".hs", fileContent = "import " <> qualifiedViewModuleName config name }
]
2 changes: 1 addition & 1 deletion Test/IDE/SchemaDesigner/ParserSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ tests = do
-- Catching empty Enums results in the "Create Enum" UI button being useless.
-- Thats why empty Enums will not throw errors.
it "should parse CREATE TYPE .. AS ENUM without values" do
evaluate (parseSql "CREATE TYPE colors AS ENUM ();") `shouldBe` CreateEnumType { name = "colors", values = [] }
parseSql "CREATE TYPE colors AS ENUM ();" `shouldBe` CreateEnumType { name = "colors", values = [] }

parseSql :: Text -> Statement
parseSql sql = let [statement] = parseSqlStatements sql in statement
Expand Down

0 comments on commit 1b47825

Please sign in to comment.