Dr Nic has a movie showing you how to use Ruby with TextMate snippets and commands.
Allan finally found time to set up scripts. It’s up.
Here is my snippet for favicon links for TextMate.
# favicon links snippet for TextMate
#Activation: Tab Trigger: favicon
#Scope Selector: text.html
<link rel="shortcut icon" href="${1:/path/to/favicon}.ico" type="image/x-icon" />
<link rel="icon" href="${1:/path/to/favicon}.ico" type="image/x-icon" />
I hope you like this.
Div tags are nasty. I always end up with trying to find which </div> corresponds to which <div>. One thing I try to do is to keep the consistent indention even when the tags are generated automatically by templates of web frameworks. If you don’t like this messy nature of HTML, you might want to try HAML, a drop-in replacement for Ruby(ERB) for Rails.
A convention I try to keep at least for my own projects is to have a HTML comment after the close tag as in </div> <!-- end #id .class -->. I have made the TextMate snippets for them, which I would like to share with you.
There are four snippets. <div id="">, <div class="">, <div id="" class="">, <div class="" id="">. You first tab and fill in id and/or class. After presseing the tab again, the comment part is highlighted, it gives you a chance to delete the whole comment.
# <div id=""> snippet for TextMate
# Activation: Tab Trigger: divi
# Scope Selector: text.html
<div id="$1">
$0
</div> ${2:<!-- end #$1 -->}
# <div id="" class=""> snippet for TextMate
# Activation: Tab Trigger: divic
# Scope Selector: text.html
<div id="$1" class="$2">
$0
</div> ${3:<!-- end #$1 .$2-->}
# <div class="" id=""> snippet for TextMate
# Activation: Tab Trigger: divci
# Scope Selector: text.html
<div id="$1" class="$2">
$0
</div> ${3:<!-- end #$1 .$2 -->}
# <div class=""> snippet for TextMate
# Activation: Tab Trigger: divc
# Scope Selector: text.html
<div class="$1">
$0
</div> ${2:<!-- end .$1 -->}
Tweak them as you want to, and enjoy coding.
When I work on Rails, I would like to have two tabs open that are in the same directory. One for server log and another for running commands (e.g., script/generate) After opening the TextMate project file. I type ⌃⇧O to open the main directory in Terminal.
Then I run the following AppleScript.
tell application "System Events"
-- Need to wait a bit to avoild some conflict
-- No key should be pressed when this script is being run
do shell script "sleep 0.75"
tell application "Terminal" to activate
-- Change Kotoeri Input to Alphanumeric mode
keystroke ";" using {control down, shift down}
set the clipboard to ""
keystroke "pwd | pbcopy"
keystroke return
keystroke "t" using command down
keystroke "cd "
keystroke "v" using command down
end tell
I put the script in ~/Library/Scripts/Application/Terminal, and assigned ⌘⇧D using FastScripts.
Update: Thanks to Allan and Mike, this cheat sheet is now officially in YAML bundle in TextMate. Get it at the svn repository.
Here is what I do. The data is from the official reference card.
In Bundle Editor, make a new command named "Show YAML Reference Card. Set "Save" to "Nothiing", "Input" to "None", and "Output" to "Show as HTML". In "Commands(s)", type in as in below:
. "$TM_SUPPORT_PATH/lib/webpreview.sh"
html_header "YAML Reference Card" "YAML"
Markdown.pl <<'EOF'
<title>YAML Reference Card</title>
Collection indicators:
'? ' : Key indicator.
': ' : Value indicator.
'- ' : Nested series entry indicator.
', ' : Separate in-line branch entries.
'[]' : Surround in-line series branch.
'{}' : Surround in-line keyed branch.
Scalar indicators:
'''' : Surround in-line unescaped scalar ('' escaped ').
'"' : Surround in-line escaped scalar (see escape codes below).
'|' : Block scalar indicator.
'>' : Folded scalar indicator.
'-' : Strip chomp modifier ('|-' or '>-').
'+' : Keep chomp modifier ('|+' or '>+').
1-9 : Explicit indentation modifier ('|1' or '>2').
# Modifiers can be combined ('|2-', '>+1').
Alias indicators:
'&' : Anchor property.
'*' : Alias indicator.
Tag property: # Usually unspecified.
none : Unspecified tag (automatically resolved by application).
'!' : Non-specific tag (by default, "!!map"/"!!seq"/"!!str").
'!foo' : Primary (by convention, means a local "!foo" tag).
'!!foo' : Secondary (by convention, means "tag:yaml.org,2002:foo").
'!h!foo': Requires "%TAG !h! <prefix>" (and then means "<prefix>foo").
'!<foo>': Verbatim tag (always means "foo").
Document indicators:
'%' : Directive indicator.
'---': Document header.
'...': Document terminator.
Misc indicators:
' #' : Throwaway comment indicator.
'`@' : Both reserved for future use.
Special keys:
'=' : Default "value" mapping key.
'<<' : Merge keys from another mapping.
Core types: # Default automatic tags.
'!!map' : { Hash table, dictionary, mapping }
'!!seq' : { List, array, tuple, vector, sequence }
'!!str' : Unicode string
More types:
'!!set' : { cherries, plums, apples }
'!!omap': [ one: 1, two: 2 ]
Language Independent Scalar types:
{ ~, null } : Null (no value).
[ 1234, 0x4D2, 02333 ] : [ Decimal int, Hexadecimal int, Octal int ]
[ 1_230.15, 12.3015e+02 ]: [ Fixed float, Exponential float ]
[ .inf, -.Inf, .NAN ] : [ Infinity (float), Negative, Not a number ]
{ Y, true, Yes, ON } : Boolean true
{ n, FALSE, No, off } : Boolean false
? !!binary >
R0lG...BADS=
: >-
Base 64 binary value.
Escape codes:
Numeric : { "\x12": 8-bit, "\u1234": 16-bit, "\U00102030": 32-bit }
Protective: { "\\": '\', "\"": '"', "\ ": ' ', "\<TAB>": TAB }
C : { "\0": NUL, "\a": BEL, "\b": BS, "\f": FF, "\n": LF, "\r": CR,
"\t": TAB, "\v": VTAB }
Additional: { "\e": ESC, "\_": NBSP, "\N": NEL, "\L": LS, "\P": PS }
EOF
html_footer
Set "Activation" to "Key Equivalent ⌃ H" and "Scope Selector" to "source.yaml".
RubyAMP is a TextMate bundle that makes you more productive in editing, navigating, and debugging Ruby code. Now you can easily:
- auto-complete from all open tabs
- jump to a method, class, or fixture named under the cursor
- start the debugger on a series of RSpec examples and break at * the current line
- inspect by highlighting to evaluate to tooltip or clipboard
- fire up a Merb/Rails server or console for your current app
- tail development.log
As Rails 2.0 uses SQLite as the default database, you need to use rails -d mysql name_of_your_app to use MySQL as your database. I, however, forget this, and find myself deleting the app and run the command line once again.
So, I compared an app generated with SQLite with one with MySQL. Here is a visual result of diff thanks to Changes. Click the image to enlarge.
Three files are different.
protect_from_forgery in application.rb. We don’t have to care this.session_key and it’s secret in environment.rb. We don’t have to care this.database.yml is completely differnt. We need complete rewriting.What this means is that in order to change the setting, all you need to do is simply rewrite the database.yml. So, I decided to write a TextMate snippet that contains the entire content of the setting.
Here’s a snippet
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql
# On Mac OS X:
# sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql
# On Mac OS X Leopard:
# sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
# This sets the ARCHFLAGS environment variable to your native architecture
# On Windows:
# gem install mysql
# Choose the win32 build.
# Install MySQL and put its /bin directory on your path.
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql
encoding: utf8
database: ${1:app_name}_development
username: ${2:root}
password: $3
socket: /tmp/mysql.sock
# Warning: The database defined as 'test' will be erased and
# re-generated from your development database when you run 'rake'.
# Do not set this db to the same as development or production.
test:
adapter: mysql
encoding: utf8
database: ${1:app_name}_test
username: ${2:root}
password: $3
socket: /tmp/mysql.sock
production:
adapter: mysql
encoding: utf8
database: ${1:app_name}_production
username: ${2:root}
password: $3
socket: /tmp/mysql.sock
I assign tab trigger to “database” and scope selector to “source.yaml”. The way to use is simple. Open database.yml and delete the content. Then, type database and ⇥(tab) and voila! (Note: I don’t recommend you use the same username and password for all of the environments.)
I have spent the last two years on Nicola and have good memories, but I will move to Marin. If you are my new neighbor, please say hello to me.
Marin doesn’t have a tagline? It’s sad…
Due to this migration, this website will down off and on for the next few days. I think I will close Mate Tips now. I’m sure that the prime time for TextMate is not ready in Japan, but I’m also sure there are already many people who use TextMate as a development tool on a daily basis. I hope we will see a Japanese community for TextMate discussing Japanese (double-byte), TeX and any other Japanese-related matters. As I’m proudly jobless right now and spending most of my time for getting a job, I don’t think I can keep the website up-to-date with upcoming news.
(Note: You should not start a sentence with “due to”. It will piss off old people. I mean, chronologically-challenged people. Avoid the usage in formal writing. I’m doing formal writing in both Japanese and English a lot these days.)