forked from marcemarc/monosnow.umbraco.uCssClassNameDropdown
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9093315
Showing
23 changed files
with
1,881 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto | ||
|
||
# Custom for Visual Studio | ||
*.cs diff=csharp | ||
*.sln merge=union | ||
*.csproj merge=union | ||
*.vbproj merge=union | ||
*.fsproj merge=union | ||
*.dbproj merge=union | ||
|
||
# Standard to msysgit | ||
*.doc diff=astextplain | ||
*.DOC diff=astextplain | ||
*.docx diff=astextplain | ||
*.DOCX diff=astextplain | ||
*.dot diff=astextplain | ||
*.DOT diff=astextplain | ||
*.pdf diff=astextplain | ||
*.PDF diff=astextplain | ||
*.rtf diff=astextplain | ||
*.RTF diff=astextplain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
################# | ||
## Eclipse | ||
################# | ||
|
||
*.pydevproject | ||
.project | ||
.metadata | ||
bin/ | ||
tmp/ | ||
*.tmp | ||
*.bak | ||
*.swp | ||
*~.nib | ||
local.properties | ||
.classpath | ||
.settings/ | ||
.loadpath | ||
|
||
# External tool builders | ||
.externalToolBuilders/ | ||
|
||
# Locally stored "Eclipse launch configurations" | ||
*.launch | ||
|
||
# CDT-specific | ||
.cproject | ||
|
||
# PDT-specific | ||
.buildpath | ||
|
||
|
||
################# | ||
## Visual Studio | ||
################# | ||
|
||
## Ignore Visual Studio temporary files, build results, and | ||
## files generated by popular Visual Studio add-ons. | ||
|
||
# User-specific files | ||
*.suo | ||
*.user | ||
*.sln.docstates | ||
|
||
# Build results | ||
[Dd]ebug/ | ||
[Rr]elease/ | ||
*_i.c | ||
*_p.c | ||
*.ilk | ||
*.meta | ||
*.obj | ||
*.pch | ||
*.pdb | ||
*.pgc | ||
*.pgd | ||
*.rsp | ||
*.sbr | ||
*.tlb | ||
*.tli | ||
*.tlh | ||
*.tmp | ||
*.vspscc | ||
.builds | ||
*.dotCover | ||
|
||
## TODO: If you have NuGet Package Restore enabled, uncomment this | ||
#packages/ | ||
|
||
# Visual C++ cache files | ||
ipch/ | ||
*.aps | ||
*.ncb | ||
*.opensdf | ||
*.sdf | ||
|
||
# Visual Studio profiler | ||
*.psess | ||
*.vsp | ||
|
||
# ReSharper is a .NET coding add-in | ||
_ReSharper* | ||
|
||
# Installshield output folder | ||
[Ee]xpress | ||
|
||
# DocProject is a documentation generator add-in | ||
DocProject/buildhelp/ | ||
DocProject/Help/*.HxT | ||
DocProject/Help/*.HxC | ||
DocProject/Help/*.hhc | ||
DocProject/Help/*.hhk | ||
DocProject/Help/*.hhp | ||
DocProject/Help/Html2 | ||
DocProject/Help/html | ||
|
||
# Click-Once directory | ||
publish | ||
|
||
# Others | ||
[Bb]in | ||
[Oo]bj | ||
sql | ||
TestResults | ||
*.Cache | ||
ClientBin | ||
stylecop.* | ||
~$* | ||
*.dbmdl | ||
Generated_Code #added for RIA/Silverlight projects | ||
|
||
# Backup & report files from converting an old project file to a newer | ||
# Visual Studio version. Backup files are not needed, because we have git ;-) | ||
_UpgradeReport_Files/ | ||
Backup*/ | ||
UpgradeLog*.XML | ||
|
||
|
||
|
||
############ | ||
## Windows | ||
############ | ||
|
||
# Windows image file caches | ||
Thumbs.db | ||
|
||
# Folder config file | ||
Desktop.ini | ||
|
||
|
||
############# | ||
## Python | ||
############# | ||
|
||
*.py[co] | ||
|
||
# Packages | ||
*.egg | ||
*.egg-info | ||
dist | ||
build | ||
eggs | ||
parts | ||
bin | ||
var | ||
sdist | ||
develop-eggs | ||
.installed.cfg | ||
|
||
# Installer logs | ||
pip-log.txt | ||
|
||
# Unit test / coverage reports | ||
.coverage | ||
.tox | ||
|
||
#Translations | ||
*.mo | ||
|
||
#Mr Developer | ||
.mr.developer.cfg | ||
|
||
# Mac crap | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("monosnow.umbraco.uCssClassNameDropdown")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("monosnow.umbraco.uCssClassNameDropdown")] | ||
[assembly: AssemblyCopyright("Copyright © 2013")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("37222f19-810f-42fc-b5a8-169d37b70c40")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Revision and Build Numbers | ||
// by using the '*' as shown below: | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
monosnow.umbraco.uCssClassNameDropdown | ||
========= | ||
|
||
Umbraco datatype to build a dropdown of Css Class names selected from a css file using a regex | ||
Also control to display font-awesome icons, to help editor pick class name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.IO; | ||
using System.Web; | ||
using System.Runtime.Caching; | ||
|
||
namespace monosnow.umbraco.uCssClassNameDropdown.Services | ||
{ | ||
/// <summary> | ||
/// Service responsible for applying the regex and retrieving the class names | ||
/// </summary> | ||
public class ClassNameRetrievalService | ||
{ | ||
private string _pathToCss = "/css/font-awesome.css"; | ||
private string _exceptions = "large"; | ||
private string _cssClassRegEx = @"\.icon-([^:]*?):before"; | ||
public ClassNameRetrievalService() | ||
{ | ||
|
||
|
||
} | ||
/// <summary> | ||
/// Checks if filename exists | ||
/// </summary> | ||
public Boolean CssFileExists { get { return (File.Exists(HttpContext.Current.Server.MapPath(_pathToCss))); } } | ||
|
||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
/// <param name="pathToCss">path to Css File Name</param> | ||
public ClassNameRetrievalService(string pathToCss) | ||
{ | ||
_pathToCss = String.IsNullOrEmpty(pathToCss) ? _pathToCss : pathToCss; ; | ||
|
||
} | ||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
/// <param name="pathToCss">Path to Css File name</param> | ||
/// <param name="exceptions">List of classes to ignore</param> | ||
public ClassNameRetrievalService(string pathToCss, string exceptions) | ||
{ | ||
|
||
_pathToCss = String.IsNullOrEmpty(pathToCss) ? _pathToCss : pathToCss; | ||
_exceptions = String.IsNullOrEmpty(exceptions) ? _exceptions : exceptions; | ||
|
||
} | ||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
/// <param name="pathToCss">Path to Css File name</param> | ||
/// <param name="exceptions">List of classes to ignore</param> | ||
/// <param name="cssClassRegEx">Regex to match classnames, first capture group is the text used</param> | ||
public ClassNameRetrievalService(string pathToCss, string exceptions, string cssClassRegEx) | ||
{ | ||
_pathToCss = String.IsNullOrEmpty(pathToCss) ? _pathToCss : pathToCss; ; | ||
_cssClassRegEx = String.IsNullOrEmpty(cssClassRegEx) ? _cssClassRegEx : cssClassRegEx; | ||
_exceptions = String.IsNullOrEmpty(exceptions) ? _exceptions : exceptions; | ||
|
||
} | ||
/// <summary> | ||
/// Method to get the CssClass names from the file by applying the regex | ||
/// </summary> | ||
/// <returns>An enumeration of class names</returns> | ||
public IEnumerable<string> GetClassNames() | ||
{ | ||
string cssContents = getCssFileContents(); | ||
// use regex to find all the class names | ||
List<string> _cssClassNames = new List<string>(); | ||
|
||
// Define a regular expression for repeated words. | ||
Regex rx = new Regex(_cssClassRegEx, | ||
RegexOptions.Compiled | RegexOptions.IgnoreCase); | ||
|
||
// Find matches. | ||
MatchCollection matches = rx.Matches(cssContents); | ||
string[] exceptions = _exceptions.Split(new char[]{'|',','},StringSplitOptions.RemoveEmptyEntries); | ||
// loop through all the matches | ||
foreach (Match match in matches) | ||
{ | ||
// read in the first capture group of the matching text | ||
string _matchingText = match.Groups[1].Value.Trim(); | ||
// check class is longer that 2 chars and not in the exception list and not already in the list of matched css names | ||
if (_matchingText.Length > 2 && !exceptions.Contains(_matchingText.ToLower()) && !_cssClassNames.Contains(_matchingText)) | ||
{ | ||
_cssClassNames.Add(_matchingText); | ||
} | ||
} | ||
|
||
//sort the list alphabetically | ||
_cssClassNames.Sort(); | ||
return _cssClassNames; | ||
|
||
} | ||
/// <summary> | ||
/// method to read the contents of the css file from disc | ||
/// contents are added to server cache, and cache is attempted to be read first | ||
/// until file changes. | ||
/// </summary> | ||
/// <returns>string containing contents of css file</returns> | ||
private string getCssFileContents() | ||
{ | ||
string cssContents = String.Empty; | ||
if (this.CssFileExists) | ||
{ | ||
ObjectCache cache = MemoryCache.Default; | ||
cssContents = (string)cache[_pathToCss + "CssFileContents"]; | ||
if (String.IsNullOrEmpty(cssContents)) | ||
{ | ||
if (File.Exists(HttpContext.Current.Server.MapPath(_pathToCss))) | ||
{ | ||
StreamReader cssFileStream = new StreamReader(HttpContext.Current.Server.MapPath(_pathToCss)); | ||
cssContents = cssFileStream.ReadToEnd(); | ||
cssFileStream.Close(); | ||
if (!String.IsNullOrEmpty(cssContents)) | ||
{ | ||
CacheItemPolicy policy = new CacheItemPolicy(); | ||
|
||
List<string> filePaths = new List<string>(); | ||
filePaths.Add(HttpContext.Current.Server.MapPath(_pathToCss)); | ||
|
||
policy.ChangeMonitors.Add(new | ||
HostFileChangeMonitor(filePaths)); | ||
|
||
|
||
cache.Add(_pathToCss + "CssFileContents", cssContents, policy); | ||
} | ||
} | ||
} | ||
|
||
} | ||
return cssContents; | ||
|
||
} | ||
|
||
} | ||
} | ||
|
||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.