Fewer parentheses

This commit is contained in:
Vit Brunner
2014-12-22 23:07:40 +01:00
parent 83fbe5d538
commit fe8c134920
17 changed files with 100 additions and 108 deletions
+12 -12
View File
@@ -8,26 +8,26 @@ angular.module("sideBySide.controllers", [])
min = 1
max = 5
scroll = () ->
setTimeout () ->
if ('section' of route.params)
scroll = ->
setTimeout ->
if 'section' of route.params
section = 'section-' + route.params['section']
element = document.getElementById(section)
element = document.getElementById section
$document.scrollTo(element, 10, 200) if element
, 1
$rootScope.$on 'duScrollspy:becameActive', ($event, $element) ->
if (not $scope.meta[0].Loading)
route.update('section', $element.prop('id').replace('section-', ''))
if not $scope.meta[0].Loading
route.update 'section', $element.prop('id').replace('section-', '')
$rootScope.$apply()
$scope.$watchCollection () ->
$scope.$watchCollection ->
poems.getActive()
, () ->
, ->
active = poems.getActive()
$scope.columns = active.length
transformed = transformer(active)
transformed = transformer active
$scope.verses = transformed.verses
$scope.meta = transformed.meta
@@ -40,9 +40,9 @@ angular.module("sideBySide.controllers", [])
$scope.switchActive = (poem) ->
length = poems.getActive().length
active = poem.meta.Active
if ((length > min or not active) and (length < max or active))
if (length > min or not active) and (length < max or active)
poem.meta.Active = not poem.meta.Active
route.update('display', filter.getFilter())
route.update 'display', filter.getFilter()
# TODO else notification
$scope.flipPick = () ->
@@ -51,7 +51,7 @@ angular.module("sideBySide.controllers", [])
$scope.pick = false
load(
route.appUrl + '/' + route.params.base.replace(/\./g, '/')
route.appUrl + '/' + route.params.base.replace /\./g, '/'
route.params.display
)
]
+14 -21
View File
@@ -1,27 +1,24 @@
angular.module("sideBySide").service "filter", ['poems', (poems) ->
headers = []
@update = () ->
extractHeaders(poems.all)
@update = ->
extractHeaders poems.all
@getFilter = () ->
@getFilter = ->
encodings = []
for header in headers
activeHeaderValues = _.uniq(poems.getActive().map((item) ->
activeHeaderValues = _.uniq poems.getActive().map (item) ->
item.meta[header]
))
inactiveMatching = poems.getInactive().filter((item) ->
inactiveMatching = poems.getInactive().filter (item) ->
item.meta[header] in activeHeaderValues
)
if (inactiveMatching.length > 0)
if inactiveMatching.length > 0
continue # inactive poems have same header value
encodings.push({ 'header': header, 'values': activeHeaderValues })
encodings.push { 'header': header, 'values': activeHeaderValues }
minlength = _.min(encodings.map((item) -> item.values.length))
firstMin = _.first(encodings.filter((item) ->
minlength = _.min encodings.map (item) -> item.values.length
firstMin = _.first encodings.filter (item) ->
item.values.length == minlength
))
ret = {}
ret[firstMin.header] = firstMin.values
@@ -29,23 +26,19 @@ angular.module("sideBySide").service "filter", ['poems', (poems) ->
extractHeaders = (all) ->
fieldLengths = all
.map (poem) ->
poem.meta
.reduce((fields, meta) ->
.map (poem) -> poem.meta
.reduce (fields, meta) ->
for key, val of meta
if typeof val == 'string'
if key not of fields
fields[key] = 0
fields[key] += val.length
fields
, {})
, {}
headers = _
.sortBy((
{ 'key': k, 'len': l } for k,l of fieldLengths
), 'len')
.map (item) ->
item.key
.sortBy ({ 'key': k, 'len': l } for k,l of fieldLengths), 'len'
.map (item) -> item.key
@
]
+1 -1
View File
@@ -1,4 +1,4 @@
angular.module("sideBySide").factory "load", ['filter', 'fetch', 'poems', (filter, fetch, poems) ->
angular.module("sideBySide").factory "load", [ 'filter', 'fetch', 'poems', (filter, fetch, poems) ->
# Load poems
#
# @param base [String] Path to config file directory
+3 -3
View File
@@ -1,4 +1,4 @@
angular.module("sideBySide").service "poems", () ->
angular.module("sideBySide").service "poems", ->
@all = [{
meta: {
Active: true
@@ -14,13 +14,13 @@ angular.module("sideBySide").service "poems", () ->
# Get active poems
#
# @return [Array] Active poems
@getActive = () ->
@getActive = ->
(poem for poem in @all when poem.meta.Active == true)
# Get inactive poems
#
# @return [Array] Inactive poems
@getInactive = () ->
@getInactive = ->
(poem for poem in @all when poem.meta.Active != true)
@
@@ -7,9 +7,9 @@ angular.module("sideBySide").factory "readerFactory", ['$injector', ($injector)
extension = filename.split(".").pop()
switch extension
when "json"
return $injector.get("jsonReader")
return $injector.get "jsonReader"
when "md", "markdown"
return $injector.get("markdownReader")
return $injector.get "markdownReader"
else
throw "Unknown extension '" + extension + "'."
]
@@ -1,4 +1,4 @@
angular.module("sideBySide").factory("jsonReader", () ->
angular.module("sideBySide").factory("jsonReader", ->
# Read json poem
#
# For sample input, see:
@@ -10,7 +10,7 @@ angular.module("sideBySide").factory("jsonReader", () ->
parsed = eval('(' + source + ')')
for i,verse of parsed.content
if typeof(verse) == "string"
if typeof verse == "string"
parsed.content[i] = { section: "", text: verse }
else
verse.section = "" if "section" not of verse
@@ -1,4 +1,4 @@
angular.module("sideBySide").factory("markdownReader", () ->
angular.module("sideBySide").factory("markdownReader", ->
# Read markdown poem
#
# For sample input, see:
@@ -14,9 +14,9 @@ angular.module("sideBySide").factory("markdownReader", () ->
# @return [Object] Meta properties
readMeta = (text, inlineLexer) ->
meta = {}
for line in text.split("\n")
lexed = inlineLexer.output(line)
match = /([^:]*):(.*)/.exec(lexed)
for line in text.split "\n"
lexed = inlineLexer.output line
match = /([^:]*):(.*)/.exec lexed
meta[match[1].trim()] = match[2].trim()
meta
@@ -28,7 +28,7 @@ angular.module("sideBySide").factory("markdownReader", () ->
items = []
while lexed.length > 0
break if lexed[0]["type"] in separators
items.push(lexed.shift())
items.push lexed.shift()
items
# Read content from lexed blocks
@@ -46,16 +46,15 @@ angular.module("sideBySide").factory("markdownReader", () ->
text = readSection(lexed, separators)
text.links = lexed.links
content.push({
content.push {
section: heading
text: marked.parser(text)
})
text: marked.parser text
}
content
marked.setOptions({ smartypants: true })
lexed = marked.lexer(source)
meta = lexed.shift()
meta = readMeta(meta.text, new marked.InlineLexer(lexed.links))
marked.setOptions { smartypants: true }
lexed = marked.lexer source
meta = readMeta(lexed.shift().text, new marked.InlineLexer lexed.links)
separators = if meta.Separator \
then [meta.Separator] else ['heading', 'hr']
+7 -7
View File
@@ -3,10 +3,10 @@ angular.module("sideBySide").service "route", ['$location', ($location) ->
.split '/'
.filter (item) -> item
.map (item) -> item.split ':'
.reduce((params, param) ->
.reduce (params, param) ->
key = param.shift()
if (param.length > 1)
if param.length > 1
value = {}
value[param[0]] = param[1].split ','
else
@@ -14,7 +14,7 @@ angular.module("sideBySide").service "route", ['$location', ($location) ->
params[key] = value
params
, {})
, {}
@params.base = '' if 'base' not of @params
@@ -22,18 +22,18 @@ angular.module("sideBySide").service "route", ['$location', ($location) ->
.substring(0, $location.absUrl().length - $location.url().length)
getValue = (value) ->
if (typeof value == 'object')
if typeof value == 'object'
for key, val of value
# only works for one key...
return key + ":" + val.join(',')
return key + ":" + val.join ','
value
@get = () ->
@get = ->
['base', 'display', 'section']
.filter (key) => @params[key]
.map (key) =>
key + ':' + getValue @params[key]
.join('/')
.join '/'
@update = (key, value) ->
@params[key] = value
@@ -1,4 +1,4 @@
angular.module("sideBySide").factory("transformer", () ->
angular.module("sideBySide").factory("transformer", ->
# Transform translations
#
# @param translations [Array] Translations with 'meta' and 'content' keys
@@ -26,8 +26,8 @@ angular.module("sideBySide").factory("transformer", () ->
details = []
while _.size(_.compact(lengths)) > 1
mindex = _.indexOf(lengths, _.min(lengths))
maxdex = _.indexOf(lengths, _.max(lengths))
mindex = _.indexOf(lengths, _.min lengths)
maxdex = _.indexOf(lengths, _.max lengths)
# least occuring count is higher than most occuring count
message = if mindex > maxdex \
@@ -41,7 +41,7 @@ angular.module("sideBySide").factory("transformer", () ->
return "'" + _.last(translation.content).text + "'"
)
details.push(message + lastVerses.join(", "))
details.push message + lastVerses.join ", "
# remove least occuring from lengths
delete lengths[mindex]
@@ -50,7 +50,7 @@ angular.module("sideBySide").factory("transformer", () ->
uneven.join(", ") + "." +
" (" + details.join("; ") + ")."
checkLengths(translations)
checkLengths translations
data = {
meta: (translation.meta for translation in translations)