Added SupportedUIExtensions to IMacroEngine

This commit is contained in:
Elijah
2011-02-16 01:48:40 -11:00
parent 3d5ed109af
commit ce83c8a1b9
6 changed files with 53 additions and 78 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using umbraco.cms.businesslogic.macro;
using umbraco.interfaces;
@@ -11,47 +12,37 @@ namespace umbraco.MacroEngines
{
#region IMacroEngine Members
public virtual string Name
{
public virtual string Name {
get { return "Umbraco DLR Macro Engine"; }
}
public virtual List<string> SupportedExtensions
{
get
{
var exts = new List<string> { "py", "rb" };
return exts;
}
public virtual IEnumerable<string> SupportedExtensions {
get { return new [] {"py", "rb"}; }
}
public virtual Dictionary<string, IMacroGuiRendering> SupportedProperties
{
public IEnumerable<string> SupportedUIExtensions {
get { return SupportedExtensions; }
}
public virtual Dictionary<string, IMacroGuiRendering> SupportedProperties {
get { throw new NotImplementedException(); }
}
public virtual bool Validate(string code, string filePath, INode currentPage, out string errorMessage) {
errorMessage = string.Empty;
return true;
}
public virtual string Execute(MacroModel macro, INode currentPage)
{
string fileEnding = macro.ScriptName.Substring(macro.ScriptName.LastIndexOf('.')).Trim('.');
MacroScriptEngine mse = MacroScriptEngine.LoadEngineByFileExtension(fileEnding);
var vars = new SortedDictionary<string, object>
{
public virtual string Execute(MacroModel macro, INode currentPage) {
var fileEnding = macro.ScriptName.Substring(macro.ScriptName.LastIndexOf('.')).Trim('.');
var mse = MacroScriptEngine.LoadEngineByFileExtension(fileEnding);
var vars = new SortedDictionary<string, object> {
{"currentPage", new DynamicNode(currentPage)}
};
foreach (MacroPropertyModel prop in macro.Properties)
{
foreach (var prop in macro.Properties) {
vars.Add(prop.Key, prop.Value);
}
mse.ScriptVariables = vars;
return mse.ExecuteFile(IOHelper.MapPath(SystemDirectories.Python + "/" + macro.ScriptName));
}

View File

@@ -134,7 +134,9 @@ namespace umbraco.MacroEngines
public string Name { get { return "Razor Macro Engine"; } }
public List<string> SupportedExtensions { get { return new List<string> {"cshtml", "vbhtml", "razor"}; } }
public IEnumerable<string> SupportedExtensions { get { return new List<string> {"cshtml", "vbhtml", "razor"}; } }
public IEnumerable<string> SupportedUIExtensions { get { return new List<string> { "cshtml", "vbhtml" }; } }
public Dictionary<string, IMacroGuiRendering> SupportedProperties {
get { throw new NotSupportedException(); }

View File

@@ -1,17 +1,14 @@
using System;
using System.Collections;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Scripting.Hosting;
namespace umbraco.MacroEngines.Scripting
{
public class MacroScript
{
public static string Execute(string script, string scriptType, Hashtable variables)
{
MacroScriptEngine mse = new MacroScriptEngine(scriptType);
public class MacroScript {
public static string Execute(string script, string scriptType, Hashtable variables) {
var mse = new MacroScriptEngine(scriptType);
mse.ScriptVariables = ConvertHashTable(variables);
mse.Script = script;
return mse.Execute();
@@ -19,47 +16,38 @@ namespace umbraco.MacroEngines.Scripting
public static string Evaluate(string script, string scriptType, Hashtable variables)
{
MacroScriptEngine mse = new MacroScriptEngine(scriptType);
var mse = new MacroScriptEngine(scriptType);
mse.ScriptVariables = ConvertHashTable(variables);
mse.Script = script;
return mse.Evaluate();
}
public static string ExecuteFile(string path, Hashtable variables)
{
string fileEnding = path.Substring(path.LastIndexOf('.')).Trim('.');
MacroScriptEngine mse = MacroScriptEngine.LoadEngineByFileExtension(fileEnding);
public static string ExecuteFile(string path, Hashtable variables) {
var fileEnding = path.Substring(path.LastIndexOf('.')).Trim('.');
var mse = MacroScriptEngine.LoadEngineByFileExtension(fileEnding);
mse.ScriptVariables = ConvertHashTable(variables);
return mse.ExecuteFile(path);
}
//friendly helpers....
public static string ExecutePython(string script, Hashtable variables)
{
public static string ExecutePython(string script, Hashtable variables) {
return Execute(script, "python", variables);
}
public static string ExecuteRuby(string script, Hashtable variables)
{
public static string ExecuteRuby(string script, Hashtable variables) {
return Execute(script, "ruby", variables);
}
private static SortedDictionary<string, object> ConvertHashTable(Hashtable ht)
{
SortedDictionary<string, object> retval = new SortedDictionary<string, object>();
foreach (DictionaryEntry de in ht)
{
private static SortedDictionary<string, object> ConvertHashTable(Hashtable ht) {
var retval = new SortedDictionary<string, object>();
foreach (DictionaryEntry de in ht) {
retval.Add(de.Key.ToString(), de.Value);
}
return retval;
}
public static List<LanguageSetup> GetAvailableLanguages()
{
return ScriptRuntimeSetup.ReadConfiguration().LanguageSetups.ToList<LanguageSetup>();
public static List<LanguageSetup> GetAvailableLanguages() {
return ScriptRuntimeSetup.ReadConfiguration().LanguageSetups.ToList();
}
}
}

View File

@@ -6,21 +6,11 @@ using umbraco.interfaces;
namespace umbraco.cms.businesslogic.macro
{
public interface IMacroEngine
{
string Name
{
get;
}
List<string> SupportedExtensions
{
get;
}
Dictionary<string, IMacroGuiRendering> SupportedProperties
{
get;
}
public interface IMacroEngine {
string Name { get; }
IEnumerable<string> SupportedExtensions { get; }
IEnumerable<string> SupportedUIExtensions { get; }
Dictionary<string, IMacroGuiRendering> SupportedProperties { get; }
bool Validate(string code, string tempFileName, INode currentPage, out string errorMessage);
string Execute(MacroModel macro, INode currentPage);
}

View File

@@ -49,16 +49,23 @@ namespace umbraco.cms.businesslogic.macro
}
}
public static List<MacroEngineLanguage> GetSupportedLanguages()
{
List<MacroEngineLanguage> languages = new List<MacroEngineLanguage>();
foreach(IMacroEngine engine in GetAll())
{
public static IEnumerable<MacroEngineLanguage> GetSupportedLanguages() {
var languages = new List<MacroEngineLanguage>();
foreach(var engine in GetAll()) {
foreach(string lang in engine.SupportedExtensions)
if (languages.Find(t => t.Extension == lang) == null)
languages.Add(new MacroEngineLanguage(lang, engine.Name));
}
return languages;
}
public static IEnumerable<MacroEngineLanguage> GetSupportedUILanguages() {
var languages = new List<MacroEngineLanguage>();
foreach (var engine in GetAll()) {
foreach (string lang in engine.SupportedUIExtensions)
if (languages.Find(t => t.Extension == lang) == null)
languages.Add(new MacroEngineLanguage(lang, engine.Name));
}
return languages;
}
@@ -68,8 +75,7 @@ namespace umbraco.cms.businesslogic.macro
if (m_allEngines.Count == 0)
{
Initialize();
foreach (string name in m_engines.Keys)
{
foreach (string name in m_engines.Keys) {
m_allEngines.Add(GetEngine(name));
}
}

View File

@@ -23,10 +23,8 @@ namespace umbraco.presentation.create
protected void Page_Load(object sender, System.EventArgs e)
{
sbmt.Text = ui.Text("create");
if (!Page.IsPostBack)
{
foreach (MacroEngineLanguage lang in MacroEngineFactory.GetSupportedLanguages())
{
if (!Page.IsPostBack) {
foreach (MacroEngineLanguage lang in MacroEngineFactory.GetSupportedUILanguages()) {
filetype.Items.Add(new ListItem(string.Format("{0} by {1}", helper.SpaceCamelCasing(lang.Extension), lang.EngineName), lang.Extension));
}
filetype.SelectedIndex = 0;