Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
Set cookie for first visit.
convert tabs to space in data
Better error handling for render
  • Loading branch information
bthornto committed Nov 28, 2017
1 parent f2de2b5 commit 85da8b4
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 33 deletions.
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"Split.js": "^1.3.5",
"angular-ui-codemirror": "^0.3.0",
"ng-split": "^0.2.0",
"angular-material": "^1.1.5"
"angular-material": "^1.1.5",
"angular-cookies": "^1.6.7"
}
}
28 changes: 19 additions & 9 deletions td4a/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,27 @@ def render_template(data, template):
env.filters[entry[0]] = entry[1]
result = env.from_string(template).render(data)
return None, result
except (TemplateAssertionError, TypeError, jinja2.UndefinedError), error:
except Exception, error:
tback = traceback.extract_tb(sys.exc_traceback)
template_error = next(x for x in tback if re.search('^<.*>$', x[0]))
return {"Error":
{
"in": "template",
"title": "Issue found while rendering template.",
"line_number": template_error[1],
"details": str(error)
}
}, None
if template_error:
return {"Error":
{
"in": "template",
"title": "Issue found while rendering template.",
"line_number": template_error[1],
"details": str(error)
}
}, None
else:
return {"Error":
{
"in": "unknown",
"title": "Unexpected error occured.",
"line_number": 'unknown',
"details": "Please see the console for details."
}
}, None

def load_data(str_data):
""" load yaml from string
Expand Down
56 changes: 34 additions & 22 deletions td4a/static/js/app.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
var app = angular.module('mainController', ['ngRoute', 'ngMaterial', 'ngMessages', 'ui.codemirror', 'ng-split']);
var app = angular.module('mainController', ['ngRoute', 'ngMaterial', 'ngMessages', 'ui.codemirror', 'ng-split', 'ngCookies']);

app.config(function($routeProvider,$locationProvider) {
$locationProvider.html5Mode(true);
})

app.controller('main', function($scope, $http, $window, $mdToast, $routeParams, $location) {
app.controller('main', function($scope, $http, $window, $mdToast, $routeParams, $location, $cookies) {
$scope.error = {}
$scope.template = { data: '', jinja: '' }
$scope.renderButton = false;
$scope.showDemo = $cookies.firstVisit || "";
$scope.codemirror = {
dataOptions:
{
lineNumbers: true,
theme:'material',
lineWrapping : true,
mode: 'yaml',
indentUnit: 2,
tabSize: 2,
extraKeys: {
Tab: function(cm) {
var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
cm.replaceSelection(spaces);
}
}
},
templateOptions:
{
lineNumbers: true,
theme:'material',
lineWrapping : true,
mode: 'jinja2',
mode: 'jinja2'
},
resultOptions:
{
Expand All @@ -31,25 +40,28 @@ app.controller('main', function($scope, $http, $window, $mdToast, $routeParams,
mode: 'yaml',
}
}

$http({
method : 'GET',
url : 'data.yml',
})
.then(function(response) {
if (response.status == 200) {
$scope.template.data = response.data
}
})
$http({
method : 'GET',
url : 'template.j2',
})
.then(function(response) {
if (response.status == 200) {
$scope.template.jinja = response.data
}
})
$scope.demoShown = $cookies.get('demoShown') || false;
if (!($scope.demoShown)) {
$cookies.put('demoShown',true);
$http({
method : 'GET',
url : 'data.yml',
})
.then(function(response) {
if (response.status == 200) {
$scope.template.data = response.data
}
})
$http({
method : 'GET',
url : 'template.j2',
})
.then(function(response) {
if (response.status == 200) {
$scope.template.jinja = response.data
}
})
}

$scope.render = function() {
$scope.renderButton = true;
Expand Down
2 changes: 1 addition & 1 deletion td4a/static/js/main.min.js

Large diffs are not rendered by default.

0 comments on commit 85da8b4

Please sign in to comment.