Skip to content

add twig snippets #299

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

Merged
merged 1 commit into from
Dec 16, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 35 additions & 13 deletions UltiSnips/php/symfony2.snippets
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# sugguestion? report bugs?
# go to https://github.com/chrisyue/vim-snippets/issues

snippet contr "symfony2 controller" b
snippet contr "Symfony2 controller" b
namespace `!p
abspath = os.path.abspath(path)
m = re.search(r'[A-Z].+(?=/)', abspath)
Expand All @@ -25,19 +25,19 @@ snip.rv = re.match(r'.*(?=\.)', fn).group()
}
endsnippet

snippet act "symfony2 action" b
snippet act "Symfony2 action" b
/**
* @Route("${3}", name="${4}")
* @Method({${5:"POST"}})
* @Template()
*/
public function ${1}Action(${2})
{
${6}
return $this->redirect($this->generateUrl('home', [], false));
}
endsnippet

snippet actt "symfony2 action and template" b
snippet actt "Symfony2 action and template" b
/**
* @Route("${3}", name="${4}")
* @Method({${5:"GET"}})
Expand All @@ -51,7 +51,7 @@ public function ${1}Action(${2})
abspath = os.path.abspath(path)`
endsnippet

snippet comm "symfony2 command" b
snippet comm "Symfony2 command" b
namespace `!p
abspath = os.path.abspath(path)
m = re.search(r'[A-Z].+(?=/)', abspath)
Expand All @@ -74,14 +74,12 @@ snip.rv = re.match(r'.*(?=\.)', fn).group()
{
protected function configure()
{
$this
->setName('${1}')
$this->setName('${1}')
->setDescription('${2}')
->setDefinition([
new InputArgument('', InputArgument::REQUIRED, ''),
new InputOption('', null, InputOption::VALUE_NONE, ''),
])
;
]);
}

protected function execute(InputInterface $input, OutputInterface $output)
Expand All @@ -90,7 +88,7 @@ snip.rv = re.match(r'.*(?=\.)', fn).group()
}
endsnippet

snippet subs "symfony2 subscriber" b
snippet subs "Symfony2 subscriber" b
namespace `!p
abspath = os.path.abspath(path)
m = re.search(r'[A-Z].+(?=/)', abspath)
Expand Down Expand Up @@ -121,7 +119,7 @@ snip.rv = re.match(r'.*(?=\.)', fn).group()
}
endsnippet

snippet transf "symfony2 form data transformer" b
snippet transf "Symfony2 form data transformer" b
namespace `!p
abspath = os.path.abspath(path)
m = re.search(r'[A-Z].+(?=/)', abspath)
Expand Down Expand Up @@ -155,7 +153,7 @@ snip.rv = re.match(r'.*(?=\.)', fn).group()
}
endsnippet

snippet ent "symfony2 doctrine entity" b
snippet ent "Symfony2 doctrine entity" b
namespace `!p
abspath = os.path.abspath(path)
m = re.search(r'[A-Z].+(?=/)', abspath)
Expand Down Expand Up @@ -192,7 +190,7 @@ snip.rv = re.match(r'.*(?=\.)', fn).group()
}
endsnippet

snippet form "symfony2 form type" b
snippet form "Symfony2 form type" b
namespace `!p
abspath = os.path.abspath(path)
m = re.search(r'[A-Z].+(?=/)', abspath)
Expand Down Expand Up @@ -235,3 +233,27 @@ snip.rv = re.match(r'.*(?=\.)', fn).group()
}
}
endsnippet

snippet ev "Symfony2 event" b
namespace `!p
abspath = os.path.abspath(path)
m = re.search(r'[A-Z].+(?=/)', abspath)
if m:
snip.rv = m.group().replace('/', '\\')
`;

use Symfony\Component\EventDispatcher\Event;

/**
* ${2:@author `whoami`}
*/
class `!p
snip.rv = re.match(r'.*(?=\.)', fn).group()
` extends Event
{
}
endsnippet

snippet redir "Symfony2 redirect"
$this->redirect($this->generateUrl('${1}', ${2}));
endsnippet
33 changes: 33 additions & 0 deletions UltiSnips/twig.snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
snippet bl "twig block" b
{% block ${1} %}
${2}
{% endblock $1 %}
endsnippet

snippet js "twig javascripts" b
{% javascripts '${1}' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
endsnippet

snippet css "twig stylesheets" b
{% stylesheets '${1}' %}
<script src="{{ asset_url }}"></script>
{% endstylesheets %}
endsnippet

snippet if "twig if" b
{% if ${1} %}
${2}
{% endif %}
endsnippet

snippet for "twig for" b
{% for ${1} in ${2} %}
${3}
{% endfor %}
endsnippet

snippet ext "twig extends" b
{% extends ${1} %}
endsnippet