Skip to content

Commit 4dc97d8

Browse files
authored
Merge pull request #294 from dahlia/docs
Build the nirum.org website using docs target
2 parents a43539f + 7dcd1bb commit 4dc97d8

File tree

10 files changed

+260
-63
lines changed

10 files changed

+260
-63
lines changed

.travis.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ script:
126126
- 'TOX="$(python3 -m site --user-base)/bin/tox" stack --no-terminal test -j4 --coverage'
127127
- ./lint.sh
128128

129+
# Build website
130+
- stack runhaskell ./app/nirum-docs.hs /tmp/nirum.org/
131+
129132
after_script:
130133
- |
131134
# Since codecov-haskell doesn't work on Windows,
@@ -142,6 +145,11 @@ after_script:
142145
--token="$(echo $token_encoded | python -m base64 -d)" \
143146
spec
144147
148+
# Used for making a commit into gh-pages (nirum.org website)
149+
- git log -n1 --format="format:%s%n%n$TRAVIS_COMMIT_RANGE" > /tmp/git-commit
150+
- git log -n1 --format="format:%an" > /tmp/git-author
151+
- git log -n1 --format="format:%ae" > /tmp/git-author-email
152+
145153
notifications:
146154
webhooks:
147155
urls:
@@ -235,3 +243,20 @@ after_deploy: |
235243
python -c 'import json, os; print(json.dumps({"username": os.environ["HACKAGE_USERNAME"], "password": os.environ["HACKAGE_PASSWORD"]}))' > ~/.stack/upload/credentials.json
236244
stack --no-terminal upload --ignore-check --no-signature .
237245
fi
246+
247+
# Upload website to nirum.org
248+
echo "$NIRUM_GH_PAGES_KEY" | tr / '\n' > /tmp/nirum_org_ed25519
249+
chmod 600 /tmp/nirum_org_ed25519
250+
eval "$(ssh-agent -s)"
251+
ssh-add /tmp/nirum_org_ed25519
252+
pushd /tmp/nirum.org/
253+
git init
254+
git config user.name "$(cat /tmp/git-author)"
255+
git config user.email "$(cat /tmp/git-author-email)"
256+
echo nirum.org > CNAME
257+
touch .nojekyll
258+
git add .
259+
git commit -a -F /tmp/git-commit
260+
git push -f [email protected]:nirum-lang/nirum-lang.github.io.git master
261+
popd
262+
rm /tmp/nirum_org_ed25519

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ To be released.
2020
- [CommonMark] in docstrings became to have a limited subset of
2121
[special attributes extension]. It's only allowed to heading elements and
2222
only anchor identifiers are supported (e.g., `{#header-id}`).
23+
- `style`, `header`, and `footer` options were added. These options purpose
24+
to customize the look and feel of the result pages.
2325
- Fixed an incorrect processing of [CommonMark] thight list items: it had
2426
crashed when a thight list item contains blocks other than paragraphs.
2527

