Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: tlbdk/MVC3TestApp
base: 9ebd805334
...
head fork: tlbdk/MVC3TestApp
compare: 1df94048cf
  • 2 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
175 ResourceHelper/HtmlHelperExtensions.cs
@@ -1,175 +0,0 @@
-using System;
-using System.Web.Mvc;
-using System.Web.WebPages;
-using System.Collections.Generic;
-using System.IO;
-using System.Web;
-using System.Globalization;
-using System.Configuration;
-using System.Linq;
-using System.Text.RegularExpressions;
-using System.Security.Cryptography;
-using System.Text;
-
-namespace MvcHtmlHelpers
-{
- public class HtmlResources
- {
- public List<string> Scripts;
- public List<string> Stylesheets;
-
- public bool Bundle = false;
- public bool Minify = false;
-
- public DateTime LatestScriptFile = DateTime.MinValue;
- public DateTime LatestCSSFile = DateTime.MinValue;
-
- public HtmlResources()
- {
- Scripts = new List<String>();
- Stylesheets = new List<String>();
- bool.TryParse(ConfigurationManager.AppSettings["ResourceBundle"], out Bundle);
- bool.TryParse(ConfigurationManager.AppSettings["ResourceMinify"], out Minify);
- }
- }
-
- public static class HtmlHelperExtensions
- {
- private const string scriptsFolder = "~/Scripts/"; // TODO: Get from somewhere else!
- private const string cssFolder = "~/Content/"; // TODO: Get from somewhere else!
-
- public static MvcHtmlString Resource(this HtmlHelper html, string value)
- {
- var server = html.ViewContext.RequestContext.HttpContext.Server;
- var resources = (HtmlResources)html.ViewData["Resources"];
- if (resources == null)
- {
- resources = new HtmlResources();
- html.ViewData["Resources"] = resources;
- }
-
- if (File.Exists(server.MapPath(value)))
- {
- FileInfo info = new FileInfo(server.MapPath(value));
- if (value.EndsWith(".js"))
- {
- if (!resources.Scripts.Contains(value))
- {
- // Note the latest date a file was changed.
- if (DateTime.Compare(resources.LatestScriptFile, info.LastWriteTime) < 0) {
- resources.LatestScriptFile = info.LastWriteTime;
- }
-
- // Minify the script file if necessary.
- if (resources.Minify)
- {
- string origname = info.Name.Substring(0, info.Name.LastIndexOf('.'));
- if (origname.EndsWith(".min"))
- {
- // The resource is pre-minified. Skip.
- resources.Scripts.Insert(0, value);
- }
- else if (File.Exists(server.MapPath(scriptsFolder + origname + ".min" + info.Extension)) && DateTime.Compare(File.GetLastWriteTime(server.MapPath(scriptsFolder + origname + ".min" + info.Extension)), info.LastWriteTime) >= 0)
- {
- if (DateTime.Compare(resources.LatestScriptFile, info.LastWriteTime) < 0) {
- resources.LatestScriptFile = File.GetLastWriteTime(server.MapPath(scriptsFolder + origname + ".min" + info.Extension));
- }
- // We have already minified the file. Skip.
- resources.Scripts.Insert(0, scriptsFolder + origname + ".min" + info.Extension);
- }
- else
- {
- // Minify file.
- string filename = scriptsFolder + origname + ".min" + info.Extension;
- File.WriteAllText(server.MapPath(filename), Yahoo.Yui.Compressor.JavaScriptCompressor.Compress(File.ReadAllText(server.MapPath(value))));
- resources.LatestScriptFile = File.GetLastWriteTime(server.MapPath(filename));
-
- // Insert the path to the minified file.
- resources.Scripts.Insert(0, filename);
- }
- }
- else
- {
- resources.Scripts.Insert(0, value);
- }
- }
- }
- else if (value.EndsWith(".css"))
- {
- if (!resources.Stylesheets.Contains(value))
- {
- // Note the latest date a file was changed.
- if (DateTime.Compare(resources.LatestCSSFile, info.LastWriteTime) < 0)
- resources.LatestCSSFile = info.LastWriteTime;
-
- resources.Stylesheets.Insert(0, value);
- }
- }
- }
- else
- {
- throw new FileNotFoundException(String.Format("Could not find file {0}", value), value);
- }
- return null;
- }
-
- public static MvcHtmlString RenderResources(this HtmlHelper html)
- {
- var url = new UrlHelper(html.ViewContext.RequestContext);
- var server = html.ViewContext.RequestContext.HttpContext.Server;
- var resources = (HtmlResources)html.ViewData["Resources"];
- string result = "";
-
- if (resources != null)
- {
- if (resources.Bundle)
- {
- // Get a hash of the files in question and generate a path.
- string scriptPath = scriptsFolder + BitConverter.ToString(new MD5CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(string.Join(";", resources.Scripts)))) + ".js";
- if (File.Exists(scriptPath) && DateTime.Compare(File.GetLastWriteTime(scriptPath), resources.LatestScriptFile) >= 0)
- {
- // We have already bundled the files.
- }
- else
- {
- foreach (string script in resources.Scripts)
- {
- File.AppendAllText(server.MapPath(scriptPath), File.ReadAllText(server.MapPath(script)));
- }
- }
- result += "<script src=\"" + url.Content(scriptPath) + "?" + String.Format("{0:yyyyddHHss}", File.GetLastWriteTime(scriptPath)) + "\" type=\"text/javascript\"></script>\n";
-
- // Get a hash of the files in question and generate a path.
- string cssPath = cssFolder + BitConverter.ToString(new MD5CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(string.Join(";", resources.Stylesheets)))) + ".css";
- if (File.Exists(cssPath) && DateTime.Compare(File.GetLastWriteTime(cssPath), resources.LatestCSSFile) >= 0)
- {
- // We have already bundled the files.
- }
- else
- {
- foreach (string stylesheet in resources.Stylesheets)
- {
- File.AppendAllText(server.MapPath(cssPath), File.ReadAllText(server.MapPath(stylesheet)));
- }
- }
- result += "<link href=\"" + url.Content(cssPath) + "?" + String.Format("{0:yyyyddHHss}", File.GetLastWriteTime(cssPath)) + "\" rel=\"stylesheet\" type=\"text/css\" />\n";
- }
- else
- {
- foreach (string resource in resources.Stylesheets)
- {
- DateTime dt = File.GetLastWriteTime(server.MapPath(resource));
- result += "<link href=\"" + url.Content(resource) + "?" + String.Format("{0:yyyyddHHss}", dt) + "\" rel=\"stylesheet\" type=\"text/css\" />\n";
- }
- foreach (string resource in resources.Scripts)
- {
- DateTime dt = File.GetLastWriteTime(server.MapPath(resource));
- result += "<script src=\"" + url.Content(resource) + "?" + String.Format("{0:yyyyddHHss}", dt) + "\" type=\"text/javascript\"></script>\n";
- }
- }
- }
-
- return MvcHtmlString.Create(result);
- }
- }
-}
View
62 ResourceHelper/ResourceHelper.csproj
@@ -1,62 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>8.0.30703</ProductVersion>
- <SchemaVersion>2.0</SchemaVersion>
- <ProjectGuid>{8BFC33B8-8A8D-458B-BFEE-692629502286}</ProjectGuid>
- <OutputType>Library</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>ResourceHelper</RootNamespace>
- <AssemblyName>ResourceHelper</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
- <FileAlignment>512</FileAlignment>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>bin\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin\Release\</OutputPath>
- <DefineConstants>TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="System" />
- <Reference Include="System.configuration" />
- <Reference Include="System.Core" />
- <Reference Include="System.Web" />
- <Reference Include="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
- <Reference Include="System.Web.Routing" />
- <Reference Include="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
- <Reference Include="System.Xml.Linq" />
- <Reference Include="System.Data.DataSetExtensions" />
- <Reference Include="Microsoft.CSharp" />
- <Reference Include="System.Data" />
- <Reference Include="System.Xml" />
- <Reference Include="Yahoo.Yui.Compressor">
- <HintPath>bin\Yahoo.Yui.Compressor.dll</HintPath>
- </Reference>
- </ItemGroup>
- <ItemGroup>
- <Compile Include="HtmlHelperExtensions.cs" />
- <Compile Include="Properties\AssemblyInfo.cs" />
- </ItemGroup>
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
- Other similar extension points exist, see Microsoft.Common.targets.
- <Target Name="BeforeBuild">
- </Target>
- <Target Name="AfterBuild">
- </Target>
- -->
-</Project>
View
BIN  ResourceHelper/bin/Yahoo.Yui.Compressor.dll
Binary file not shown
View
6 TestApp.sln
@@ -5,8 +5,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApp", "TestApp\TestApp.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApp.Tests", "TestApp.Tests\TestApp.Tests.csproj", "{976E4335-1F7C-4AAD-A42F-4F6C0E8920BD}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ResourceHelper", "ResourceHelper\ResourceHelper.csproj", "{8BFC33B8-8A8D-458B-BFEE-692629502286}"
-EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -21,10 +19,6 @@ Global
{976E4335-1F7C-4AAD-A42F-4F6C0E8920BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{976E4335-1F7C-4AAD-A42F-4F6C0E8920BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{976E4335-1F7C-4AAD-A42F-4F6C0E8920BD}.Release|Any CPU.Build.0 = Release|Any CPU
- {8BFC33B8-8A8D-458B-BFEE-692629502286}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {8BFC33B8-8A8D-458B-BFEE-692629502286}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {8BFC33B8-8A8D-458B-BFEE-692629502286}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {8BFC33B8-8A8D-458B-BFEE-692629502286}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
View
8 TestApp/TestApp.csproj
@@ -154,12 +154,6 @@
<ItemGroup>
<Content Include="packages.config" />
</ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\ResourceHelper\ResourceHelper.csproj">
- <Project>{8BFC33B8-8A8D-458B-BFEE-692629502286}</Project>
- <Name>ResourceHelper</Name>
- </ProjectReference>
- </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
@@ -190,4 +184,4 @@
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
-</Project>
+</Project>

No commit comments for this range

Something went wrong with that request. Please try again.