Almost configurable base

This commit is contained in:
Vit Brunner
2014-11-11 09:09:01 +01:00
parent 81d5f664b8
commit 6c4a600270
9 changed files with 60 additions and 34 deletions
+6 -4
View File
@@ -1,6 +1,7 @@
doctype html
html(ng-app="sideBySide")
head
base(href='/')
title Side By Side viewer
meta(charset="utf-8")
link(rel="stylesheet", type="text/css", href="//fonts.googleapis.com/css?family=Noticia+Text:400,700,400italic,700italic")
@@ -21,10 +22,11 @@ html(ng-app="sideBySide")
.pure-menu.pure-menu-open.pure-menu-horizontal.menu-main
ul
li
a(href="#{{base}}") Home
a(href="") Home
li
a(href="#{{base}}/help") Help
a(href="help") Help
li
a(href="#{{base}}/about") About
a(href="about") About
div(ng-view class="cols-{{columns}}")
div(ng-controller="ComparisonController" class="cols-{{columns}}")
include includes/comparison.html.jade
+2 -5
View File
@@ -1,7 +1,4 @@
angular.module('sideBySide', ['sideBySide.controllers', 'ngRoute', 'ngSanitize'])
.config [ '$routeProvider', ($routeProvider) ->
$routeProvider.when '/:base?/:section?', {
templateUrl: 'partials/comparison.html'
controller: 'ComparisonController'
}
.config [ '$locationProvider', ($locationProvider) ->
$locationProvider.html5Mode true
]
+15 -11
View File
@@ -2,21 +2,25 @@ angular.module("sideBySide.controllers", [])
.controller "AppController", [
'$location', '$scope', 'poems'
($location, $scope, poems) ->
$scope.$on "$routeChangeSuccess", ($currentRoute, $previousRoute) ->
$scope.base = if $previousRoute.params.base \
then '/' + $previousRoute.params.base
else ''
urlParams = $location.url()
.split('/')
.filter((item) -> item)
.map (item) ->
item.split(':')
.reduce((prev, current) ->
prev[current[0]] = current[1]
prev
, {})
if 'base' of urlParams
urlParams.base = urlParams.base.replace(/\./g, '/')
else
urlParams.base = ''
appUrl = $location.absUrl()
.substring(0, $location.absUrl().length - $location.url().length)
.replace(/[^\/]*?#$/, '')
base = appUrl + $location.url()
.slice(1)
.replace(/(.*)\/.*/, '$1')
.replace(/\./g, '/')
poems.load base
poems.load appUrl + '/' + urlParams.base
]
.controller "ComparisonController", [
+4 -3
View File
@@ -1,12 +1,13 @@
angular.module("sideBySide").factory "fetch", ['$http', '$q', 'readerFactory', ($http, $q, readerFactory) ->
# Fetch
#
# @param file [String] Path to config file
# @param base [String] Path to config file directory
# @return [Object] Promises and heading
(file = "/config.json") ->
(base) ->
file = base + '/config.json'
$http.get(file).then (config) ->
promises = config.data.files.map (poem) ->
$http.get(poem).then (response) ->
$http.get(base + '/' + poem).then (response) ->
readerFactory(poem) response.data
{
+2 -2
View File
@@ -32,8 +32,8 @@ angular.module("sideBySide").service "poems", ['fetch', (fetch) ->
# Load poems
#
# @param base [String]
@load = (base = '') =>
fetch(base + "/config.json").then (config) =>
@load = (base) =>
fetch(base).then (config) =>
config.fetchPoems.then (poems) =>
@all = (activize(poem, config.active) for poem in poems)
@heading = config.heading
+7 -7
View File
@@ -1,12 +1,12 @@
{
"files":
[ "tests/the_raven/1845-poe.md"
, "tests/the_raven/1881-vrchlicky.md"
, "tests/the_raven/1885-muzik.md"
, "tests/the_raven/1918-dostal-lutinov.md"
, "tests/the_raven/1900-zenon-przesmycki.md"
, "tests/the_raven/1910-barbara-beaupre.md"
, "tests/the_raven/1970-baranczak.md"
[ "1845-poe.md"
, "1881-vrchlicky.md"
, "1885-muzik.md"
, "1918-dostal-lutinov.md"
, "1900-zenon-przesmycki.md"
, "1910-barbara-beaupre.md"
, "1970-baranczak.md"
],
"active": {
"Language": [ "Czech" ]