Thursday, January 3, 2008
I was playing around with CodePress. There are some modification I made:
This one updates all textareas fields when form is submited, and fix the problem with rails javascript tag hepler.
CodePress.run = function() {
s = document.getElementsByTagName('script');
for(var i=0,n=s.length;iif(s[i].src.match('codepress.js')) {
CodePress.path = s[i].src.replace(/codepress.js.*$/,'');
}
}
t = document.getElementsByTagName('textarea');
for(var i=0,n=t.length;iif(t[i].className.match('codepress')) {
id = t[i].id;
t[i].id = id+'_cp';
eval(id+' = new CodePress(t[i])');
t[i].parentNode.insertBefore(eval(id), t[i]);
}
}
f = document.getElementsByTagName('form');
for(var i=0,n=f.length;icps = f[i].getElementsByClassName('codepress');
if(cps.length > 0){
f[i].cps = cps;
f[i].onsubmit = function(){
for(var i=0;ithis.cps[i].value = eval(this.cps[i].id.replace('_cp','')+'.getCode()');
this.cps[i].disabled = false;
};
}
}
}
}
I also update a little syntax highlight for Ruby language:
/*
* CodePress regular expressions for Ruby syntax highlighting
*/
// Ruby
Language.syntax = [
{ input : /\"(.*?)(\"|
|<\/P>)/g, output : '"$1$2' }, // strings double quote
{ input : /\'(.*?)(\'|
|<\/P>)/g, output : '\'$1$2' }, // strings single quote
{ input : /([\$\@\%]+)([\w\.]*)/g, output : '$1$2' }, // vars
{ input : /\|(.*?)(\||
|<\/P>)/g, output : '|$1$2' }, // block vars
{ input : /(def\s+)([\w\.]*)/g, output : '$1$2' }, // functions
{ input : /\b(alias|and|BEGIN|begin|break|case|class|def|defined|do|else|elsif|END|end|ensure|false|for|if|in|module|next|nil|not|or|redo|rescue|retry|return|self|super|then|true|undef|unless|until|when|while|yield)\b/g, output : '$1' }, // reserved words
{ input : /([\(\){}])/g, output : '$1' }, // special chars
{ input : /#(.*?)(
|<\/P>)/g, output : '#$1$2' }, // comments
{ input : /#(.*?)(
|<\/P>)/g, output : '#$1$2' }, // comments
{ input : /\b(Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Fixnum|Fload|Hash|Integer|IO|MatchData|Method|Module|NilClass|Numeric|Object|Proc|Range|Regexp|String|Symbol|ThreadGroup|Thread|Time|TrueClass)\b/g, output : '$1' } // buildins
];
Language.snippets = []
Language.complete = [
{ input : '\'',output : '\'$0\'' },
{ input : '"', output : '"$0"' },
{ input : '(', output : '\($0\)' },
{ input : '[', output : '\[$0\]' },
{ input : '{', output : '{$0}' }
]
Language.shortcuts = []
0 Responses to CodePress Addons
Something to say?