From 8ca58aef80930db82cd20e85f44f5e34e1d74214 Mon Sep 17 00:00:00 2001 From: Gil Mizrahi Date: Sun, 12 Sep 2021 09:07:13 +0300 Subject: [PATCH] Chapter 5.3 - Package format --- LICENSE.txt | 29 +++++++++++++++ README.md | 5 +++ app/Main.hs | 8 +++++ hs-blog.cabal | 51 +++++++++++++++++++++++++++ Main.hs => src/HsBlog.hs | 15 +++++--- Convert.hs => src/HsBlog/Convert.hs | 8 ++--- Html.hs => src/HsBlog/Html.hs | 6 ++-- {Html => src/HsBlog/Html}/Internal.hs | 4 +-- Markup.hs => src/HsBlog/Markup.hs | 4 +-- stack.yaml | 4 +++ 10 files changed, 118 insertions(+), 16 deletions(-) create mode 100644 LICENSE.txt create mode 100644 README.md create mode 100644 app/Main.hs create mode 100644 hs-blog.cabal rename Main.hs => src/HsBlog.hs (87%) rename Convert.hs => src/HsBlog/Convert.hs (79%) rename Html.hs => src/HsBlog/Html.hs (61%) rename {Html => src/HsBlog/Html}/Internal.hs (95%) rename Markup.hs => src/HsBlog/Markup.hs (97%) create mode 100644 stack.yaml diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..f12e08e --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2021-2022, Gil Mizrahi +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..b566cfc --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# hs-blog + +One day it will be a static blog generator. + +[Read the book](https://lhbg-book.link). diff --git a/app/Main.hs b/app/Main.hs new file mode 100644 index 0000000..8b1888b --- /dev/null +++ b/app/Main.hs @@ -0,0 +1,8 @@ +-- app/Main.hs + +module Main where + +import qualified HsBlog + +main :: IO () +main = HsBlog.main diff --git a/hs-blog.cabal b/hs-blog.cabal new file mode 100644 index 0000000..c8126ac --- /dev/null +++ b/hs-blog.cabal @@ -0,0 +1,51 @@ +cabal-version: 2.4 + +name: hs-blog +version: 0.1.0.0 +synopsis: A custom blog generator from markup files +description: This package provides a static blog generator + from a custom markup format to HTML. + It defines a parsing for this custom markup format + as well as an html pretty printer EDSL. + + It is used as the example project in the online book + 'Learn Haskell Blog Generator'. See the README for + more details. +homepage: https://github.com/soupi/learn-haskell-blog-generator +bug-reports: https://github.com/soupi/learn-haskell-blog-generator/issues +license: BSD-3-Clause +license-file: LICENSE.txt +author: Gil Mizrahi +maintainer: gilmi@posteo.net +category: Learning, Web +extra-doc-files: + README.md + +common common-settings + default-language: Haskell2010 + ghc-options: + -Wall + +library + import: common-settings + hs-source-dirs: src + build-depends: + base + , directory + exposed-modules: + HsBlog + HsBlog.Convert + HsBlog.Html + HsBlog.Html.Internal + HsBlog.Markup + -- other-modules: + +executable hs-blog-gen + import: common-settings + hs-source-dirs: app + main-is: Main.hs + build-depends: + base + , hs-blog + ghc-options: + -O diff --git a/Main.hs b/src/HsBlog.hs similarity index 87% rename from Main.hs rename to src/HsBlog.hs index 89713ff..262ff29 100644 --- a/Main.hs +++ b/src/HsBlog.hs @@ -1,9 +1,14 @@ --- Main.hs -module Main where +-- src/HsBlog.hs -import qualified Markup -import qualified Html -import Convert (convert) +module HsBlog + ( main + , process + ) + where + +import qualified HsBlog.Markup as Markup +import qualified HsBlog.Html as Html +import HsBlog.Convert (convert) import System.Directory (doesFileExist) import System.Environment (getArgs) diff --git a/Convert.hs b/src/HsBlog/Convert.hs similarity index 79% rename from Convert.hs rename to src/HsBlog/Convert.hs index c835470..6a1e6a4 100644 --- a/Convert.hs +++ b/src/HsBlog/Convert.hs @@ -1,9 +1,9 @@ --- Convert.hs +-- src/HsBlog/Convert.hs -module Convert where +module HsBlog.Convert where -import qualified Markup -import qualified Html +import qualified HsBlog.Markup as Markup +import qualified HsBlog.Html as Html convert :: Html.Title -> Markup.Document -> Html.Html convert title = Html.html_ title . foldMap convertStructure diff --git a/Html.hs b/src/HsBlog/Html.hs similarity index 61% rename from Html.hs rename to src/HsBlog/Html.hs index cab54bf..0531fa0 100644 --- a/Html.hs +++ b/src/HsBlog/Html.hs @@ -1,6 +1,6 @@ --- Html.hs +-- src/HsBlog/Html.hs -module Html +module HsBlog.Html ( Html , Title , Structure @@ -14,4 +14,4 @@ module Html ) where -import Html.Internal +import HsBlog.Html.Internal diff --git a/Html/Internal.hs b/src/HsBlog/Html/Internal.hs similarity index 95% rename from Html/Internal.hs rename to src/HsBlog/Html/Internal.hs index fa81488..378d884 100644 --- a/Html/Internal.hs +++ b/src/HsBlog/Html/Internal.hs @@ -1,6 +1,6 @@ --- Html/Internal.hs +-- src/HsBlog/Html/Internal.hs -module Html.Internal where +module HsBlog.Html.Internal where import Numeric.Natural diff --git a/Markup.hs b/src/HsBlog/Markup.hs similarity index 97% rename from Markup.hs rename to src/HsBlog/Markup.hs index 4715b3a..4f60d6d 100644 --- a/Markup.hs +++ b/src/HsBlog/Markup.hs @@ -1,6 +1,6 @@ --- Markup.hs +-- src/HsBlog/Markup.hs -module Markup +module HsBlog.Markup ( Document , Structure(..) , parse diff --git a/stack.yaml b/stack.yaml new file mode 100644 index 0000000..e52220e --- /dev/null +++ b/stack.yaml @@ -0,0 +1,4 @@ +resolver: lts-18.22 + +packages: +- .