RickStrahl / Snippets-MarkdownMonster-Addin

A Snippet Expansion Manager for embedding templated text into Markdown Monster Markdown documents
https://markdownmonster.west-wind.com
6 stars 3 forks source link

What type if ActiveDocument property? #1

Closed gep13 closed 7 years ago

gep13 commented 7 years ago

@RickStrahl Is it possible to just get the file name without the path and extension?

This is what I currently have in my snippet (based on a file called this-is-a-test.md)

---
Title: {{System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(Model.ActiveDocument.Filename.Replace('-', ' '))}}
Tags:
- 
---

Which results in the following:

image

So, quite close to what I am looking for 😄

RickStrahl commented 7 years ago

Like this?

---
Title: {{System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(System.IO.Path.GetFileNameWithoutExtension(Model.ActiveDocument.Filename).Replace('-', ' '))}}
Tags:
- 
---
RickStrahl commented 7 years ago

Ok... I made a few more changes to the @Razor hosting part that now allows adding assemblies and namespaces.

This is what you want:

@reference Westwind.Utilities.dll
@using Westwind.Utilities
@{
    var file = Path.GetFileNameWithoutExtension(Model.ActiveDocument.Filename);

    file = StringUtils.FromCamelCase(file);
    file = file.Replace("-"," ");
}---
Title: @file
Timestamp: @DateTime.Now.ToString("MMM dd, yyyy HH:mm")
Tags:
-
---

FWIW, the first two lines will not be necesary any more as I'm adding those as default dependencies.

You'll need to make sure you grab 1.10 of the addin though - update and restart.

gep13 commented 7 years ago

@RickStrahl thank you very much! This is perfect!

I modified it slightly:

@{
    var file = Path.GetFileNameWithoutExtension(Model.ActiveDocument.Filename);

    file = file.Replace("-"," ");
    file = StringUtils.ProperCase(file);
}---
Title: @file
Timestamp: @DateTime.Now.ToString("MMM dd, yyyy HH:mm")
Tags:
-
---