Skip to content

Commit

Permalink
Only load theme that matches the provided theme name (#183)
Browse files Browse the repository at this point in the history
* theme start

* Only load theme that matches the provided theme name
  • Loading branch information
lesaltzm authored Mar 11, 2021
1 parent aa6ea5a commit 5ae10a0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 31 deletions.
5 changes: 3 additions & 2 deletions src/PAModel/Serializers/SourceSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ internal static partial class SourceSerializer
// 16 - Group Control transform
// 17 - Moved PublishOrderIndex entirely to Entropy
// 18 - AppChecker result is not part of entropy (See change 0.5 in this list)
// 19 - Switch extension to .fx.yaml
public static Version CurrentSourceVersion = new Version(0, 19);
// 19 - Switch extension to .fx.yaml
// 20 - Only load themes that match the specified theme name
public static Version CurrentSourceVersion = new Version(0, 20);

// Layout is:
// src\
Expand Down
66 changes: 37 additions & 29 deletions src/PAModel/Themes/Theme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

Expand All @@ -21,52 +22,59 @@ internal class Theme
public Theme(ThemesJson themeJson)
{
Contract.Assert(themeJson != null);

var currentThemeName = themeJson.CurrentTheme;
var namedThemes = themeJson.CustomThemes.ToDictionary(theme => theme.name);
if (namedThemes.TryGetValue(currentThemeName, out var foundTheme))
{
LoadTheme(foundTheme);
}

foreach (var theme in themeJson.CustomThemes)
}


private void LoadTheme(CustomThemeJson theme)
{
Dictionary<string, string> palleteRules = new Dictionary<string, string>();
foreach (var item in theme.palette)
{
Dictionary<string, string> palleteRules = new Dictionary<string, string>();
foreach(var item in theme.palette)
{
palleteRules[item.name] = item.value;
}
palleteRules[item.name] = item.value;
}

foreach (var style in theme.styles)
foreach (var style in theme.styles)
{
var styleName = style.name;
foreach (var prop in style.propertyValuesMap)
{
var styleName = style.name;
foreach (var prop in style.propertyValuesMap)
var propName = prop.property;
var ruleValue = prop.value;

// TODO - share with logic in D:\dev\pa2\PowerApps-Client\src\Cloud\DocumentServer.Core\Document\Document\Theme\ControlStyle.cs
// Resolve %%, from palette.
{
var propName = prop.property;
var ruleValue = prop.value;

// TODO - share with logic in D:\dev\pa2\PowerApps-Client\src\Cloud\DocumentServer.Core\Document\Document\Theme\ControlStyle.cs
// Resolve %%, from palette.
var match = Regex.Match(ruleValue, "%Palette.([^%]+)%");
if (match.Success)
{
var match = Regex.Match(ruleValue, "%Palette.([^%]+)%");
if (match.Success)
{
var group = match.Groups[1];
var group = match.Groups[1];



string resourceValue;
// Template may refer to a missing rule.
if (palleteRules.TryGetValue(group.ToString(), out resourceValue))
{
ruleValue = ruleValue.Replace(match.Value, resourceValue);
}
string resourceValue;
// Template may refer to a missing rule.
if (palleteRules.TryGetValue(group.ToString(), out resourceValue))
{
ruleValue = ruleValue.Replace(match.Value, resourceValue);
}
}
}

ruleValue = ControlTemplateParser.UnescapeReservedName(ruleValue);
ruleValue = ControlTemplateParser.UnescapeReservedName(ruleValue);

_styles.GetOrCreate(styleName).Add(propName, ruleValue);
}
_styles.GetOrCreate(styleName).Add(propName, ruleValue);
}
}
}



public bool TryLookup(string styleName, string propertyName, out string defaultScript)
{
if (_styles.TryGetValue(styleName, out var styles))
Expand Down

0 comments on commit 5ae10a0

Please sign in to comment.