app/nirum-docs.hs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env stack runghc
2+
{-# LANGUAGE OverloadedLists #-}
3+
{-# LANGUAGE OverloadedStrings #-}
4+
{-# LANGUAGE QuasiQuotes #-}
5+
import Control.Monad
6+
import Data.List (isPrefixOf)
7+
import System.Environment
8+
9+
import Data.Map.Strict
10+
import Data.Set
11+
import Data.Text hiding (isPrefixOf)
12+
import System.FilePath (pathSeparator)
13+
import Text.InterpolatedString.Perl6 (q)
14+
15+
import Nirum.Cli (writeFiles)
16+
import Nirum.Constructs.Module
17+
import Nirum.Package
18+
import Nirum.Targets
19+
import Nirum.Targets.Docs (Docs (..))
20+
import Nirum.Package.Metadata
21+
import Nirum.Package.ModuleSet
22+
import qualified Nirum.Version
23+
24+
packageMetadata :: Metadata Docs
25+
packageMetadata = Metadata
26+
{ version = Nirum.Version.version
27+
, description = Just
28+
"IDL compiler and RPC/distributed object framework for microservices"
29+
, license = Just "GPL-3"
30+
, keywords = ["IDL", "microservices", "SOA", "RPC"]
31+
, authors = [Author "Nirum team" Nothing Nothing]
32+
, Nirum.Package.Metadata.target = Docs
33+
{ docsTitle = "Nirum"
34+
, docsStyle = style
35+
, docsHeader = ""
36+
, docsFooter = footer
37+
}
38+
}
39+
40+
loadPackage :: FilePath -> IO (Either (Set ImportError) (Package Docs))
41+
loadPackage path = do
42+
documents <- filterWithKey ignores <$> scanDocuments path
43+
return $ case fromMap [(coreModulePath, coreModule)] of
44+
Left importErrors -> Left importErrors
45+
Right ms -> Right $ Package packageMetadata ms documents
46+
where
47+
ignores :: FilePath -> d -> Bool
48+
ignores filePath _ =
49+
not $ ("examples" ++ [pathSeparator]) `isPrefixOf` filePath
50+
51+
main :: IO ()
52+
main = do
53+
args <- getArgs
54+
outputDir <- case args of
55+
o : _ -> return o
56+
[] -> fail "missing output path"
57+
packageR <- loadPackage "."
58+
package <- case packageR of
59+
Left errors -> fail (show errors)
60+
Right p -> return p
61+
case buildPackage package of
62+
Right buildResult -> writeFiles outputDir buildResult
63+
Left e -> print e
64+
65+
style :: Text
66+
style = [q|
67+
.github-corner:hover .octo-arm {
68+
animation: octocat-wave 560ms ease-in-out;
69+
}
70+
@keyframes octocat-wave {
71+
0%, 100% { transform:rotate(0) }
72+
20%, 60% { transform:rotate(-25deg) }
73+
40%, 80% { transform:rotate(10deg) }
74+
}
75+
@media (max-width:500px) {
76+
.github-corner:hover .octo-arm {
77+
animation: none;
78+
}
79+
.github-corner .octo-arm {
80+
animation: octocat-wave 560ms ease-in-out;
81+
}
82+
}
83+
|]
84+
85+
footer :: Text
86+
footer = [q|
87+
<div class="github"><a href="https://github.com/spoqa/nirum/tree/master/examples" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a></div>
88+
|]

docs/target/docs.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ Docs target
22
===========
33

44
This target does not generate any program code files, but HTML pages (and
5-
some extra assets like CSS). It generates two kinds of pages:
5+
some extra assets like CSS). It generates three kinds of pages:
66

7+
- A home page that renders *README.md* file (if exists) or table of contents
8+
(if there is no *README.md* file).
79
- Reference docs from the docs comments in the source code: type definitions,
810
union tags, enum members, service methods, etc, and
911
- Manual pages from CommonMark (i.e., _\*.md_) files.
@@ -42,3 +44,15 @@ Settings
4244

4345
It goes to `<title>` elements of generated HTML pages. It's usually a name of
4446
the Nirum package.
47+
48+
49+
### `style` (optional): Custom CSS
50+
51+
It goes to very ending of the CSS file, which means it can override other
52+
predefined style rules.
53+
54+
55+
### `header`/`footer` (optional): Custom header & footer HTML
56+
57+
It goes to the very beginning and ending of `<body>` contents. It's usually
58+
used to customize HTML pages.

examples/package.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,24 @@ classifiers = [
1010

1111
[targets.docs]
1212
title = "Nirum Examples"
13+
style = """
14+
.github-corner:hover .octo-arm {
15+
animation: octocat-wave 560ms ease-in-out;
16+
}
17+
@keyframes octocat-wave {
18+
0%, 100% { transform:rotate(0) }
19+
20%, 60% { transform:rotate(-25deg) }
20+
40%, 80% { transform:rotate(10deg) }
21+
}
22+
@media (max-width:500px) {
23+
.github-corner:hover .octo-arm {
24+
animation: none;
25+
}
26+
.github-corner .octo-arm {
27+
animation: octocat-wave 560ms ease-in-out;
28+
}
29+
}
30+
"""
31+
footer = """
32+
<div class="github"><a href="https://github.com/spoqa/nirum/tree/master/examples" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a></div>
33+
"""

src/Nirum/Cli.hs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ import Nirum.Package.ModuleSet ( ImportError ( CircularImportError
3737
, MissingModulePathError
3838
)
3939
)
40-
import Nirum.Targets ( BuildError (CompileError, PackageError, TargetNameError)
41-
, BuildResult
42-
, buildPackage
43-
, targetNames
44-
)
40+
import Nirum.Targets
41+
( BuildError (..)
42+
, BuildResult
43+
, buildPackageFromFilePath
44+
, targetNames
45+
)
4546
import Nirum.Version (versionString)
4647

4748
type TFlag = TVar Bool
@@ -136,7 +137,7 @@ build options@AppOptions { packagePath = src
136137
, outputPath = outDir
137138
, targetLanguage = target
138139
} = do
139-
result <- buildPackage target src
140+
result <- buildPackageFromFilePath target src
140141
case result of
141142
Left (TargetNameError targetName') ->
142143
tryDie' [qq|Couldn't find "$targetName'" target.

src/Nirum/Package/Metadata.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ module Nirum.Package.Metadata ( Author (Author, email, name, uri)
4040
, fieldType
4141
, metadataFilename
4242
, metadataPath
43+
, optional
4344
, parseMetadata
4445
, packageTarget
4546
, prependMetadataErrorField

src/Nirum/Targets.hs

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{-# LANGUAGE QuasiQuotes, ScopedTypeVariables, TemplateHaskell #-}
2-
module Nirum.Targets ( BuildError (CompileError, PackageError, TargetNameError)
3-
, BuildResult
4-
, Target (..)
5-
, TargetName
6-
, buildPackage
7-
, targetNames
8-
) where
2+
module Nirum.Targets
3+
( BuildError (..)
4+
, BuildResult
5+
, Target (..)
6+
, TargetName
7+
, buildPackage
8+
, buildPackageFromFilePath
9+
, targetNames
10+
) where
911

1012
import Data.Either (partitionEithers)
1113
import Data.Maybe (fromMaybe)
@@ -48,34 +50,41 @@ type BuildResult = M.Map FilePath ByteString
4850

4951
packageBuilders :: M.Map TargetName
5052
(FilePath -> IO (Either BuildError BuildResult))
51-
packageBuilders = M.fromList $(targetProxyMapQ [e|buildPackage'|])
53+
packageBuilders = M.fromList $(targetProxyMapQ [e|buildPackageFromFilePath'|])
5254

5355
targetNames :: Set TargetName
5456
targetNames = M.keysSet packageBuilders
5557

56-
buildPackage :: TargetName -> FilePath -> IO (Either BuildError BuildResult)
57-
buildPackage targetName' =
58+
buildPackage :: forall t. Target t => Package t -> Either BuildError BuildResult
59+
buildPackage pkg@Package { metadata = Metadata { target = target' } } =
60+
case partitionEithers eithers of
61+
(errors@(_ : _), _) ->
62+
Left $ CompileError $ M.fromList errors
63+
([], outs) -> Right $ M.fromList outs
64+
where
65+
results :: [(FilePath, Either (CompileError t) (CompileResult t))]
66+
results = M.toList $ compilePackage pkg
67+
eithers :: [Either (FilePath, Text) (FilePath, ByteString)]
68+
eithers = [ case result of
69+
Left e -> Left (f, showCompileError target' e)
70+
Right r -> Right (f, toByteString target' r)
71+
| (f, result) <- results
72+
]
73+
74+
buildPackageFromFilePath :: TargetName
75+
-> FilePath
76+
-> IO (Either BuildError BuildResult)
77+
buildPackageFromFilePath targetName' =
5878
fromMaybe (\ _ -> return $ Left $ TargetNameError targetName') $
5979
M.lookup targetName' packageBuilders
6080

61-
buildPackage' :: forall t. Target t
62-
=> Proxy t
63-
-> FilePath
64-
-> IO (Either BuildError BuildResult)
65-
buildPackage' _ packagePath = do
81+
buildPackageFromFilePath' :: forall t. Target t
82+
=> Proxy t
83+
-> FilePath
84+
-> IO (Either BuildError BuildResult)
85+
buildPackageFromFilePath' _ packagePath = do
6686
scanResult <- scanPackage packagePath
6787
return $ case scanResult of
6888
Left e -> Left $ PackageError e
6989
Right (pkg :: Package t) ->
70-
let Package { metadata = Metadata { target = target' } } = pkg
71-
results = M.toList $ compilePackage pkg
72-
eithers = [ case result of
73-
Left e -> Left (f, showCompileError target' e)
74-
Right r -> Right (f, toByteString target' r)
75-
| (f, result) <- results
76-
] :: [Either (FilePath, Text) (FilePath, ByteString)]
77-
in
78-
case partitionEithers eithers of
79-
(errors@(_ : _), _) ->
80-
Left $ CompileError $ M.fromList errors
81-
([], outs) -> Right $ M.fromList outs
90+
buildPackage pkg

0 commit comments

Comments
 (0)