Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(281)

Delta Between Two Patch Sets: src/cmd/godoc/godoc.go

Issue 6523045: code review 6523045: godoc: make examples editable and runnable in playground (Closed)
Left Patch Set: diff -r 3d637cc9dff0 https://code.google.com/p/go Created 12 years, 5 months ago
Right Patch Set: diff -r e10f183a55fb https://code.google.com/p/go Created 12 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/godoc/package.html ('k') | src/cmd/godoc/main.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package main 5 package main
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "encoding/json" 9 "encoding/json"
10 "flag" 10 "flag"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 55
56 // file system roots 56 // file system roots
57 // TODO(gri) consider the invariant that goroot always end in '/' 57 // TODO(gri) consider the invariant that goroot always end in '/'
58 goroot = flag.String("goroot", runtime.GOROOT(), "Go root directory") 58 goroot = flag.String("goroot", runtime.GOROOT(), "Go root directory")
59 testDir = flag.String("testdir", "", "Go root subdirectory - for testing only (faster startups)") 59 testDir = flag.String("testdir", "", "Go root subdirectory - for testing only (faster startups)")
60 60
61 // layout control 61 // layout control
62 tabwidth = flag.Int("tabwidth", 4, "tab width") 62 tabwidth = flag.Int("tabwidth", 4, "tab width")
63 showTimestamps = flag.Bool("timestamps", false, "show timestamps with di rectory listings") 63 showTimestamps = flag.Bool("timestamps", false, "show timestamps with di rectory listings")
64 templateDir = flag.String("templates", "", "directory containing alte rnate template files") 64 templateDir = flag.String("templates", "", "directory containing alte rnate template files")
65 showPlayground = flag.Bool("play", false, "enable playground in web inte rface")
65 66
66 // search index 67 // search index
67 indexEnabled = flag.Bool("index", false, "enable search index") 68 indexEnabled = flag.Bool("index", false, "enable search index")
68 indexFiles = flag.String("index_files", "", "glob pattern specifying i ndex files;"+ 69 indexFiles = flag.String("index_files", "", "glob pattern specifying i ndex files;"+
69 "if not empty, the index is read from these files in sorted orde r") 70 "if not empty, the index is read from these files in sorted orde r")
70 maxResults = flag.Int("maxresults", 10000, "maximum number of full te xt search results shown") 71 maxResults = flag.Int("maxresults", 10000, "maximum number of full te xt search results shown")
71 indexThrottle = flag.Float64("index_throttle", 0.75, "index throttle val ue; 0.0 = no time allocated, 1.0 = full throttle") 72 indexThrottle = flag.Float64("index_throttle", 0.75, "index throttle val ue; 0.0 = no time allocated, 1.0 = full throttle")
72 73
73 // file system information 74 // file system information
74 fsTree RWValue // *Directory tree of packages, updated with each sy nc (but sync code is removed now) 75 fsTree RWValue // *Directory tree of packages, updated with each sy nc (but sync code is removed now)
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 code = strings.Replace(code, "\n ", "\n", -1) 348 code = strings.Replace(code, "\n ", "\n", -1)
348 // remove output comment 349 // remove output comment
349 if loc := exampleOutputRx.FindStringIndex(code); loc != nil { 350 if loc := exampleOutputRx.FindStringIndex(code); loc != nil {
350 code = strings.TrimSpace(code[:loc[0]]) 351 code = strings.TrimSpace(code[:loc[0]])
351 } 352 }
352 } 353 }
353 354
354 // Write out the playground code in standard Go style 355 // Write out the playground code in standard Go style
355 // (use tabs, no comment highlight, etc). 356 // (use tabs, no comment highlight, etc).
356 play := "" 357 play := ""
357 » » if eg.Play != nil { 358 » » if eg.Play != nil && *showPlayground {
358 » » » buf := new(bytes.Buffer) 359 » » » var buf bytes.Buffer
359 » » » err := (&printer.Config{Mode: printer.TabIndent, Tabwidt h: 8}).Fprint(buf, fset, eg.Play) 360 » » » err := (&printer.Config{Mode: printer.TabIndent, Tabwidt h: 8}).Fprint(&buf, fset, eg.Play)
360 if err != nil { 361 if err != nil {
361 log.Print(err) 362 log.Print(err)
362 } else { 363 } else {
363 play = buf.String() 364 play = buf.String()
364 } 365 }
365 } 366 }
366 367
367 // Drop output, as the output comment will appear in the code. 368 // Drop output, as the output comment will appear in the code.
368 if wholeFile && play == "" { 369 if wholeFile && play == "" {
369 out = "" 370 out = ""
(...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 updateIndex() 1419 updateIndex()
1419 } 1420 }
1420 delay := 60 * time.Second // by default, try every 60s 1421 delay := 60 * time.Second // by default, try every 60s
1421 if *testDir != "" { 1422 if *testDir != "" {
1422 // in test mode, try once a second for fast startup 1423 // in test mode, try once a second for fast startup
1423 delay = 1 * time.Second 1424 delay = 1 * time.Second
1424 } 1425 }
1425 time.Sleep(delay) 1426 time.Sleep(delay)
1426 } 1427 }
1427 } 1428 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b