Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intial support for vsCodeTagSnippets #589

Merged
merged 4 commits into from
Feb 26, 2021
Merged

Intial support for vsCodeTagSnippets #589

merged 4 commits into from
Feb 26, 2021

Conversation

phalaphone
Copy link
Contributor

@phalaphone phalaphone commented Jan 25, 2021

Added new method to produce a string of tag snippets formatted for use in the hubspot vscode plugin.

Updated
(1/29) Output:

{% import ${1:path} ${2:import_name} %}

{% elif ${1:condition} %}

{% autoescape %}
{% endautoescape %}

{% from ${1:path} ${2:macro_name} %}

{% macro ${1:macro_name} ${2:argument_names} %}
{% endmacro %}

{% raw %}
{% endraw %}

{% else %}

{% if ${1:condition} %}
{% endif %}

{% print ${1:expr} %}

{% do %}

{% cycle ${1:string_to_print} %}

{% unless ${1:expr} %}
{% endunless %}

{% include ${1:path} %}

{% ifchanged %}
{% endifchanged %}

{% set ${1:var} = ${2:expr} %}

{% block ${1:block_name} %}
{% endblock %}

{% call %}
{% endcall %}

{% extends ${1:path} %}

{% for ${1:items_to_iterate} %}
{% endfor %}

@phalaphone phalaphone requested a review from mattcoley January 25, 2021 22:08
Copy link
Collaborator

@mattcoley mattcoley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🆒 Looks like if/elif are missing the jinjavaparam in the doc, can you add it here?

@mattcoley
Copy link
Collaborator

I think set tag is a bit custom here since I think you want {% set ${1:var} = ${2:expr} %}. Maybe it is worth adding a new annotation to specify an override for this custom behavior on the few tags that we need to adjust the snippet?

@phalaphone
Copy link
Contributor Author

I updated the output in at the top of the page. I did notice for a lot of them (i.e. if, else, macro, etc.) We have no jinjava annotation for body, would it be worthwhile to add that so we can represent where code would go in an if statement for example?

@anthmatic
Copy link
Contributor

anthmatic commented Feb 3, 2021

we can represent where code would go

@phalaphone do you mean something like this?

{% if ${1:condition} %}
  $0
{% endif %}

If so, I think that would be helpful. Each ${} tag is a tabbable placeholder in VSCode and $0, $1, etc... are tab stops

@@ -4,6 +4,7 @@
import com.hubspot.jinjava.doc.annotations.JinjavaMetaValue;
import com.hubspot.jinjava.doc.annotations.JinjavaParam;
import com.hubspot.jinjava.doc.annotations.JinjavaSnippet;
import com.hubspot.jinjava.doc.annotations.JinjavaVSCodeSnippet;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this should be VSCode specific. This syntax is technically borrowed from Textmate and other editors use a similar format so I think this could be used across other editors pretty easily

@phalaphone
Copy link
Contributor Author

@mattcoley @anthmatic

Here is the current list:

{% import ${1:path} ${2:import_name} %}

{% elif ${1:condition} %}
${2:Code}

{% autoescape %}
{% endautoescape %}

{% from ${1:path} ${2:macro_name} %}

{% macro ${1:macro_name} ${2:argument_names} %}
${3:Code}
{% endmacro %}

{% raw %}
{% endraw %}

{% else %}
${1:Code}

{% if ${1:condition} %}
${2:Code}
{% endif %}

{% print ${1:expr} %}

{% do %}

{% cycle ${1:string_to_print} %}

{% unless ${1:expr} %}
${2:Code}
{% endunless %}

{% include ${1:path} %}

{% ifchanged %}
${1:Code}
{% endifchanged %}

{% set ${1:var} = ${2:expr} %}

{% block ${1:block_name} %}
{% endblock %}

{% call %}
{% endcall %}

{% extends ${1:path} %}

{% for ${1:items_to_iterate} %}
${2:Code}
{% endfor %}

Any changes before we get this out as a starting point?

@anthmatic
Copy link
Contributor

Thanks @phalaphone! I made some changes to some snippets below:

{% import '${1:path}' ${2: as ${3:import_name}} %}

{% elif ${1:condition} %}
$0

{% autoescape %}
{% endautoescape %}

{% from '${1:path}' import ${2:macro_name} %}

{% macro ${1:macro_name}(${2:argument_names}) %}
$0
{% endmacro %}**

{% raw %}
{% endraw %}

{% else %}
$0

{% if ${1:condition} %}
$0
{% endif %}

{% print ${1:expr} %}

{% do ${1:expr} %}

{% cycle ${1:string_to_print} %}

{% unless ${1:expr} %}
$0
{% endunless %}

{% include '${1:path}' %}

{% ifchanged %}
$0
{% endifchanged %}

{% set ${1:var} = ${2:expr} %}

{% block ${1:block_name} %}
$0
{% endblock {$1} %}

{% call ${1:macro_name}(${2:argument_names}) %}
$0
{% endcall %}

{% extends '${1:path}' %}

{% for ${1:items} in ${2:list} %}
{{ ${1} }}$0
{% endfor %}```

The most notable change is that the code placeholder should just be `$0`, but there are a bunch of small changes to most of these. Let me know if you have any questions about any changes.

@phalaphone phalaphone merged commit f5fa978 into master Feb 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants