#Batraquio
Batraquio is a set of gedit snippets and tools. The goal is help and improve the developers production.
I strongly recommend that you install the Gmate and the package gedit-plugins.
Obs.: The Licences snippets and the Align Columns plugin were removed because now they are included in the Gmate package
##Install
First, download the script follow the link Download at the top of this page. After that click at Download .tar.gz.
Next, unpack the file running on terminal (assuming you downloaded the file in the Download dir):
$ cd Download
$ tar xzfv hugomaiavieira-batraquio-*.tar.gz
Finally to finish the install:
$ cd hugomaiavieira-batraquio-*
$ ./install.sh
To use the snippets, you have to enable the snippets (trechos in Portuguese) plugin. You can do this following (Edit -> Preferences -> Plug-ins).
Note: If you're with an open Gedit instance, close it and open again.
##Snippets
Obs.: I'm using it instead test in the methods because I use the Specloud to run my specs. With that I can write specifications instead mere tests.
###Smart def
The Smart def snippet speeds up the method definition. The activation is made with Ctrl + u. The examples below show the ways to use:
Type the line below and press Ctrl + u with the cursor on the line
it should return the sum of two numbers
and you will have this (the | represents the cursor):
def it_should_return_the_sum_of_two_numbers(self):
|
You can pass params too:
it should return the sum of two numbers(number1, number2)
And you will have this:
def it_should_return_the_sum_of_two_numbers(self, number1, number2):
|
You can also do this...
def it should return the sum of two numbers
This...
def it should return the sum of two numbers ():
Or many combinations of fails syntax that you will have this:
def it_should_return_the_sum_of_two_numbers(self):
|
###Unittest
Type ut and then press Tab and you get this:
import unittest
from should_dsl import *
class ClassName(unittest.TestCase):
|
You only have to write the class name and press tab again.
I assume that you use the amazing package should-dsl that gives you a lot of matchers and turns your test/specs more readable.
###Step Definition
This snippet is based on freshen step definition, but is functional for pycukes and lettuce too. The difference is that you should add manually the parameter context or step respectively.
Type sd and press Tab and you get this:
@Given/When/Then(r'step definition with params (.*)')
def step_definition_with_params(var1):
|
You only have to write Given, When or Then (for freshen or pycukes) or step for lettuce; press Tab and write the step definition; press Tab again and the method will be created. The name for the method is created replacing spaces for undescore on the step definition text. The params list is created based on the regex finded in the step definition text.
###Scape Html tags
If you are writing HTML code for your site, but this code must to be printed as is, like code an example, you must to replace the characters < and > by its special html sequence. Do this while you are writing is not fun. So you can press SHIFT+CTRL+H and this snippet will do this for you.
###Should-dsl
Should-dsl is an amazing python package that gives you a lot of matchers and turns your test/specs more readable.
Batraquio has snippets for all matchers of should-dsl. What you have to do is type the left part of the matcher, then type the abbreviation of the matcher and press Tab. Doing this the rest of the matcher will appear just to you complete de right part of the matcher.
For example:
[1,2,3] anyof # Press Tab
[1,2,3] |should| include_any_of(iterable) # Type the iterable
[1,2,3] |should| include_any_of([1]) # Press Tab again to go to a new line below
Below the description of all snippets for the matchers.
####Matcher (abbreviation)
All of this have the not version, that you can get typing not before the abbreviatio, like the Should not be example. To be succinct, the not version will not be demonstrate.
-
Should be (be)
actual |should| be(expected)
-
Should not be (notbe)
actual |should_not| be(expected)
-
Should be greater than (greater)
actual |should| be_greater_than(expected)
-
Should be greater than or equal to (greaterequal)
actual |should| be_greater_than_or_equal_to(expected)
-
Should be into (into)
item |should| be_into(collection)
-
Should be kind of (kind)
instance |should| be_kind_of(class)
-
Should be less than (less)
actual |should| be_less_than(expected)
-
Should be less than or equal to (lessequal)
actual |should| be_less_than_or_equal_to(expected)
-
Should be like (like)
string |should| be_like(regex)
-
Should be thrown by (thrownby)
exception |should| be_thrown_by(call)
-
Should change (change)
action |should| change(something)
-
Should change by (changeby)
action |should| change(something).by(count)
-
Should change by at least (changebyleast)
action |should| change(something).by_at_lest(count)
-
Should change by at most (changebymost)
action |should| change(something).by_at_most(count)
-
Should change from to (changefromto)
action |should| change(something)._from(initial value).to(final value)
-
Should change to (changeto)
action |should| change(something).to(value)
-
Should close to (close)
actual |should| close_to(value, delta)
-
Should contain (contain)
collection |should| contain(items)
-
Should ended with (ended)
string |should| be_ended_with(substring)
-
Should equal to (equal)
actual |should| equal_to(expect)
-
Should equal to ignoring case (ignoring)
actual |should| be_equal_to_ignoring_case(expect)
-
Should have (have)
collection |should| have(quantity).something
-
Should have at least (atleast)
collection |should| have_at_least(quantity).something
-
Should have at most (atmost)
collection |should| have_at_most(quantity).something
-
Should include (include)
collection |should| include(items)
-
Should include all of (allof)
collection |should| include_all_of(iterable)
-
Should include any of (anyof)
collection |should| include_any_of(iterable)
-
Should include in any order (anyorder)
collection |should| include_in_any_order(iterable)
-
Should include (include)
collection |should| include(items)
-
Should respond to (respond)
object |should| respond_to('method')
-
Should throw (throw)
call |should| throw(exception)
-
Should throw with message (throwmsg)
call |should| throw(exception, message="message")
##Tools
To use this tools, the plugin "External Tools" have to be enabled.
###Tool: Method Location
Tool name: Open Method Definition
Shortcut=Shift+Control+E
Applicability: Python files (.py), Ruby Files (.rb)
Dependency: To use this tool, the plugin "File Browser" in Gedit have to be enabled, and you have to be in your workspace dir.
IMPORTANT: You have to put a file named '.this_is_the_root_folder' on the project root folder. (this is a hidden and blank file) (read example for more instructions)
I also strongly recommend that you install the package 'ack-grep', to improve accuracy of the search (because ack-grep will ignore unwanted folders used by some CVS systems or things like that).
If you doesn't have 'ack-grep' installed, you can install it in a Debian-like distribution doing:
[sudo] apt-get install ack-grep
Description: Select a method name, press the shortcut specified, and gedit should open the file that specify this method.
Example: I have a file named "extension.py", that defines a method like this:
def foo(bar="hello"): #this definition is on line 5 of this file
pass
It's location is './product/modules/'.
And my Gedit is opened, editing only one file named "main.py", that is located on "./product/", and have this on it:
from modules.extension import foo
if __name__=="__main__":
foo()
I put a file named '.this_is_the_root_folder' on the path './product/', to indicate the tool that this is my project root folder.
If I select all the word 'foo' on this file (or even all the call 'foo()'), and press the shortcut Shift+Control+E
the file "extension.py" will be opened on the line 5, the exact location that defines the method "foo"
###Tool: Execute File
Tool name: Execute File
Shortcut=F5
Applicability: Python (.py) | Ruby (.rb) | Browser (.html, .htm, .xml) | Cucumber (.feature) | Markdown (.md)
Dependency: You have to install 'markdown' if you want to compile .md files.
To do this, Debian-like distributions should do: [sudo] apt-get install markdown
IMPORTANT: The python used to compile .py files is the one defined on system's path (using the command python).
Description: Execute the working file.
Example: I'm editing a file named my_app.py.
If I press the shortcut key F5, a panel will open and show the output of the execution of the file.
Obs: For Markdown files, it'll first compile it using the 'markdown' command, and than show it with your preferred browser (defined on gnome-open command).
##Next steps
Add snippets for django template tags and most common licences text.