Skip to content

Commit

Permalink
Merge pull request #1369 from 47deg/master
Browse files Browse the repository at this point in the history
New Proposal for the Cats Microsite
  • Loading branch information
kailuowang authored Oct 21, 2016
2 parents 9f981b1 + ed35844 commit fe026bc
Show file tree
Hide file tree
Showing 55 changed files with 174 additions and 877 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ scala:
- 2.10.6
- 2.11.8

before_install:
- export PATH=${PATH}:./vendor/bundle

script:
- scripts/travis-publish.sh

# http://austinpray.com/ops/2015/09/20/change-travis-node-version.html
install:
- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm install $TRAVIS_NODE_VERSION
- pip install --user codecov
- gem install jekyll -v 2.5

notifications:
webhooks:
Expand Down
7 changes: 4 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
layout: default
layout: page
title: "Contributing"
section: "contributing"
position: 5
---

# Contributor guide
Expand Down Expand Up @@ -175,7 +176,7 @@ The documentation for this website is stored alongside the source, in the [docs

### Generating the Site

run `sbt docs/makeSite`
run `sbt docs/makeMicrosite`

### Previewing the site

Expand All @@ -193,7 +194,7 @@ run `sbt docs/makeSite`

4. Navigate to http://localhost:4000/cats/ in your browser

5. Make changes to your site, and run `sbt makeSite` to regenerate the site. The changes should be reflected as soon as you run `makeSite`.
5. Make changes to your site, and run `sbt docs/makeMicrosite` to regenerate the site. The changes should be reflected as soon as you run `makeMicrosite`.

### Compiler verified documentation

Expand Down
33 changes: 25 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import com.typesafe.sbt.pgp.PgpKeys.publishSigned
import com.typesafe.sbt.SbtSite.SiteKeys._
import com.typesafe.sbt.SbtGhPages.GhPagesKeys._
import sbtunidoc.Plugin.UnidocKeys._
import ReleaseTransformations._
Expand Down Expand Up @@ -145,16 +143,36 @@ lazy val javadocSettings = Seq(
sources in (Compile, doc) := (if (docsSourcesAndProjects(scalaVersion.value)._1) (sources in (Compile, doc)).value else Nil)
)

lazy val docsMappingsAPIDir = settingKey[String]("Name of subdirectory in site target directory for api docs")

lazy val docSettings = Seq(
micrositeName := "Cats",
micrositeDescription := "Lightweight, modular, and extensible library for functional programming",
micrositeAuthor := "Typelevel contributors",
micrositeHighlightTheme := "atom-one-light",
micrositeHomepage := "http://typelevel.org/cats",
micrositeBaseUrl := "cats",
micrositeDocumentationUrl := "api",
micrositeGithubOwner := "typelevel",
micrositeExtraMdFiles := Map(file("CONTRIBUTING.md") -> "contributing.md"),
micrositeGithubRepo := "cats",
micrositePalette := Map(
"brand-primary" -> "#5B5988",
"brand-secondary" -> "#292E53",
"brand-tertiary" -> "#222749",
"gray-dark" -> "#49494B",
"gray" -> "#7B7B7E",
"gray-light" -> "#E5E5E6",
"gray-lighter" -> "#F4F3F4",
"white-color" -> "#FFFFFF"),
autoAPIMappings := true,
unidocProjectFilter in (ScalaUnidoc, unidoc) :=
inProjects(docsSourcesAndProjects(scalaVersion.value)._2:_*),
site.addMappingsToSiteDir(mappings in (ScalaUnidoc, packageDoc), "api"),
site.addMappingsToSiteDir(tut, "_tut"),
docsMappingsAPIDir := "api",
addMappingsToSiteDir(mappings in (ScalaUnidoc, packageDoc), docsMappingsAPIDir),
ghpagesNoJekyll := false,
fork in tut := true,
fork in (ScalaUnidoc, unidoc) := true,
siteMappings += file("CONTRIBUTING.md") -> "contributing.md",
scalacOptions in (ScalaUnidoc, unidoc) ++= Seq(
"-Xfatal-warnings",
"-doc-source-url", scmInfo.value.get.browseUrl + "/tree/master€{FILE_PATH}.scala",
Expand All @@ -166,14 +184,13 @@ lazy val docSettings = Seq(
)

lazy val docs = project
.enablePlugins(MicrositesPlugin)
.settings(moduleName := "cats-docs")
.settings(catsSettings)
.settings(noPublishSettings)
.settings(unidocSettings)
.settings(site.settings)
.settings(ghpages.settings)
.settings(docSettings)
.settings(tutSettings)
.settings(tutScalacOptions ~= (_.filterNot(Set("-Ywarn-unused-import", "-Ywarn-dead-code"))))
.settings(commonJvmSettings)
.dependsOn(coreJVM, freeJVM)
Expand Down Expand Up @@ -402,7 +419,7 @@ lazy val publishSettings = Seq(
// These aliases serialise the build for the benefit of Travis-CI.
addCommandAlias("buildJVM", "catsJVM/test")

addCommandAlias("validateJVM", ";scalastyle;buildJVM;makeSite")
addCommandAlias("validateJVM", ";scalastyle;buildJVM;makeMicrosite")

addCommandAlias("validateJS", ";catsJS/compile;testsJS/test;js/test")

Expand Down
3 changes: 3 additions & 0 deletions docs/src/main/resources/microsite/css/override.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.technologies {
display: none;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/main/resources/microsite/img/poster.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion docs/src/site/colophon.md → docs/src/main/tut/colophon.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
layout: default
layout: page
title: "Colophon"
section: "colophon"
position: 6
---
Cats has been made a much better project, and is a much more enjoyable
project to work on because of many of the other projects on which Cats
Expand Down
5 changes: 3 additions & 2 deletions docs/src/site/datatypes.md → docs/src/main/tut/datatypes.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
---
layout: default
layout: docs
title: "Data Types"
section: "data"
position: 2
---
# Data Types

{% for x in site.tut %}
{% for x in site.pages %}
{% if x.section == 'data' %}
- [{{x.title}}]({{site.baseurl}}{{x.url}})
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: default
layout: docs
title: "Const"
section: "data"
source: "core/src/main/scala/cats/data/Const.scala"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: default
layout: docs
title: "Either"
section: "data"
source: "core/src/main/scala/cats/syntax/either.scala"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: default
layout: docs
title: "FreeApplicatives"
section: "data"
source: "free/src/main/scala/cats/free/FreeApplicative.scala"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: default
layout: docs
title: "FreeMonads"
section: "data"
source: "free/src/main/scala/cats/free/Free.scala"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: default
layout: docs
title: "Kleisli"
section: "data"
source: "core/src/main/scala/cats/data/Kleisli.scala"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: default
layout: docs
title: "OneAnd"
section: "data"
source: "core/src/main/scala/cats/data/OneAnd.scala"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: default
layout: docs
title: "OptionT"
section: "data"
source: "core/src/main/scala/cats/data/OptionT.scala"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: default
layout: docs
title: "State"
section: "data"
source: "core/src/main/scala/cats/data/StateT.scala"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: default
layout: docs
title: "Validated"
section: "data"
source: "core/src/main/scala/cats/data/Validated.scala"
Expand Down
3 changes: 2 additions & 1 deletion docs/src/main/tut/faq.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
layout: default
layout: page
title: "FAQ"
section: "faq"
position: 4
---

# Frequently Asked Questions
Expand Down
2 changes: 1 addition & 1 deletion docs/src/site/index.md → docs/src/main/tut/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: default
layout: home
title: "Home"
section: "home"
---
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
layout: default
layout: page
title: "Resources for Learners"
section: "resources_for_learners"
position: 3
---
# Books
* [Functional Programming in Scala](https://www.manning.com/books/functional-programming-in-scala)
Expand Down
99 changes: 13 additions & 86 deletions docs/src/main/tut/typeclasses.md
Original file line number Diff line number Diff line change
@@ -1,87 +1,14 @@
# Type classes
---
layout: docs
title: "Type Classes"
section: "typeclasses"
position: 1
---
{% include_relative typeclasses/typeclasses.md %}

{% for x in site.pages %}
{% if x.section == 'typeclasses' %}
- [{{x.title}}]({{site.baseurl}}{{x.url}})
{% endif %}
{% endfor %}

The type class pattern is a ubiquitous pattern in Scala, its function
is to provide a behavior for some type. You think of it as an
"interface" in the Java sense. Here's an example.

```tut:silent
/**
* A type class to provide textual representation
*/
trait Show[A] {
def show(f: A): String
}
```
This class says that a value of type `Show[A]` has a way to turn `A`s
into `String`s. Now we can write a function which is polymorphic on
some `A`, as long as we have some value of `Show[A]`, so that our function
can have a way of producing a `String`:

```tut:silent
def log[A](a: A)(implicit s: Show[A]) = println(s.show(a))
```

If we now try to call log, without supplying a `Show` instance, we will
get a compilation error:

```tut:nofail
log("a string")
```

It is trivial to supply a `Show` instance for `String`:

```tut:silent
implicit val stringShow = new Show[String] {
def show(s: String) = s
}
```

and now our call to Log succeeds

```tut:book
log("a string")
```

This example demonstrates a powerful property of the type class
pattern. We have been able to provide an implementation of `Show` for
`String`, without needing to change the definition of `java.lang.String`
to extend a new Java-style interface; something we couldn't have done
even if we wanted to, since we don't control the implementation of
`java.lang.String`. We use this pattern to retrofit existing
types with new behaviors. This is usually referred to as "ad-hoc
polymorphism".

For some types, providing a `Show` instance might depend on having some
implicit `Show` instance of some other type, for instance, we could
implement `Show` for `Option`:

```tut:silent
implicit def optionShow[A](implicit sa: Show[A]) = new Show[Option[A]] {
def show(oa: Option[A]): String = oa match {
case None => "None"
case Some(a) => "Some("+ sa.show(a) + ")"
}
}
```

Now we can call our log function with a `Option[String]` or a
`Option[Option[String]]`:

```tut:book
log(Option(Option("hello")))
```

Scala has syntax just for this pattern that we use frequently:

```tut:silent
def log[A: Show](a: A) = println(implicitly[Show[A]].show(a))
```

is the same as

```tut:silent
def log[A](a: A)(implicit s: Show[A]) = println(s.show(a))
```

That is that declaring the type parameter as `A : Show`, it will add
an implicit parameter to the method signature (with a name we do not know).
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: default
layout: docs
title: "Applicative"
section: "typeclasses"
source: "core/src/main/scala/cats/Applicative.scala"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: default
layout: docs
title: "Apply"
section: "typeclasses"
source: "core/src/main/scala/cats/Apply.scala"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: default
layout: docs
title: "Contravariant"
section: "typeclasses"
source: "core/src/main/scala/cats/functor/Contravariant.scala"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: default
layout: docs
title: "Foldable"
section: "typeclasses"
source: "core/src/main/scala/cats/Foldable.scala"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: default
layout: docs
title: "Functor"
section: "typeclasses"
source: "core/src/main/scala/cats/Functor.scala"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: default
layout: docs
title: "Id"
section: "typeclasses"
source: "core/src/main/scala/cats/package.scala"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: default
layout: docs
title: "Imports"
section: "imports"
---
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: default
layout: docs
title: "Invariant"
section: "typeclasses"
source: "core/src/main/scala/cats/functor/Invariant.scala"
Expand Down
Loading

0 comments on commit fe026bc

Please sign in to comment.