packages feed

yesod-raml-docs (empty) → 0.1.0

raw patch · 6 files changed

+163/−0 lines, 6 filesdep +basedep +bytestringdep +containerssetup-changed

Dependencies added: base, bytestring, containers, shakespeare, template-haskell, text, yaml, yesod-markdown, yesod-raml

Files

+ ChangeLog.md view
@@ -0,0 +1,3 @@+## 0.1.0++* First Release
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2015 Junji Hashimoto++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ README.md view
@@ -0,0 +1,18 @@+# Yesod-Raml-Docs: ++Yesod-Raml-Docs makes a html-document from [RAML](http://raml.org/spec.html) File.++The template of html document uses Hamlet(Shakespeare).++Though the template is Hamlet, original template is numjucks of [raml2html](https://github.com/kevinrenskers/raml2html).+To convert numjucks to Hamlet, I used [html2hamlet](https://hackage.haskell.org/package/html2hamlet).++## Usage++```parseRamlDocsFile``` makes Html data type from RAML file.+Example is below.++```+getHelpR ::  Handler Html+getHelpR = return  $(parseRamlDocsFile "config/routes.raml")+```
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ Yesod/Raml/Docs.hs view
@@ -0,0 +1,84 @@+{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE OverloadedStrings #-}++module Yesod.Raml.Docs(+  htmlFromRaml+, parseRamlDocsFile+) where++import Yesod.Raml.Parser+import Yesod.Raml.Type+import Text.Hamlet+import Yesod.Markdown+import qualified Data.Map as M+import qualified Data.Text as T+import qualified Data.Yaml.Include as YI+import qualified Data.Yaml as Y+import Data.Monoid+import Language.Haskell.TH.Syntax++import qualified Paths_yesod_raml_docs as D+import Data.Version (showVersion)++yesodRamlDocsVersion :: String+yesodRamlDocsVersion = showVersion D.version++txt2md :: T.Text -> Html+txt2md txt = +  case (markdownToHtml (Markdown txt)) of+    Left msg -> error $ show msg+    Right md -> md++findAuth :: Auth -> Raml -> Maybe RamlSecuritySchemes+findAuth auth raml = M.lookup auth (foldr1 (<>) (securitySchemes raml))++haveMethodParam :: RamlMethod -> Bool+haveMethodParam method = not ((M.null (m_queryParameters method)) && (M.null (m_headers method)) && (M.null (m_body method)))++haveResourceParam :: RamlResource -> Bool+haveResourceParam resource = not ((M.null (r_uriParameters resource)) && (M.null (r_baseUriParameters resource)))++haveParam :: RamlResource -> RamlMethod -> Bool+haveParam resource method = haveMethodParam method || haveResourceParam resource++haveMethod :: RamlResource -> Bool+haveMethod resource = (not  (M.null (r_methods resource)))++scriptBody :: Html+scriptBody = $(shamletFile "templates/script.hamlet")++styleBody :: Html+styleBody = $(shamletFile "templates/style.hamlet")++htmlFromRaml :: Raml -> Html+htmlFromRaml raml = docs $ genUriParamDescription $ applyTrait $ applyResourceType $ applyVersion raml++docs :: Raml -> Html+docs raml = $(shamletFile "templates/docs.hamlet")++resources :: Raml -> RamlResource -> T.Text -> T.Text -> Html+resources raml res puri ruri = $(shamletFile "templates/resource.hamlet")++items :: T.Text -> RamlNamedParameters -> Html+items key item = $(shamletFile "templates/item.hamlet")++docId :: T.Text -> T.Text +docId uri =+    T.replace "{" "_"+  $ T.replace "}" "_"+  $ T.replace " " "_"+  $ T.replace "." "_"+  $ T.replace "/" "_" uri+++parseRamlDocsFile ::  FilePath -> Q Exp+parseRamlDocsFile file = do+  qAddDependentFile file+  raml <- qRunIO $ do+    eRaml <- YI.decodeFileEither file ::  IO (Either Y.ParseException Raml)+    case eRaml of+          Right v -> return  v+          Left e -> error $ "Invalid raml :" ++ show e+  [|htmlFromRaml raml|]+    
+ yesod-raml-docs.cabal view
@@ -0,0 +1,36 @@+name:                yesod-raml-docs+version:             0.1.0+synopsis:            A html documentation generator library for RAML.+description:         A html documentation generator library for RAML.+license:             MIT+license-file:        LICENSE+author:              junji.hashimoto+maintainer:          junji.hashimoto@gmail.com+category:            Web, Yesod+build-type:          Simple+cabal-version:       >=1.10+extra-source-files:   ChangeLog.md+                    , README.md++bug-reports:         https://github.com/junjihashimoto/yesod-raml/issues++source-repository head+  type:           git+  location:       https://github.com/junjihashimoto/yesod-raml.git++library+  exposed-modules:     Yesod.Raml.Docs+                     , Paths_yesod_raml_docs+  -- other-modules:       +  build-depends:       base ==4.*+                     , yesod-raml == 0.2.*+                     , yesod-markdown+                     , shakespeare+                     , containers+                     , text+                     , yaml+                     , bytestring+                     , template-haskell+  default-language:    Haskell2010+  ghc-options:       -Wall+