added clipboard functionality with your comments
This commit is contained in:
parent
1b53607cd5
commit
dc33273d8a
BIN
templates/clipboard.png
Normal file
BIN
templates/clipboard.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 488 B |
@ -28,7 +28,7 @@
|
|||||||
{{.DocsRendered}}
|
{{.DocsRendered}}
|
||||||
</td>
|
</td>
|
||||||
<td class="code{{if .CodeEmpty}} empty{{end}}{{if .CodeLeading}} leading{{end}}">
|
<td class="code{{if .CodeEmpty}} empty{{end}}{{if .CodeLeading}} leading{{end}}">
|
||||||
{{if .CodeRun}}<a href="http://play.golang.org/p/{{$.UrlHash}}"><img title="Run code" src="play.png" class="run" /></a>{{end}}
|
{{if .CodeRun}}<a href="http://play.golang.org/p/{{$.UrlHash}}"><img title="Run code" src="play.png" class="run" /></a><img title="Copy code" src="clipboard.png" class="copy" />{{end}}
|
||||||
{{.CodeRendered}}
|
{{.CodeRendered}}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -44,5 +44,10 @@
|
|||||||
by <a href="https://twitter.com/mmcgrana">@mmcgrana</a> | <a href="mailto:mmcgrana@gmail.com">feedback</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/{{.Id}}">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
by <a href="https://twitter.com/mmcgrana">@mmcgrana</a> | <a href="mailto:mmcgrana@gmail.com">feedback</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/{{.Id}}">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
<script>
|
||||||
|
var codeLines = [];
|
||||||
|
{{range .Segs}}{{range .}}codeLines.push('{{js .CodeForJs}}'); {{end}}{{end}}
|
||||||
|
</script>
|
||||||
|
<script src="site.js" async></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -136,11 +136,14 @@ pre, code {
|
|||||||
font-size: 14px; line-height: 18px;
|
font-size: 14px; line-height: 18px;
|
||||||
font-family: 'Menlo', 'Monaco', 'Consolas', 'Lucida Console', monospace;
|
font-family: 'Menlo', 'Monaco', 'Consolas', 'Lucida Console', monospace;
|
||||||
}
|
}
|
||||||
img.run {
|
img.copy, img.run {
|
||||||
height: 16px;
|
height: 16px;
|
||||||
width: 16px;
|
width: 16px;
|
||||||
float: right
|
float: right
|
||||||
}
|
}
|
||||||
|
img.copy {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
/* Syntax highlighting */
|
/* Syntax highlighting */
|
||||||
body .hll { background-color: #ffffcc }
|
body .hll { background-color: #ffffcc }
|
||||||
|
17
templates/site.js
Normal file
17
templates/site.js
Normal file
File diff suppressed because one or more lines are too long
@ -120,7 +120,7 @@ var dashPat = regexp.MustCompile("\\-+")
|
|||||||
|
|
||||||
type Seg struct {
|
type Seg struct {
|
||||||
Docs, DocsRendered string
|
Docs, DocsRendered string
|
||||||
Code, CodeRendered string
|
Code, CodeRendered, CodeForJs string
|
||||||
CodeEmpty, CodeLeading, CodeRun bool
|
CodeEmpty, CodeLeading, CodeRun bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,6 +205,10 @@ func parseAndRenderSegs(sourcePath string) ([]*Seg, string) {
|
|||||||
}
|
}
|
||||||
if seg.Code != "" {
|
if seg.Code != "" {
|
||||||
seg.CodeRendered = cachedPygmentize(lexer, seg.Code)
|
seg.CodeRendered = cachedPygmentize(lexer, seg.Code)
|
||||||
|
// adding the content to the js code for copying to the clipboard
|
||||||
|
if strings.HasSuffix(sourcePath, ".go") {
|
||||||
|
seg.CodeForJs = strings.Trim(seg.Code, "\n") + "\n"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// we are only interested in the 'go' code to pass to play.golang.org
|
// we are only interested in the 'go' code to pass to play.golang.org
|
||||||
@ -276,9 +280,11 @@ func renderExamples(examples []*Example) {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
copyFile("templates/site.css", siteDir+"/site.css")
|
copyFile("templates/site.css", siteDir+"/site.css")
|
||||||
|
copyFile("templates/site.js", siteDir+"/site.js")
|
||||||
copyFile("templates/favicon.ico", siteDir+"/favicon.ico")
|
copyFile("templates/favicon.ico", siteDir+"/favicon.ico")
|
||||||
copyFile("templates/404.html", siteDir+"/404.html")
|
copyFile("templates/404.html", siteDir+"/404.html")
|
||||||
copyFile("templates/play.png", siteDir+"/play.png")
|
copyFile("templates/play.png", siteDir+"/play.png")
|
||||||
|
copyFile("templates/clipboard.png", siteDir+"/clipboard.png")
|
||||||
examples := parseExamples()
|
examples := parseExamples()
|
||||||
renderIndex(examples)
|
renderIndex(examples)
|
||||||
renderExamples(examples)
|
renderExamples(examples)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user