Add some Codo comments

This commit is contained in:
Vit Brunner committed 2013-06-16 11:18:18 +01:00
1 parent 72e5280e44
commit 8483aa6548
3 files changed
+43 -12

No files matched your search

@@ -1,4 +1,8 @@
angular.module("sideBySide").factory("readerFactory", ($injector) ->
# Create poem reader based on file name
#
# @param [String] Source file name
# @return [Object] Reader
return (filename) ->
extension = filename.split(".").pop()
switch extension
@@ -1,4 +1,11 @@
angular.module("sideBySide").factory("jsonReader", () ->
# Read json poem
#
# For sample input, see:
# source/documents/tests/services/reader/json.js.coffee
#
# @param source [String] Json poem
# @return [Object] Poem object
return (source) ->
parsed = eval('(' + source + ')')
@@ -1,22 +1,42 @@
angular.module("sideBySide").factory("markdownReader", () ->
# Read markdown poem
#
# For sample input, see:
# source/documents/tests/services/reader/markdown.js.coffee
#
# @param source [String] Markdown poem
# @return [Object] Poem object
return (source) ->
readMeta = (block, inlineLexer) ->
# Read meta information from markdown block
#
# @param block [string] Meta block
# @param inlineLexer [Object] Inline markdown lexer
# @return [Object] Meta properties
readMeta = (text, inlineLexer) ->
meta = {}
lexed = inlineLexer.output(block.text)
lexed = inlineLexer.output(text)
for line in lexed.split("\n")
match = /([^:]*):(.*)/.exec(line)
meta[match[1].trim()] = match[2].trim()
return meta
readContent = (lexed) ->
getSection = (lexed) ->
items = []
while lexed.length > 0
if lexed[0]["type"] == "heading"
break
items.push(lexed.shift())
return items
# Read and remove one section from start of lexed blocks
#
# @param lexed [Array] Lexed blocks
# @return [Array] Section
readSection = (lexed) ->
items = []
while lexed.length > 0
if lexed[0]["type"] == "heading"
break
items.push(lexed.shift())
return items
# Read content from lexed blocks
#
# @param lexed [Array] Lexed blocks
# @return [Array] Content
readContent = (lexed) ->
content = []
while lexed.length > 0
@@ -25,7 +45,7 @@ angular.module("sideBySide").factory("markdownReader", () ->
else
heading = ''
text = getSection(lexed)
text = readSection(lexed)
text.links = lexed.links
content.push({
section: heading
@@ -39,7 +59,7 @@ angular.module("sideBySide").factory("markdownReader", () ->
inlineLexer = new marked.InlineLexer(lexed.links)
return {
meta: readMeta(meta, inlineLexer)
meta: readMeta(meta.text, inlineLexer)
content: readContent(lexed)
}
)