Skip to content

Commit

Permalink
Merge pull request #85 from bausshf/master
Browse files Browse the repository at this point in the history
Better error messages for views
  • Loading branch information
bausshf authored Apr 15, 2018
2 parents 839b056 + 44241ff commit 771c8f4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
6 changes: 4 additions & 2 deletions init/diamondapp.d
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ else

mixin GenerateViews;

import std.array : join;
mixin(generateViewsResult.join(""));
static foreach (viewResult; generateViewsResult)
{
mixin("#line 1 \"view: " ~ viewResult.name ~ "\"\n" ~ viewResult.source);
}

mixin GenerateGetView;

Expand Down
7 changes: 4 additions & 3 deletions init/web.d
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ static if (isWeb)
{
mixin GenerateViews;

import std.array : join;

mixin(generateViewsResult.join(""));
static foreach (viewResult; generateViewsResult)
{
mixin("#line 1 \"view: " ~ viewResult.name ~ "\"\n" ~ viewResult.source);
}

mixin GenerateGetView;
}
Expand Down
14 changes: 10 additions & 4 deletions views/viewgenerator.d
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@ static if (!isWebApi)
import diamond.core.webconfig;
import diamond.views.viewparser;

struct ViewResult
{
string name;
string source;
}

/**
* Generates the strings of the view classes to use with mixin.
* Returns:
* An array consisting of the generated classes of the views.
* The first element of the array is the routable data.
*/
private string[] generateViews()
private ViewResult[] generateViews()
{
string[] viewGenerations = [];
ViewResult[] viewGenerations = [];

string routableViewsMixin = "private static __gshared string[string] _routableViews;
@property string[string] routableViews()
Expand All @@ -40,7 +46,7 @@ static if (!isWebApi)
auto parts = parseTemplate(viewContent);

string route;
viewGenerations ~= parseViewParts(parts, viewName, route);
viewGenerations ~= ViewResult(viewName, parseViewParts(parts, viewName, route));

if (route && route.length)
{
Expand All @@ -52,7 +58,7 @@ static if (!isWebApi)
routableViewsMixin ~= "return _routableViews;
}";

return [routableViewsMixin] ~ viewGenerations;
return [ViewResult("__routes", routableViewsMixin)] ~ viewGenerations;
}

/// The result of the generated views.
Expand Down

0 comments on commit 771c8f4

Please sign in to comment.