Skip to content

Commit

Permalink
# 0.1.1
Browse files Browse the repository at this point in the history
- More accurate extension descriptions
- Improvements to Sitecore extension snippets
- Verified and supplemented list of full extensions
- More links to documentation in auto-complete tooltips
- i_item extensions no longer erroneously appear as available options for fields auto completion.
  • Loading branch information
AdamNaj committed Dec 11, 2019
1 parent b466670 commit 770d1ca
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 111 deletions.
27 changes: 27 additions & 0 deletions .examples/Product Summary.scriban
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<div class="product-summary" data-id="{{ i_item.name }}">
{{ displayName = i_item.display_name | html.escape }}
<a title="{{ displayName }}" href="{{ i_item.url }}">
<div class="product-photo">
{{
productImage = i_item.images.targets | array.first
if productImage
mediaUrl = productImage.media_url
end
}}
<img src="{{ mediaUrl }}" />
</div>
</a>
<div class="product-info">
<a class="product-title" title="{{ displayName }}" href="{{ i_item.url }}">
{{ displayName }}
</a>
<div class="product-brand">
{{ i_item.brand }}
</div>
<div class="product-detail">
<a class="product-link" title="{{ displayName }}" href="{{ i_item.url }}">
{{ sc_translate 'DETAILS' }}
</a>
</div>
</div>
</div>
44 changes: 26 additions & 18 deletions .examples/gallery.scriban
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
{{- # ↓ Name of the item template -}}
{{ if i_item.template_name == "Gallery Image" }}
<a class="field-image">

{{- # ↓ Name of the item template -
if i_item.template_name == "Gallery Image"
sc_editframe i_item 'Gallery Image' -}}
<a class="field-image">

{{- # ↓ raw value from the field ↓ media url from a field -}}
<a title="{{ i_item.ImageTitle.raw }}" href="{{ i_item.Image.media_url }}">
<a title="{{ i_item.ImageTitle.raw }}" href="{{ i_item.Image.media_url }}">

{{- # ↓ item.FieldName - renders Sitecore field -}}
{{ i_item.Image }}
</a>
</a>
{{end}}
{{ i_item.Image }}

</a>
</a>{{
sc_endeditframe
end}}

{{- # ↓ conditional statement
if i_item.template_name == "Gallery Video"
sc_editframe i_item 'Gallery Video'
if (i_item.VideoID.raw ) == "" && (i_item.VideoThumbnail.raw) == "" -}}

{{- # ↓ conditional statement }}
{{ if i_item.template_name == "Gallery Video" }}
{{ if (i_item.VideoID.raw ) == "" && (i_item.VideoThumbnail.raw) == "" }}
<span>[Edit Gallery Video here]</span>
{{ else }}
<a title="{{i_item.VideoTitle.raw }}" href="http://www.youtube.com/watch?v={{ i_item.VideoID.raw }}">

{{- # ↓ access model properties }}
{{- else -}}

<a title="{{i_item.VideoTitle.raw }}" href="http://www.youtube.com/watch?v={{ i_item.VideoID.raw }}">
{{- # ↓ access model properties -}}

<img src="{{ o_model.thumbnail_url }}" alt="{{ i_item.VideoDescription.raw }}"
data-title="{{ i_item.VideoTitle.raw }}" data-description="{{ i_item.VideoDescription.raw }}" ></img>
</a>
{{end}}
{{end}}
</a>{{
end
sc_endeditframe
end }}
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Change Log

Sitecore Scriban Syntax Coloring and intellisense for known objects Extension for Visual Studio Code
Sitecore Experience Accelerator Scriban syntax coloring and auto completion for known objects - Extension for Visual Studio Code

## 1.0.0
## 0.1.1
- More accurate extension descriptions
- Improvements to Sitecore extension snippets
- Verified and supplemented list of full extensions
- More links to documentation in auto-complete tooltips
- i_item extensions no longer erroneously appear as available options for fields auto completion.

## 0.1.0
- Initial release
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
# Scriban Syntax Coloring extension for Visual Studio Code

This extension allows to colorize Scriban scripts and Scriban-Html scripts following the syntax of the [scriban templating language](https://github.com/lunet-io/scriban)
This extension allows to colorize Sitecore Experience Accelerator Scriban-Html scripts following the syntax of the [scriban templating language](https://github.com/lunet-io/scriban) with [SXA extensions](https://doc.sitecore.com/developers/sxa/93/sitecore-experience-accelerator/en/scriban-templates.html)

## Features

- Mixed **scriban and HTML** (using `{{` and `}}` to enter scriban) with the expected file extensions:
- `.scriban`
- Mixed **Scriban and HTML** (using `{{` and `}}` to enter scriban) with the `.scriban` file extension.
- Supports auto complete for Scriban language auto complete including embedded objects.
- Supports auto complete for OOTB Sitecore Experience Accelerator functions and objects.

## 0.1.1
- More accurate extension descriptions
- Improvements to snippets
- Descriptions synchonized with the documentation
- Verified and supplemented list of full extensions
- More links to documentation in auto-complete tooltips
- i_item extensions no longer erroneously appear as available options for fields auto completion.

## 0.1.0
- Support for mixed `Scriban` and `HTML` grammar
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "sitecore-scriban",
"displayName": "Sitecore Scriban",
"description": "Syntax Coloring for Scriban Templating Language with Sitecore Extensions",
"version": "0.1.0",
"description": "Scriban Templates syntax coloring and auto completion for Sitecore Experience Accelerator (SXA)",
"version": "0.1.1",
"publisher": "adamnaj",
"repository": {
"type": "git",
Expand Down
21 changes: 15 additions & 6 deletions src/autoCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { languageObjects } from './languageObjects';
import { methods, embeddedItemCompletions } from './sitecoreObjects';
import { sitecoreFunctions } from './sitecoreFunctions';
import { language } from './languageSyntax';
import { isInFunctionCompletion, codeBlockFromTemplate, stripFunctionNameFromLine, isInScriban } from './regularExpressions';
import { isInFunctionCompletion, codeBlockFromTemplate, stripFunctionNameFromLine } from './regularExpressions';
import { snippetCompletion, objectFunctionCompletion } from './autoCompletionItem';

const documentStart = new vscode.Position(0, 0);
Expand Down Expand Up @@ -55,10 +55,10 @@ export function provideGlobalCompletionItems(document: vscode.TextDocument, posi
}

// sitecore functions: sc_field, sc_translate ...
snippetCompletion(sitecoreFunctions, linePrefix, results, vscode.CompletionItemKind.Function);
snippetCompletion(sitecoreFunctions, linePrefix, results, vscode.CompletionItemKind.Function, "https://doc.sitecore.com/developers/sxa/93/sitecore-experience-accelerator/en/the-embedded-functions-for-the-scriban-template.html");

//language structures: for, while, if ...
snippetCompletion(language, linePrefix, results, vscode.CompletionItemKind.Snippet);
snippetCompletion(language, linePrefix, results, vscode.CompletionItemKind.Snippet, "https://github.com/lunet-io/scriban/blob/master/doc/language.md");

}
return results;
Expand All @@ -68,7 +68,8 @@ export function provideFunctionCompletionItems(document: vscode.TextDocument, po

// all text from beginning of the document to cursor position
let documentPrefix = document.getText(new vscode.Range(documentStart, position))

const isInScriban = new RegExp(/[{]([^}]+)$/g);

if (!isInScriban.test(documentPrefix)) {
return;
}
Expand Down Expand Up @@ -105,7 +106,14 @@ export function provideFunctionCompletionItems(document: vscode.TextDocument, po
methods.forEach(element => {
var validationRegex = new RegExp(element.validationRegEx);
if (validationRegex.test(linePrefix)) {
results.push(objectFunctionCompletion(element.prefix, element.name, element.template, element.description, vscode.CompletionItemKind.Property))
var description = element.description
if(element.prefix === "i_item."){
description = description + "... [more](https://doc.sitecore.com/developers/sxa/93/sitecore-experience-accelerator/en/item-and-field-extensions.html)";
} else {
description = description + "... [more](https://doc.sitecore.com/developers/sxa/93/sitecore-experience-accelerator/en/the-embedded-functions-for-the-scriban-template.html)";
}

results.push(objectFunctionCompletion(element.prefix, element.name, element.template, description, vscode.CompletionItemKind.Property))
}
});

Expand All @@ -116,7 +124,8 @@ export function provideFunctionCompletionItems(document: vscode.TextDocument, po
commitCharacterCompletion.kind = vscode.CompletionItemKind.Variable;
commitCharacterCompletion.insertText = item.name;
commitCharacterCompletion.commitCharacters = ['.'];
commitCharacterCompletion.documentation = new vscode.MarkdownString(item.description);
var description = item.description + "... [more](https://doc.sitecore.com/developers/sxa/93/sitecore-experience-accelerator/en/the-embedded-items-and-objects-in-the-scriban-context.html)";
commitCharacterCompletion.documentation = new vscode.MarkdownString(description);
commitCharacterCompletion.command = { command: 'editor.action.triggerSuggest', title: 'Re-trigger completions...' };
results.push(commitCharacterCompletion);
}
Expand Down
14 changes: 8 additions & 6 deletions src/autoCompletionItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
* Copyright (C) 2019 - Adam Najmanowicz. All rights reserved.
*--------------------------------------------------------*/

import * as vscode from 'vscode';
import * as vscode from 'vscode';
import { ScribanSnippet } from './types';
import { getCodeBlockFromSnippet } from './autoCompletion';
import { isInScriban, lineHasPipe, snippetVariableCleanup } from './regularExpressions';
import { lineHasPipe, snippetVariableCleanup } from './regularExpressions';

export function snippetCompletion(snippets: ScribanSnippet[], linePrefix: string, results: vscode.CompletionItem[], kind: vscode.CompletionItemKind) {
export function snippetCompletion(snippets: ScribanSnippet[], linePrefix: string, results: vscode.CompletionItem[], kind: vscode.CompletionItemKind, helpUrl: String) {
const isInScriban = new RegExp(/[{]([^}]+)$/g);
for (let snippet of snippets) {
const commitCharacterCompletion = new vscode.CompletionItem(snippet.name);
commitCharacterCompletion.kind = kind;
Expand All @@ -24,6 +25,7 @@ export function snippetCompletion(snippets: ScribanSnippet[], linePrefix: string
}
}

let description = new vscode.MarkdownString(snippet.description+"... [more]("+ helpUrl +")");
if (inMoustaches) {

// if inside moustache block {{ }}
Expand All @@ -33,7 +35,7 @@ export function snippetCompletion(snippets: ScribanSnippet[], linePrefix: string
continue;
}
commitCharacterCompletion.insertText = new vscode.SnippetString(snippet.pipeTemplate + " ");
commitCharacterCompletion.documentation = new vscode.MarkdownString(snippet.description).appendCodeblock(getCodeBlockFromSnippet(snippet.pipeTemplate)).appendCodeblock("\n \n "); // (snippet.pipeCodeBlock);
commitCharacterCompletion.documentation = description.appendCodeblock(getCodeBlockFromSnippet(snippet.pipeTemplate)).appendCodeblock("\n \n "); // (snippet.pipeCodeBlock);
} else {
// if not after pipe, just within moustaches {{ ... }}
//template must be wrapped with moustaches - those are used inside of pure-HTML snippets
Expand All @@ -47,7 +49,7 @@ export function snippetCompletion(snippets: ScribanSnippet[], linePrefix: string
continue;
}
commitCharacterCompletion.insertText = new vscode.SnippetString(template);
commitCharacterCompletion.documentation = new vscode.MarkdownString(snippet.description).appendCodeblock(getCodeBlockFromSnippet(template)).appendCodeblock("\n \n ") // snippet.codeBlock);
commitCharacterCompletion.documentation = description.appendCodeblock(getCodeBlockFromSnippet(template)).appendCodeblock("\n \n ") // snippet.codeBlock);
}
} else {

Expand All @@ -60,7 +62,7 @@ export function snippetCompletion(snippets: ScribanSnippet[], linePrefix: string
documentation = getCodeBlockFromSnippet(snippet.template.join("\n"), false);
}

commitCharacterCompletion.documentation = new vscode.MarkdownString(snippet.description).appendCodeblock(documentation).appendCodeblock("\n "); // snippet.codeBlock);
commitCharacterCompletion.documentation = description.appendCodeblock(documentation).appendCodeblock("\n "); // snippet.codeBlock);
}
results.push(commitCharacterCompletion);
}
Expand Down
7 changes: 0 additions & 7 deletions src/sitecoreFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,4 @@ export const sitecoreFunctions = [
"template": "sc_parameter '${1:Parameter Name}'",
"pipeTemplate": "sc_parameter",
},
{
"name": "",
"description": "",
"validationRegEx": "",
"template": "",
"pipeTemplate": "",
},
];
Loading

0 comments on commit 770d1ca

Please sign in to comment.