Skip to content

Commit

Permalink
refactor(report): provide toString function
Browse files Browse the repository at this point in the history
  • Loading branch information
deemp committed Mar 21, 2024
1 parent f375547 commit ba1519d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 3 additions & 4 deletions eo-phi-normalizer/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,14 @@ import Language.EO.Phi (Bytes (Bytes), Object (Formation), Program (Program), pa
import Language.EO.Phi.Dataize (dataizeRecursively, dataizeStep)
import Language.EO.Phi.Metrics as Metrics (ProgramMetrics (..), getProgramMetrics, splitPath)
import Language.EO.Phi.Report.Data as Report (ReportConfig (..), ReportItem (..), ReportPage (..), makeProgramReport, makeReport)
import Language.EO.Phi.Report.Html as Report (toHtmlReport)
import Language.EO.Phi.Report.Html as Report (toStringReport)
import Language.EO.Phi.Rules.Common (ApplicationLimits (ApplicationLimits), applyRulesChainWith, applyRulesWith, defaultContext, objectSize)
import Language.EO.Phi.Rules.Yaml (RuleSet (rules, title), convertRule, parseRuleSetFromFile)
import Options.Applicative hiding (metavar)
import Options.Applicative qualified as Optparse (metavar)
import System.Directory (createDirectoryIfMissing, doesFileExist)
import System.FilePath (takeDirectory, (</>))
import System.IO (IOMode (WriteMode), getContents', hFlush, hPutStr, hPutStrLn, openFile, stdout)
import Text.Blaze.Renderer.Text (renderMarkup)

data CLI'TransformPhi = CLI'TransformPhi
{ chain :: Bool
Expand Down Expand Up @@ -411,11 +410,11 @@ main = do
metricsPhiNormalized <- getMetrics item.bindingsPathPhiNormalized (Just item.phiNormalized)
pure $ makeProgramReport item metricsPhi metricsPhiNormalized
let report = makeReport programReports
reportHtml = toHtmlReport reportConfig report
reportString = toStringReport reportConfig report
pageHtmlPath = reportConfig.reportPage.directory </> reportConfig.reportPage.html

createDirectoryIfMissing True (takeDirectory pageHtmlPath)
writeFile (reportConfig.reportPage.directory </> reportConfig.reportPage.html) (unpack $ renderMarkup reportHtml)
writeFile (reportConfig.reportPage.directory </> reportConfig.reportPage.html) reportString

forM_ reportConfig.reportJson $ \path -> do
createDirectoryIfMissing True (takeDirectory path)
Expand Down
4 changes: 4 additions & 0 deletions eo-phi-normalizer/src/Language/EO/Phi/Report/Html.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Data.List (intercalate)
import Data.Maybe (fromMaybe)
import Language.EO.Phi.Metrics (Metrics (..), MetricsCount, nan)
import Language.EO.Phi.Report.Data
import Text.Blaze.Html.Renderer.String (renderHtml)
import Text.Blaze.Html5
import Text.Blaze.Html5.Attributes
import Prelude hiding (div, id, span)
Expand Down Expand Up @@ -125,3 +126,6 @@ toHtmlReport reportConfig report =
, link ! href (toValue reportConfig.reportPage.css) ! rel "stylesheet"
, script ! src (toValue reportConfig.reportPage.js) $ ""
]

toStringReport :: ReportConfig -> Report -> String
toStringReport reportConfig report = renderHtml $ toHtmlReport reportConfig report

0 comments on commit ba1519d

Please sign in to comment.