Add _docs

This commit is contained in:
Hajime Hoshi 2014-12-28 00:26:33 +09:00
parent ccd8fcac3d
commit 6f5d106b37
4 changed files with 220 additions and 1 deletions

102
_docs/gen.go Normal file
View File

@ -0,0 +1,102 @@
// Copyright 2014 Hajime Hoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// +build ignore
package main
import (
"github.com/google/go-github/github"
"html/template"
"io/ioutil"
"log"
"os"
"path/filepath"
)
const (
outputPath = "public/index.html"
readMePath = "../readme.md"
templatePath = "index_tmpl.html"
)
// TODO: License should be on another file
const license = `Copyright 2014 Hajime Hoshi
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.`
func parseMarkdown(path string) (string, error) {
md, err := ioutil.ReadFile(path)
if err != nil {
return "", err
}
client := github.NewClient(nil)
html, _, err := client.Markdown(string(md), nil)
if err != nil {
return "", err
}
return html, nil
}
func comment(text string) template.HTML {
// TODO: text should be escaped
return template.HTML("<!--" + text + "-->")
}
func safeHTML(text string) template.HTML {
return template.HTML(text)
}
func main() {
f, err := os.Create(outputPath)
if err != nil {
log.Fatal(err)
}
defer f.Close()
// Parse readme.md
readme, err := parseMarkdown(readMePath)
if err != nil {
log.Fatal(err)
}
funcs := template.FuncMap{
"comment": comment,
"safeHTML": safeHTML,
}
name := filepath.Base(templatePath)
t, err := template.New(name).Funcs(funcs).ParseFiles(templatePath)
if err != nil {
panic(err)
}
data := map[string]string{
"License": license,
"ReadMe": readme,
}
if err := t.Funcs(funcs).Execute(f, data); err != nil {
log.Fatal(err)
}
}

17
_docs/generate.go Normal file
View File

@ -0,0 +1,17 @@
// Copyright 2014 Hajime Hoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package docs
//go:generate go run gen.go

3
_docs/index_tmpl.html Normal file
View File

@ -0,0 +1,3 @@
<!DOCTYPE html>
{{ comment .License }}
{{ safeHTML .ReadMe }}

View File

@ -1 +1,98 @@
hogehoge <!DOCTYPE html>
<!--Copyright 2014 Hajime Hoshi
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.-->
<h1>
<a id="user-content-ebiten-海老天-v100-alpha" class="anchor" href="#ebiten-%E6%B5%B7%E8%80%81%E5%A4%A9-v100-alpha" aria-hidden="true"><span class="octicon octicon-link"></span></a>Ebiten (海老天) v1.0.0-alpha</h1>
<ul>
<li>A simple 2D game library in Go</li>
<li>Works on
<ul>
<li>Mac OS X</li>
<li>Linux (maybe)</li>
<li>Windows (possibly)</li>
</ul>
</li>
<li><a href="http://godoc.org/github.com/hajimehoshi/ebiten">API Docs</a></li>
</ul>
<h2>
<a id="user-content-features" class="anchor" href="#features" aria-hidden="true"><span class="octicon octicon-link"></span></a>Features</h2>
<ul>
<li>2D Graphics</li>
<li>Input (Mouse, Keyboard)</li>
</ul>
<h2>
<a id="user-content-example" class="anchor" href="#example" aria-hidden="true"><span class="octicon octicon-link"></span></a>Example</h2>
<ul>
<li>example/mosaic - Mosaics an image</li>
<li>example/perspective - See an image in a perspective view</li>
<li>example/rotate - Rotates an image</li>
<li>etc.</li>
</ul>
<h2>
<a id="user-content-install-on-mac-os-x" class="anchor" href="#install-on-mac-os-x" aria-hidden="true"><span class="octicon octicon-link"></span></a>Install on Mac OS X</h2>
<pre><code>:; brew install glew
:; brew install glfw3 # or homebrew/versions/glfw3
:; go get -u github.com/hajimehoshi/ebiten
</code></pre>
<h2>
<a id="user-content-execute-the-example" class="anchor" href="#execute-the-example" aria-hidden="true"><span class="octicon octicon-link"></span></a>Execute the example</h2>
<pre><code>:; cd $GOHOME/src/github.com/hajimehoshi/ebiten/example
:; go run blocks/main.go
</code></pre>
<h3>
<a id="user-content-benchmark-the-example" class="anchor" href="#benchmark-the-example" aria-hidden="true"><span class="octicon octicon-link"></span></a>Benchmark the example</h3>
<pre><code>:; cd $GOHOME/src/github.com/hajimehoshi/ebiten/example
:; go build -o=example blocks/main.go
:; ./example -cpuprofile=cpu.out
:; go tool pprof ./example cpu.out
</code></pre>
<h2>
<a id="user-content-versioning" class="anchor" href="#versioning" aria-hidden="true"><span class="octicon octicon-link"></span></a>Versioning</h2>
<ul>
<li>We adopted <a href="http://semver.org/">Semantic Versioning</a>
</li>
</ul>
<h2>
<a id="user-content-license" class="anchor" href="#license" aria-hidden="true"><span class="octicon octicon-link"></span></a>License</h2>
<pre><code>Copyright 2014 Hajime Hoshi
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
</code></pre>