Trey Runcie

This page

Archive for November, 2008

Work Locally Save Remotely with Textmate

Saturday, November 29th, 2008

This is a method of working on a project locally and saving to a remote staging server.

You will need to be able to rsync to the remote computer without using a password. For this you will need to set up an ssh key.

Add the following shell script to Textmate as a command with input is set to none, output is set to Show as tooltip and my key equivalent is set to control+command+s (or whatever you like)

RSYNC_USER=${RSYNC_USER:-defaultUsername}
RSYNC_HOST=${RSYNC_HOST:-defaultHost}
if [ "${RSYNC_DIR}"  ]; then
	rsync -av --exclude "CVS*" --exclude "*.kpf" --exclude ".DS_Store" $RSYNC_DIR $RSYNC_USER@$RSYNC_HOST:$RSYNC_REMOTE
fi

Textmate can accept variables for this script on a per project basis. To do this open your project, make sure no files are hi-lighted in the project drawer then click on the “i” info icon at the bottom of the project drawer. Here you can add your required variables.
RSYNC_USER The user
RSYNC_DIR The local directory from which the rsync will be made. eg. “/User/me/Sites/myProject/”
RSYNC_REMOTE The remote directory in which to rsync. eg. “/var/www/myProject”
RSYNC_HOST The host name of the remote server.

Tip: It is always a good idea to echo out the rsync command and have a look at what it is doing before you let it run.

Javascript HTML Builder

Friday, November 28th, 2008

The HTML Builder is for creating markup structure with javascript in a concise nested structure. It uses the YUI Global Object and the YUI Dom object available from the Yahoo! User Interface Library.

There are four public functions.

  1. contentTag: a function for creating html elements with child nodes.
  2. tag: a function for creating self closing html elements like img, input or br.
  3. write: a function for rendering the html elements to the DOM.
  4. addEvent: a function that adds an event to an element and returns that element for rendering in the Dom.

HTML Builder Demo

Sample Usage

var HTML = YAHOO.treyruncie.html;
HTML.write(HTML.contentTag('a',{'href':'somelink'},'text node'));
var HTML = YAHOO.treyruncie.html;
HTML.write(
    HTML.contentTag('div',{'class':'divFromScript'},
        'DIV and input from script',
        HTML.tag('br'),
        HTML.contentTag('label',{'for':'sample'},
            'label for sample',
            HTML.tag('input',{'value':'hello world','name':'sample'})
        ),
        HTML.tag('br'),
        'DIV and input from script'
    ),
    'targetID','insertAfter'
);

powered by WordPress