Skip to content

Commit fd24f09

Browse files
committed
Adding Xpark project to core Spark.sln
Moving this out of the Samples.sln enables Xpark.exe to be part of the bin release zip.
1 parent 650597a commit fd24f09

File tree

13 files changed

+931
-0
lines changed

13 files changed

+931
-0
lines changed

src/Spark.sln

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
4343
..\spark.build = ..\spark.build
4444
EndProjectSection
4545
EndProject
46+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Utilities", "Utilities", "{8D3C4016-6843-4266-BA52-61D0A2C78880}"
47+
EndProject
48+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xpark", "Xpark\Xpark.csproj", "{4E7C0DEF-11F1-44C6-8CE0-198CD8FB8AB9}"
49+
EndProject
4650
Global
4751
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4852
Debug|Any CPU = Debug|Any CPU
@@ -113,6 +117,10 @@ Global
113117
{AE1175DE-6388-472B-92EB-907A1C45E541}.Debug|Any CPU.Build.0 = Debug|Any CPU
114118
{AE1175DE-6388-472B-92EB-907A1C45E541}.Release|Any CPU.ActiveCfg = Release|Any CPU
115119
{AE1175DE-6388-472B-92EB-907A1C45E541}.Release|Any CPU.Build.0 = Release|Any CPU
120+
{4E7C0DEF-11F1-44C6-8CE0-198CD8FB8AB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
121+
{4E7C0DEF-11F1-44C6-8CE0-198CD8FB8AB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
122+
{4E7C0DEF-11F1-44C6-8CE0-198CD8FB8AB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
123+
{4E7C0DEF-11F1-44C6-8CE0-198CD8FB8AB9}.Release|Any CPU.Build.0 = Release|Any CPU
116124
EndGlobalSection
117125
GlobalSection(SolutionProperties) = preSolution
118126
HideSolutionNode = FALSE
@@ -134,5 +142,6 @@ Global
134142
{92156FC5-8ECF-4A52-B4CA-AE060DCAAD18} = {F4E1F2B2-2BA6-4EFC-8082-ADBC14ECC179}
135143
{92D6EEC2-FFE5-48E5-BFE1-D5C6D2F48D90} = {F4E1F2B2-2BA6-4EFC-8082-ADBC14ECC179}
136144
{AE1175DE-6388-472B-92EB-907A1C45E541} = {F4E1F2B2-2BA6-4EFC-8082-ADBC14ECC179}
145+
{4E7C0DEF-11F1-44C6-8CE0-198CD8FB8AB9} = {8D3C4016-6843-4266-BA52-61D0A2C78880}
137146
EndGlobalSection
138147
EndGlobal

src/Xpark/Program.cs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Xml;
7+
using System.Xml.Linq;
8+
using Spark;
9+
using Spark.FileSystem;
10+
11+
namespace Xpark
12+
{
13+
class Program
14+
{
15+
static void Main(string[] args)
16+
{
17+
if (args.Length == 0)
18+
{
19+
Console.Write(@"
20+
Transforms Xml using a Spark template
21+
22+
XPARK templatefile [inputfile [outputfile]]
23+
24+
templatefile Path to a .spark file.
25+
inputfile Source xml. Path to an file or url for http GET.
26+
outputfile Target file to receive template output.
27+
28+
If inputfile or outputfile are not provided stdin and stdout are used.
29+
30+
The Model in the template is an XDocument loaded from the source.
31+
32+
The templatefile location may also contain _partial.spark files, and
33+
a _global.spark file with common namespaces, macros, etc.
34+
");
35+
return;
36+
}
37+
38+
// Find the full path to the template file,
39+
// using current directory if argument isn't fully qualified
40+
var templatePath = Path.Combine(Environment.CurrentDirectory, args[0]);
41+
var templateName = Path.GetFileName(templatePath);
42+
var templateDirPath = Path.GetDirectoryName(templatePath);
43+
44+
var viewFolder = new FileSystemViewFolder(templateDirPath);
45+
46+
// Create an engine using the templates path as the root location
47+
// as well as the shared location
48+
var engine = new SparkViewEngine
49+
{
50+
DefaultPageBaseType = typeof(SparkView).FullName,
51+
ViewFolder = viewFolder.Append(new SubViewFolder(viewFolder, "Shared"))
52+
};
53+
54+
SparkView view;
55+
// compile and instantiate the template
56+
view = (SparkView)engine.CreateInstance(
57+
new SparkViewDescriptor()
58+
.AddTemplate(templateName));
59+
60+
61+
// load the second argument, or default to reading stdin
62+
if (args.Length >= 2)
63+
view.Model = XDocument.Load(args[1]);
64+
else
65+
view.Model = XDocument.Load(XmlReader.Create(Console.OpenStandardInput()));
66+
67+
68+
// write out to the third argument, or default to writing stdout
69+
if (args.Length >= 3)
70+
{
71+
using (var writer = new StreamWriter(new FileStream(args[2], FileMode.Create), Encoding.UTF8))
72+
{
73+
view.RenderView(writer);
74+
}
75+
}
76+
else
77+
{
78+
using (var writer = new StreamWriter(Console.OpenStandardOutput(), Encoding.UTF8))
79+
{
80+
view.RenderView(writer);
81+
}
82+
}
83+
}
84+
}
85+
}

src/Xpark/Properties/AssemblyInfo.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Xpark")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Xpark")]
13+
[assembly: AssemblyCopyright("Copyright © 2009")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("9c9500dd-3487-4e3e-b98a-e417ee0aab34")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

src/Xpark/SparkView.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Xml.Linq;
2+
using Spark;
3+
using System.Xml.XPath ;
4+
5+
namespace Xpark
6+
{
7+
public abstract class SparkView : AbstractSparkView
8+
{
9+
public XDocument Model { get; set; }
10+
}
11+
}

src/Xpark/Xpark.csproj

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>9.0.30729</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{4E7C0DEF-11F1-44C6-8CE0-198CD8FB8AB9}</ProjectGuid>
9+
<OutputType>Exe</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>Xpark</RootNamespace>
12+
<AssemblyName>Xpark</AssemblyName>
13+
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<ItemGroup>
34+
<Reference Include="System" />
35+
<Reference Include="System.Core">
36+
<RequiredTargetFramework>3.5</RequiredTargetFramework>
37+
</Reference>
38+
<Reference Include="System.Xml.Linq">
39+
<RequiredTargetFramework>3.5</RequiredTargetFramework>
40+
</Reference>
41+
<Reference Include="System.Data.DataSetExtensions">
42+
<RequiredTargetFramework>3.5</RequiredTargetFramework>
43+
</Reference>
44+
<Reference Include="System.Data" />
45+
<Reference Include="System.Xml" />
46+
</ItemGroup>
47+
<ItemGroup>
48+
<Compile Include="Program.cs" />
49+
<Compile Include="Properties\AssemblyInfo.cs" />
50+
<Compile Include="SparkView.cs" />
51+
</ItemGroup>
52+
<ItemGroup>
53+
<None Include="XparkSamples\diggstyle.css">
54+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
55+
</None>
56+
<None Include="XparkSamples\Spark.Tests.dll-results.xml">
57+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
58+
</None>
59+
<None Include="XparkSamples\stories.xml">
60+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
61+
</None>
62+
<None Include="XparkSamples\TestStyle.css">
63+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
64+
</None>
65+
</ItemGroup>
66+
<ItemGroup>
67+
<None Include="XparkSamples\DiggStories.spark">
68+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
69+
</None>
70+
<None Include="XparkSamples\go.cmd">
71+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
72+
</None>
73+
<None Include="XparkSamples\TestResults.spark">
74+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
75+
</None>
76+
<None Include="XparkSamples\_global.spark">
77+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
78+
</None>
79+
</ItemGroup>
80+
<ItemGroup>
81+
<ProjectReference Include="..\Spark\Spark.csproj">
82+
<Project>{31929D34-1A68-4A6B-9D8A-B93037163A5A}</Project>
83+
<Name>Spark</Name>
84+
</ProjectReference>
85+
</ItemGroup>
86+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
87+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
88+
Other similar extension points exist, see Microsoft.Common.targets.
89+
<Target Name="BeforeBuild">
90+
</Target>
91+
<Target Name="AfterBuild">
92+
</Target>
93+
-->
94+
</Project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+

2+
<var results="
3+
from s in Model.Elements('stories').Elements('story')
4+
select new {
5+
link = (string)s.Attribute('link'),
6+
title = (string)s.Element('title'),
7+
description = (string)s.Element('description'),
8+
thumbnail = s.Elements('thumbnail').Any() ? new {
9+
src = (string)s.Element('thumbnail').Attribute('src')
10+
} : null
11+
}"/>
12+
13+
<html>
14+
<head>
15+
<title>Top Stories</title>
16+
<style type="text/css">
17+
<include href="diggstyle.css" parse="text"/>
18+
</style>
19+
</head>
20+
<body>
21+
<div each="var story in results" class="story">
22+
<h3><a href="!{story.link}">${story.title}</a></h3>
23+
<p>
24+
<img if="story.thumbnail != null" src="!{story.thumbnail.src}" class="thumbnail"/>
25+
${story.description}
26+
</p>
27+
</div>
28+
</body>
29+
</html>

0 commit comments

Comments
 (0)