Skip to content

Commit

Permalink
fix too many quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
hanjoosten committed Jul 4, 2024
1 parent 17bc7b7 commit 8b5dd90
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 80 deletions.
80 changes: 37 additions & 43 deletions src/Ampersand/Prototype/GenAngularFrontend.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,8 @@ import RIO.Char (toLower, toUpper)
import qualified RIO.Text as T
import qualified RIO.Text.Partial as Partial (splitOn)
import System.FilePath
import Text.StringTemplate
( StringTemplate,
Stringable,
)
import qualified Text.StringTemplate as ST (setAttribute)

setAttribute :: (Stringable a) => String -> Text -> StringTemplate a -> StringTemplate a
setAttribute = ST.setAttribute
import Text.StringTemplate (StringTemplate, setAttribute)
import Text.StringTemplate.GenericStandard ()

crudsToString :: Cruds -> Text
crudsToString x = T.pack $ zipWith (curry f) [crudC x, crudR x, crudU x, crudD x] "crud"
Expand Down Expand Up @@ -79,28 +73,28 @@ genComponentFileFromTemplate fSpec interf templateFunction templateFilePath targ
. T.lines
. renderTemplate Nothing template
$ setAttribute "contextName" (addSlashes . fullName $ fSpec)
. setAttribute "isSessionInterface" (tshow . isSessionInterface $ interf)
. ST.setAttribute "roles" (map show . feiRoles $ interf) -- show string, since StringTemplate does not elegantly allow to quote and separate
. setAttribute "isSessionInterface" (isSessionInterface interf)
. setAttribute "roles" (map show . feiRoles $ interf) -- show string, since StringTemplate does not elegantly allow to quote and separate
. setAttribute "ampersandVersionStr" (longVersion appVersion)
. setAttribute "ifcName" (ifcName interf)
. setAttribute "ifcNamePascal" (ifcNamePascal interf)
. setAttribute "ifcNameKebab" (ifcNameKebab interf)
. setAttribute "ifcLabel" (ifcLabel interf) -- no escaping for labels in templates needed
. setAttribute "expAdl" (showA . toExpr . ifcExp $ interf)
. setAttribute "exprIsUni" (tshow . exprIsUni . feiObj $ interf)
. setAttribute "exprIsTot" (tshow . exprIsTot . feiObj $ interf)
. setAttribute "source" (tshow . idWithoutType' . source . ifcExp $ interf)
. setAttribute "target" (tshow . idWithoutType' . target . ifcExp $ interf)
. setAttribute "crudC" (tshow . objCrudC . feiObj $ interf)
. setAttribute "crudR" (tshow . objCrudR . feiObj $ interf)
. setAttribute "crudU" (tshow . objCrudU . feiObj $ interf)
. setAttribute "crudD" (tshow . objCrudD . feiObj $ interf)
. setAttribute "exprIsUni" (exprIsUni . feiObj $ interf)
. setAttribute "exprIsTot" (exprIsTot . feiObj $ interf)
. setAttribute "source" (text1ToText . idWithoutType' . source . ifcExp $ interf)
. setAttribute "target" (text1ToText . idWithoutType' . target . ifcExp $ interf)
. setAttribute "crudC" (objCrudC . feiObj $ interf)
. setAttribute "crudR" (objCrudR . feiObj $ interf)
. setAttribute "crudU" (objCrudU . feiObj $ interf)
. setAttribute "crudD" (objCrudD . feiObj $ interf)
. setAttribute "crud" (crudsToString . objCrud . feiObj $ interf)
. setAttribute "contents" lns
. setAttribute "verbose" (tshow $ loglevel' == LevelDebug)
. setAttribute "verbose" (loglevel' == LevelDebug)
. setAttribute "loglevel" (tshow loglevel')
. setAttribute "templateFilePath" (T.pack templateFilePath)
. setAttribute "targetFilePath" (T.pack targetFilePath)
. setAttribute "templateFilePath" templateFilePath
. setAttribute "targetFilePath" targetFilePath
writePrototypeAppFile targetFilePath contents

genSingleFileFromTemplate :: (HasRunner env, HasDirPrototype env) => FSpec -> FESpec -> FilePath -> FilePath -> RIO env ()
Expand All @@ -113,32 +107,32 @@ genSingleFileFromTemplate fSpec feSpec templateFilePath targetFilePath = do
renderTemplate Nothing template
$ setAttribute "contextName" (fullName fSpec)
. setAttribute "ampersandVersionStr" (longVersion appVersion)
. ST.setAttribute "ifcs" (interfaces feSpec) -- all interfaces
. ST.setAttribute "uis" (filter (not . isApi) $ interfaces feSpec) -- only the interfaces that need UI
. ST.setAttribute "apis" (filter isApi $ interfaces feSpec) -- only the interfaces that have API (no UI)
. ST.setAttribute "concepts" (concepts feSpec)
. ST.setAttribute "views" (views feSpec)
. setAttribute "verbose" (tshow $ loglevel' == LevelDebug)
. setAttribute "loglevel" (tshow loglevel')
. setAttribute "templateFilePath" (T.pack templateFilePath)
. setAttribute "targetFilePath" (T.pack targetFilePath)
. setAttribute "ifcs" (interfaces feSpec) -- all interfaces
. setAttribute "uis" (filter (not . isApi) $ interfaces feSpec) -- only the interfaces that need UI
. setAttribute "apis" (filter isApi $ interfaces feSpec) -- only the interfaces that have API (no UI)
. setAttribute "concepts" (concepts feSpec)
. setAttribute "views" (views feSpec)
. setAttribute "verbose" (loglevel' == LevelDebug)
. setAttribute "loglevel" (show loglevel')
. setAttribute "templateFilePath" templateFilePath
. setAttribute "targetFilePath" targetFilePath
writePrototypeAppFile targetFilePath contents

objectAttributes :: FEObject -> LogLevel -> StringTemplate String -> StringTemplate String
objectAttributes obj loglevel =
setAttribute "exprIsUni" (tshow . exprIsUni $ obj)
. setAttribute "exprIsTot" (tshow . exprIsTot $ obj)
setAttribute "exprIsUni" (exprIsUni obj)
. setAttribute "exprIsTot" (exprIsTot obj)
. setAttribute "name" (escapeIdentifier' . objName $ obj)
. setAttribute "label" (objName obj) -- no escaping for labels in templates needed
. setAttribute "expAdl" (showA . toExpr . objExp $ obj)
. setAttribute "source" (tshow . idWithoutType' . source . objExp $ obj)
. setAttribute "target" (tshow . idWithoutType' . target . objExp $ obj)
. setAttribute "crudC" (tshow . objCrudC $ obj)
. setAttribute "crudR" (tshow . objCrudR $ obj)
. setAttribute "crudU" (tshow . objCrudU $ obj)
. setAttribute "crudD" (tshow . objCrudD $ obj)
. setAttribute "source" (text1ToText . idWithoutType' . source . objExp $ obj)
. setAttribute "target" (text1ToText . idWithoutType' . target . objExp $ obj)
. setAttribute "crudC" (objCrudC obj)
. setAttribute "crudR" (objCrudR obj)
. setAttribute "crudU" (objCrudU obj)
. setAttribute "crudD" (objCrudD obj)
. setAttribute "crud" (crudsToString . objCrud $ obj)
. setAttribute "verbose" (tshow $ loglevel == LevelDebug)
. setAttribute "verbose" (loglevel == LevelDebug)
. setAttribute "loglevel" (tshow loglevel)

escapeIdentifier' :: Text -> Text
Expand Down Expand Up @@ -204,8 +198,8 @@ genHTMLView fSpec depth obj =
. indentSubStructure
. renderTemplate (Just . btKeys $ header) parentTemplate
$ objectAttributes obj (logLevel runner)
. setAttribute "isRoot" (tshow $ depth == 0)
. ST.setAttribute "subObjects" subObjAttrs
. setAttribute "isRoot" (depth == 0)
. setAttribute "subObjects" subObjAttrs
FEObjT {} -> pure $ "<span>" <> objTxt obj <> "</span>"
where
getTemplateForObject ::
Expand Down Expand Up @@ -277,8 +271,8 @@ genTypescriptInterface fSpec depth obj =
. indentSubStructure
. renderTemplate (Just . btKeys $ header) boxTemplate
$ objectAttributes obj (logLevel runner)
. setAttribute "isRoot" (tshow $ depth == 0)
. ST.setAttribute "subObjects" subObjAttrs
. setAttribute "isRoot" (depth == 0)
. setAttribute "subObjects" subObjAttrs
FEObjT {} -> pure $ "'" <> objTxt obj <> "'"
where
tgtCpt = target . objExp $ obj
Expand Down
71 changes: 34 additions & 37 deletions src/Ampersand/Prototype/GenAngularJSFrontend.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@ import qualified RIO.Text as T
import System.FilePath
import Text.StringTemplate
( StringTemplate,
Stringable,
setAttribute,
)
import qualified Text.StringTemplate as ST (setAttribute)

setAttribute :: (Stringable a) => String -> Text -> StringTemplate a -> StringTemplate a
setAttribute = ST.setAttribute
import Text.StringTemplate.GenericStandard ()

-- For useful info on the template language, see
-- https://theantlrguy.atlassian.net/wiki/spaces/ST/pages/1409038/StringTemplate+cheat+sheet
Expand All @@ -51,9 +48,9 @@ genRouteProvider fSpec ifcs = do
renderTemplate Nothing template
$ setAttribute "contextName" (fullName fSpec)
. setAttribute "ampersandVersionStr" (longVersion appVersion)
. ST.setAttribute "ifcs" ifcs
. ST.setAttribute "verbose" (loglevel' == LevelDebug)
. ST.setAttribute "loglevel" (show loglevel')
. setAttribute "ifcs" ifcs
. setAttribute "verbose" (loglevel' == LevelDebug)
. setAttribute "loglevel" (show loglevel')
mapM_ (logDebug . display) $ "Generated template: " : (map (" " <>) . T.lines $ contents)
writePrototypeAppFile "routeProvider.config.js" contents
logDebug "Finish genRouteProvider."
Expand Down Expand Up @@ -82,20 +79,20 @@ genViewInterface fSpec interf = do
let contents =
renderTemplate Nothing template
$ setAttribute "contextName" (addSlashes . fullName $ fSpec)
. setAttribute "isTopLevel" (tshow . isTopLevel . source . ifcExp $ interf)
. setAttribute "roles" (tshow . feiRoles $ interf) -- show string, since StringTemplate does not elegantly allow to quote and separate
. setAttribute "isTopLevel" (isTopLevel . source . ifcExp $ interf)
. setAttribute "roles" (map tshow . feiRoles $ interf) -- show string, since StringTemplate does not elegantly allow to quote and separate
. setAttribute "ampersandVersionStr" (longVersion appVersion)
. setAttribute "interfaceName" (ifcName interf)
. setAttribute "interfaceLabel" (ifcLabel interf) -- no escaping for labels in templates needed
. setAttribute "expAdl" (showA . toExpr . ifcExp $ interf)
. setAttribute "source" (text1ToText . idWithoutType' . source . ifcExp $ interf)
. setAttribute "target" (text1ToText . idWithoutType' . target . ifcExp $ interf)
. setAttribute "crudC" (tshow . objCrudC . feiObj $ interf)
. setAttribute "crudR" (tshow . objCrudR . feiObj $ interf)
. setAttribute "crudU" (tshow . objCrudU . feiObj $ interf)
. setAttribute "crudD" (tshow . objCrudD . feiObj $ interf)
. setAttribute "crudC" (objCrudC . feiObj $ interf)
. setAttribute "crudR" (objCrudR . feiObj $ interf)
. setAttribute "crudU" (objCrudU . feiObj $ interf)
. setAttribute "crudD" (objCrudD . feiObj $ interf)
. setAttribute "contents" (T.intercalate "\n" lns) -- intercalate, because unlines introduces a trailing \n
. setAttribute "verbose" (tshow $ loglevel' == LevelDebug)
. setAttribute "verbose" (loglevel' == LevelDebug)
. setAttribute "loglevel" (tshow loglevel')
let filename :: FilePath
filename = "ifc" <> (T.unpack . ifcName $ interf) <> ".view.html"
Expand Down Expand Up @@ -123,8 +120,8 @@ genViewObject fSpec depth obj =
let loglevel' = logLevel runner
let atomicAndBoxAttrs :: StringTemplate String -> StringTemplate String
atomicAndBoxAttrs =
setAttribute "exprIsUni" (tshow . exprIsUni $ obj)
. setAttribute "exprIsTot" (tshow . exprIsTot $ obj)
setAttribute "exprIsUni" (exprIsUni obj)
. setAttribute "exprIsTot" (exprIsTot obj)
. setAttribute
"name"
( case T.uncons . objName $ obj of
Expand All @@ -133,13 +130,13 @@ genViewObject fSpec depth obj =
)
. setAttribute "label" (objName obj) -- no escaping for labels in templates needed
. setAttribute "expAdl" (showA . toExpr . objExp $ obj)
. setAttribute "source" (tshow . idWithoutType' . source . objExp $ obj)
. setAttribute "target" (tshow . idWithoutType' . target . objExp $ obj)
. setAttribute "crudC" (tshow . objCrudC $ obj)
. setAttribute "crudR" (tshow . objCrudR $ obj)
. setAttribute "crudU" (tshow . objCrudU $ obj)
. setAttribute "crudD" (tshow . objCrudD $ obj)
. setAttribute "verbose" (tshow $ loglevel' == LevelDebug)
. setAttribute "source" (text1ToText . idWithoutType' . source . objExp $ obj)
. setAttribute "target" (text1ToText . idWithoutType' . target . objExp $ obj)
. setAttribute "crudC" (objCrudC obj)
. setAttribute "crudR" (objCrudR obj)
. setAttribute "crudU" (objCrudU obj)
. setAttribute "crudD" (objCrudD obj)
. setAttribute "verbose" (loglevel' == LevelDebug)
. setAttribute "loglevel" (tshow loglevel')
case atomicOrBox obj of
FEAtomic {} -> do
Expand Down Expand Up @@ -173,8 +170,8 @@ genViewObject fSpec depth obj =
. T.lines
. renderTemplate (Just . btKeys $ header) parentTemplate
$ atomicAndBoxAttrs
. setAttribute "isRoot" (tshow $ depth == 0)
. ST.setAttribute "subObjects" subObjAttrs
. setAttribute "isRoot" (depth == 0)
. setAttribute "subObjects" subObjAttrs
FEObjT {} -> pure []
where
indentation :: [Text] -> [Text]
Expand Down Expand Up @@ -243,21 +240,21 @@ genControllerInterface fSpec interf = do
let contents =
renderTemplate Nothing template
$ setAttribute "contextName" (fullName fSpec)
. setAttribute "isRoot" (tshow . isTopLevel . source . ifcExp $ interf)
. setAttribute "roles" (tshow . feiRoles $ interf) -- show string, since StringTemplate does not elegantly allow to quote and separate
. setAttribute "isRoot" (isTopLevel . source . ifcExp $ interf)
. setAttribute "roles" (feiRoles interf) -- show string, since StringTemplate does not elegantly allow to quote and separate
. setAttribute "ampersandVersionStr" (longVersion appVersion)
. setAttribute "interfaceName" (ifcName interf)
. setAttribute "interfaceLabel" (ifcLabel interf) -- no escaping for labels in templates needed
. setAttribute "expAdl" (showA . toExpr . ifcExp $ interf)
. setAttribute "exprIsUni" (tshow . exprIsUni . feiObj $ interf)
. setAttribute "source" (tshow . idWithoutType' . source . ifcExp $ interf)
. setAttribute "target" (tshow . idWithoutType' . target . ifcExp $ interf)
. setAttribute "crudC" (tshow . objCrudC . feiObj $ interf)
. setAttribute "crudR" (tshow . objCrudR . feiObj $ interf)
. setAttribute "crudU" (tshow . objCrudU . feiObj $ interf)
. setAttribute "crudD" (tshow . objCrudD . feiObj $ interf)
. setAttribute "verbose" (tshow $ loglevel' == LevelDebug)
. setAttribute "exprIsUni" (exprIsUni . feiObj $ interf)
. setAttribute "source" (text1ToText . idWithoutType' . source . ifcExp $ interf)
. setAttribute "target" (text1ToText . idWithoutType' . target . ifcExp $ interf)
. setAttribute "crudC" (objCrudC . feiObj $ interf)
. setAttribute "crudR" (objCrudR . feiObj $ interf)
. setAttribute "crudU" (objCrudU . feiObj $ interf)
. setAttribute "crudD" (objCrudD . feiObj $ interf)
. setAttribute "verbose" (loglevel' == LevelDebug)
. setAttribute "loglevel" (tshow loglevel')
. setAttribute "usedTemplate" (T.pack controlerTemplateName)
. setAttribute "usedTemplate" controlerTemplateName
let filename = "ifc" <> T.unpack (ifcName interf) <> ".controller.js"
writePrototypeAppFile filename contents

0 comments on commit 8b5dd90

Please sign in to comment.