Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 3 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 111 additions and 12 deletions.
  1. +32 −0 coffee/planfile.coffee
  2. +35 −10 planfile.go
  3. +44 −2 sass/planfile.sass
View
32 coffee/planfile.coffee
@@ -20,7 +20,39 @@ define 'planfile', (exports, root) ->
exports.auth = auth = ->
if getLogin() == '' then false else true
+ buildTags = ->
+ tagMenu = doc.createElement 'div'
+ tagMenu.setAttribute 'class', 'container tag-menu'
+ tagList = doc.querySelector('article input[type="hidden"]').value
+ for tag in tagList.trim().split(" ")
+ do (tag) ->
+ tagElem = document.createElement('a')
+ tagElem.href = '#'
+ tagText = tag.replace('tag-user-', '@').replace('tag-label-', '#')
+ tagElem.textContent = tagText
+ tagElem.setAttribute 'class', tag
+ clicked = false
+ tagElem.onclick = (e) ->
+ style = ''
+ tClass = ''
+ if !clicked
+ style = 'display: none;'
+ tClass = "clicked "
+ targets = doc.querySelectorAll('section.' + tag)
+ for target in targets
+ do (target) ->
+ oldStyle = target.getAttribute('style')
+ target.setAttribute 'style', style
+ @.setAttribute('class', tClass + @.getAttribute('class').replace('clicked', ''))
+ clicked = !clicked
+ e.preventDefault()
+ return false
+ tagMenu.appendChild tagElem
+ header = doc.querySelector '.header'
+ header.insertAdjacentElement 'afterend', tagMenu
+
exports.run = ->
+ buildTags()
if auth()
showIndexLoggedIn()
else
View
45 planfile.go
@@ -237,10 +237,8 @@ func main() {
// Store repository in map
repos := map[string][]file{}
- log.Info("Loading repository: %s", tarURL)
repo := LoadRepository(tarURL)
saveRepo(config.Repository, repo, repos)
- log.Info("DONE")
parseTags := func(lines []string) (tags map[string]string, content []string) {
tags = make(map[string]string)
@@ -259,25 +257,52 @@ func main() {
return
}
+ generateTags := func(t string) (tags string) {
+ t = strings.Trim(t, " ")
+ ts := strings.Split(t, " ")
+ for _, c := range ts {
+ tags += "<span data-tag-link='" + c + "'>" + c + "</span>"
+ }
+ return
+ }
+
+ generateTagClasses := func(t string) string {
+ t = strings.Trim(t, " ")
+ t = strings.Replace(t, "@", "tag-user-", -1)
+ t = strings.Replace(t, "#", "tag-label-", -1)
+ return t
+ }
+
// Build a planfile from a list of files
buildPlanfile := func(repo []file) (pf string) {
var rf, e, a string
+ var tagList string
for _, f := range repo {
tags, content := parseTags(f.content)
- a = "<div class='tags'>" + tags["tags"] + "</div>"
+ ts := generateTags(tags["tags"])
+ tsc := generateTagClasses(tags["tags"])
+ tsl := strings.Split(tsc, " ")
+ for _, t := range tsl {
+ if !strings.Contains(tagList, t) {
+ tagList += " " + t
+ }
+ }
+ a = "<div class='tags'><a class='edit' href='#'>Edit</a>" + ts + "</div>"
+ original := strings.Join(f.content, "\n")
entry := strings.Join(content, "\n")
+ form := "<form action='.' method='post' style='display:none;'><textarea name='content'>" + original +
+ "</textarea><input type='hidden' value='" + f.name + "'/></form>"
e = string(blackfriday.MarkdownBasic([]byte(entry)))
if strings.ToLower(f.name) == "readme.md" {
- rf = "<div class='entry readme'>" + e + a + "</div>"
+ rf = "<section class='entry readme " + tsc + "'>" + e + a + form + "</section>"
} else {
- pf += "<div class='entry'>" + e + a + "</div>"
+ pf += "<section class='entry " + tsc + "'>" + e + a + form + "</section>"
}
}
- pf = rf + pf
+ pf = "<input type='hidden' value='" + tagList + "'/>" + rf + pf
return
}
- log.Info("Building planfile")
pf := buildPlanfile(repos[config.Repository])
register := func(path string, handler func(*Context)) {
@@ -313,9 +338,9 @@ func main() {
header = "<div class='container header'><a href='/login' class='button login'>Log in with GitHub</a></div>"
}
ctx.Write([]byte("<link href='/static/" + assets["planfile.css"] + "' rel='stylesheet' type='text/css'></head>" +
- "<body data-user='" + ctx.GetCookie("user") + "'>" +
- "<div id='body'><div id='home'>" + header + "<div class='container planfiles'>" + pf +
- "</div></div><script src='/static/" + assets["planfile.js"] + "' type='text/javascript'></script></body>"))
+ "<body data-user='" + username + "'>" + "<div id='body'><div id='home'>" + header +
+ "<article class='container planfiles'>" + pf + "</article></div><script src='/static/" + assets["planfile.js"] +
+ "' type='text/javascript'></script></body>"))
})
View
46 sass/planfile.sass
@@ -5,6 +5,7 @@ $lightgrey: #EFEFEF
$red: red
$lightred: #F11
$blue: #01A0EB
+$lightblue: #08B0FF
*
padding: 0
@@ -212,11 +213,52 @@ p.title
background: white
margin: 0
+.tag-menu
+ a
+ color: #B1B1B1
+ text-decoration: none
+ background: #F8F8F8
+ padding: 4px 9px
+ border-radius: 13px
+ font-weight: bold
+ font-size: 12px
+ margin-right: 10px
+ float: right
+ display: inline-block
+ &.clicked
+ background: #A1A1A1
+ color: white
+
.planfiles
- .entry
+ .entry
margin-bottom: 30px
.tags
- color: $lightgrey
+ clear: both
+ overflow: auto
+ a
+ background: #F8F8F8
+ text-decoration: none
+ color: #999
+ border-radius: 3px
+ padding: 4px 5px
+ font-size: 10px
+ float: left
+ display: none
+ span
+ color: #818181
+ text-decoration: none
+ padding: 4px 6px
+ background: #EEE
+ margin-right: 10px
+ border-radius: 3px
+ font-size: 10px
+ float: right
+ &[data-tag-link*="@"]
+ background: $red
+ color: white
+ &[data-tag-link*="#"]
+ background: $lightblue
+ color: white
ul
li
padding: 10px

No commit comments for this range

Something went wrong with that request. Please try again.