{-# LANGUAGE NoImplicitPrelude #-} {-| Module : Headroom.Ext Description : Extended support for selected /file types/ Copyright : (c) 2019-2020 Vaclav Svejcar License : BSD-3-Clause Maintainer : vaclav.svejcar@gmail.com Stability : experimental Portability : POSIX /Headroom/ provides /extended support/ for selected /file types/, which mean not only basic management of /license headers/ based on /template files/ is provided, but also some additional functionality is available. For example, some extra data may be extracted from the processed /source code file/ and made available to template via /template variables/ (e.g. /module name/ for /Haskell source code files/). -} module Headroom.Ext ( extractVariables , extractTemplateMeta ) where import Headroom.Configuration.Types ( CtHeaderConfig ) import qualified Headroom.Ext.Haskell as Haskell import qualified Headroom.Ext.Java as Java import qualified Headroom.Ext.PureScript as PureScript import Headroom.FileType.Types ( FileType(..) ) import Headroom.Template ( Template(..) ) import Headroom.Types ( TemplateMeta(..) ) import Headroom.Variables.Types ( Variables(..) ) import RIO -- | Extracts variables specific to the file type (if supported), e.g. module -- name for /Haskell/ source code. Currently supported file types are: -- -- * /Haskell/ - implemented in "Headroom.Ext.Haskell" -- * /Java/ - implemented in "Headroom.Ext.Java" -- * /PureScript/ - implemented in "Headroom.Ext.PureScript" extractVariables :: FileType -- ^ type of the file -> CtHeaderConfig -- ^ license header configuration -> Maybe TemplateMeta -- ^ extracted metadata from corresponding /template/ -> Maybe (Int, Int) -- ^ license header position @(startLine, endLine)@ -> Text -- ^ text of the source code file -> Variables -- ^ extracted variables extractVariables :: FileType -> CtHeaderConfig -> Maybe TemplateMeta -> Maybe (Int, Int) -> Text -> Variables extractVariables FileType fileType = case FileType fileType of FileType Haskell -> CtHeaderConfig -> Maybe TemplateMeta -> Maybe (Int, Int) -> Text -> Variables Haskell.extractVariables FileType Java -> CtHeaderConfig -> Maybe TemplateMeta -> Maybe (Int, Int) -> Text -> Variables Java.extractVariables FileType PureScript -> CtHeaderConfig -> Maybe TemplateMeta -> Maybe (Int, Int) -> Text -> Variables PureScript.extractVariables FileType _ -> CtHeaderConfig -> Maybe TemplateMeta -> Maybe (Int, Int) -> Text -> Variables forall a. Monoid a => a mempty -- | Extracts medatata from given /template/ for selected /file type/, which -- might be later required by the 'extractVariables' function. extractTemplateMeta :: (Template t) => FileType -- ^ /file type/ for which this template will be used -> t -- ^ parsed /template/ -> Maybe TemplateMeta -- ^ extracted template metadata extractTemplateMeta :: FileType -> t -> Maybe TemplateMeta extractTemplateMeta FileType Haskell t tmpl = TemplateMeta -> Maybe TemplateMeta forall a. a -> Maybe a Just (TemplateMeta -> Maybe TemplateMeta) -> TemplateMeta -> Maybe TemplateMeta forall a b. (a -> b) -> a -> b $ t -> TemplateMeta forall t. Template t => t -> TemplateMeta Haskell.extractTemplateMeta t tmpl extractTemplateMeta FileType _ t _ = Maybe TemplateMeta forall a. Maybe a Nothing