raket / idea-silverstripe

IDEA plugin for the SilverStripe framework
27 stars 12 forks source link

Bundle live templates #50

Open MarcusDalgren opened 11 years ago

MarcusDalgren commented 11 years ago

I recently implemented a custom context for SilverStripe templates and learned how to bundle live templates with a plugin. This could potentially be a great benefit to new and old users of the plugin alike but I would need some help in defining the standard live template bundle.

I'm calling on @Zauberfisch, @gherkins, @s-m, @schellmax, @lx-berlin and @markguinn for help here. If you wonder why you've been called it's because you've been active here reporting bugs and I think that these templates need to have some kind of consensus around them or at least a discussion about what people want to see.

Depending on how much time/effort you guys can spend on it you can either just suggest stuff like "I want 'if' to become x and y" or if anyone of you has some time to spend I can show you what the XML for it looks like.

Zauberfisch commented 11 years ago

could you elaborate on live templates please? I am not sure what you are referring at.

lx-berlin commented 11 years ago

I am sorry to say, that for the rest of the year i will probably not do any silverstripe work. For the current project i have chosen laravel 4. I wanted to check another framework :) I must say i am missing such a nice phpstom plugin for laravel as yours for silverstripe.

On 07/01/2013 04:21 PM, Marcus Dalgren wrote:

I recently implemented a custom context for SilverStripe templates and learned how to bundle live templates with a plugin. This could potentially be a great benefit to new and old users of the plugin alike but I would need some help in defining the standard live template bundle.

I'm calling on @Zauberfisch https://github.com/Zauberfisch, @gherkins https://github.com/gherkins, @s-m https://github.com/s-m, @schellmax https://github.com/schellmax, @lx-berlin https://github.com/lx-berlin and @markguinn https://github.com/markguinn for help here. If you wonder why you've been called it's because you've been active here reporting bugs and I think that these templates need to have some kind of consensus around them or at least a discussion about what people want to see.

Depending on how much time/effort you guys can spend on it you can either just suggest stuff like "I want 'if' to become x and y" or if anyone of you has some time to spend I can show you what the XML for it looks like.

— Reply to this email directly or view it on GitHub https://github.com/raket/idea-silverstripe/issues/50.

MarcusDalgren commented 11 years ago

Of course!

Live templates are the simpler version of zen coding. You basically define shortcuts so that for example writing "if" and then pressing tab turns it into <% if $ %>

<% end_if %> putting your cursor next to the dollar sign automatically and when you're done there you press enter and it will automatically put you inside the if statement at the right place. If defined in PHPStorm directly it would look like <% if $$$VAR$ %> $END$ <% end_if %> The triple $ is for escaping the $ sign.

MarcusDalgren commented 11 years ago

Nice of you to check in @lx-berlin!

I really like Laravel 4 as well and I have actually been thinking about doing a plugin for Blade. If you haven't already try out the IDE helper plugin (https://github.com/barryvdh/laravel-ide-helper) which helps alot with proper code completion and class finding.

Zauberfisch commented 11 years ago

ah, I see, thanks for clearing that up, so this issue is a duplicate of #16 ?

bilekt3 commented 11 years ago

Bundled live templates will be nice feature - Is there way how to help with this?

Zauberfisch commented 11 years ago

If I am not mistaken @MarcusDalgren is asking for our help to continue the work on the list in the comment on #16 and some discussion on what the exact syntax should be.

I think for the first stage here, when we draft out different syntax version, maybe a google document or a shared ehterpad would be great where we can edit simultaneously

MarcusDalgren commented 11 years ago

It's kindof like zen coding.

Live templates are zen coding:s retarded little brother. Basically you can't write if$var where $var varies, the templates are fixed. I have looked abit at how zen coding is implemented and it looks like I'd have to write my own parser for it which is alot of work. That's why I opened this as a separate issue since live templates aren't full zen coding.

Adding live templates however are just a matter of defining them in a separate XML file that you bundle with the plugin along with the code for a custom context which I have already defined. I'll post an XML example when I get home and start up a google doc for us.

MarcusDalgren commented 11 years ago

You can have a look under IDE Settings -> Live templates for examples of what's possible. Excluding the zen categories.

Zauberfisch commented 11 years ago

ah, now I understand, thanks for clearing that up I'll take a look

Zauberfisch commented 11 years ago

so if the zen stuff manages to do such live templates there, are you sure we can't just copy that?

I also did some digging and experimenting just now. it would appear at least parts of the zen coding / emmet feaatures are available.


so for example the template:

<% if $$$VAR$ %>
$END$
<% end_if %>

will allow if>ul>li*5 to become:

<% if $| %>
    <ul>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
    </ul>
<% end_if %>

also if{this is pretty cool} will work

<% if $| %>
    this is pretty cool
<% end_if %>

I did also try to somehow define the if statement, but had no luck so far, for this html template:

<form action="$VAR0$">$END$</form>

it seems that this works: form[action=test.php]

<form action="test.php"></form>

I am not sure, but it seems the [] syntax only works if the template is a valid html

MarcusDalgren commented 11 years ago

That's really cool I had no idea!

I'll have a look and see if that works in the custom context since that isn't html anymore.

Zauberfisch commented 11 years ago

ok, so that was theorie on the system behind it, now to the templates them self:

I suggest while you try to figure out if its possible to implement a sort of [] syntax, we will write the XML file

can you provide a default xml file that we can work on?

MarcusDalgren commented 11 years ago

Yes I will provide the xml file as soon as I get home!

MarcusDalgren commented 11 years ago

Damnit I can't attach files here. The xml file is available here: https://github.com/raket/idea-silverstripe/blob/phpstorm-61/resources/liveTemplates/SilverStripe.xml

MarcusDalgren commented 11 years ago

Ok I just did a new release with live templates bundled. The xml file linked above shows you what they are. I don't have any strong opinions about these shortcuts so if any of you want to see changes please let me know.

Zauberfisch commented 11 years ago

beautiful!

is there any reason you use &#37; instead of % (intellij seems to use %) eg the if block could be: value="&lt;% if $$$ifVar$ %&gt;&#10; $END$&#10;&lt;% end_if %&gt;" instead of: value="&#60;&#37; if $$$ifVar$ &#37;&#62;&#10; $END$&#10;&#60;&#37; end_if &#37;&#62;"

besides that the liveTemplates for SilverStripe templates look pretty complete.

also, may I suggest renaming this group to SilverStripe Template and creating another group called SilverStripe PHPor something like that. After you did that, I will take some time on the weekend and work on some useful SilverStripe PHP Live Template eg:

MarcusDalgren commented 11 years ago

Hmm I'm going to check that when I get home. I think &lt; got written out literally but &#60; got converted but I honestly don't remember. I remember that writing < or > directly in the string threw an error and I might just have gone all out for all special symbols. &#10; is the only one I found for a new line that worked.

I'll change the name of the context to your suggestion. Since the PHP context is already registered I'll just create the new category in the tree. I'll set that up in the branch tonight and link the XML file here.

MarcusDalgren commented 11 years ago

Alright the start of live templates for SIlverStripe PHP is in there. Just add to this file: https://github.com/raket/idea-silverstripe/blob/phpstorm-61/resources/liveTemplates/SilverStripePHP.xml and I'll add them in when you're done. Either send them to me via mail or send a pull request directly.