From james@vennt.net Thu May 24 12:05:49 2007 From: james@vennt.net To: textmate@lists.macromates.com Subject: [TxMt] List all colours in a CSS file command Date: Thu, 24 May 2007 05:05:12 -0700 Message-ID: <2088.80.229.93.65.1180008312.squirrel@webmail.vennt.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============3215375584554837773==" --===============3215375584554837773== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Thanks for the regex tip Chris, worked great. The command now displays Hex, RGB and Named colours (thanks to the bit I copied out of the CSS language file) and I tidied some of the layout up a bit to fit the longer colour names etc. So here is my final version #!/usr/bin/env ruby myFile =3D STDIN.read fileName =3D ENV['TM_FILENAME'] hex =3D Regexp.new(/(#[0-9a-fA-F]{3,6})|(seagreen|hotpink|lawngreen|darkgreen|violet|= darkred|crimson|green|sandybrown|navy|magenta|darkslategray|steelblue|silver|= darkgrey|mistyrose|gray|aliceblue|blueviolet|lightpink|saddlebrown|chocolate|= limegreen|lightslategray|yellowgreen|pink|lightskyblue|indigo|lightblue|flora= lwhite|navajowhite|mediumvioletred|honeydew|aquamarine|blue|olivedrab|palegre= en|slategray|lavenderblush|wheat|moccasin|mediumturquoise|mediumspringgreen|l= ightcoral|mintcream|tomato|lightgrey|black|darkmagenta|dimgray|darkturquoise|= midnightblue|plum|indianred|coral|lightcyan|mediumslateblue|darkcyan|darkslat= eblue|darkkhaki|ivory|azure|khaki|powderblue|darkgoldenrod|orangered|burlywoo= d|turquoise|royalblue|maroon|cornsilk|antiquewhite|yellow|teal|orange|grey|da= rkslategrey|slateblue|seashell|darkorchid|snow|lightslategrey|cyan|greenyello= w|palevioletred|goldenrod|deepskyblue|lightyellow|lightseagreen|sienna|lemonc= hiffon|darkviolet|paleturquoise|slategrey|skyblue|purple|mediumpurple|cadetbl= ue|fuchsia|chartreuse|darksalmon|lightgoldenrodyellow|white|springgreen|olive= |forestgreen|peachpuff|peru|dimgrey|mediumseagreen|thistle|firebrick|darkgray= |mediumaquamarine|darkolivegreen|mediumblue|palegoldenrod|blanchedalmond|ghos= twhite|gold|gainsboro|darkseagreen|cornflowerblue|lime|lavender|beige|orchid|= mediumorchid|whitesmoke|bisque|lightgray|tan|salmon|rosybrown|red|dodgerblue|= brown|aqua|oldlace|deeppink|papayawhip|lightsalmon|lightsteelblue|darkorange|= darkblue|linen|lightgreen)|(rgb\([0-9]{1,3}\,[0-9]{1,3}\,[0-9]{1,3}\))/) def swatch(colour,lineNumber) puts "
#{colour}
#{lineNumber}
" end puts ' Colours ' puts "

Colours used in #{fileName}

" lines =3D myFile.split("\n") counter =3D 1 lines.each do |line| colourArray =3D line.scan(hex) colourArray.each do |colour| swatch(colour,counter) end counter+=3D1 end puts "
" --===============3215375584554837773==-- From lists@interdisco.net Thu May 24 12:28:06 2007 From: Oliver Hagmann To: textmate@lists.macromates.com Subject: Re: [TxMt] List all colours in a CSS file command Date: Thu, 24 May 2007 14:28:05 +0200 Message-ID: In-Reply-To: <2088.80.229.93.65.1180008312.squirrel@webmail.vennt.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============4277489257755489669==" --===============4277489257755489669== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit On 24.05.2007, at 14:05, james(a)vennt.net wrote: > Thanks for the regex tip Chris, worked great. > > The command now displays Hex, RGB and Named colours (thanks to the > bit I > copied out of the CSS language file) and I tidied some of the > layout up a > bit to fit the longer colour names etc. I noticed a small bug: I have an ID called "#default" in one of my files. This now gets also listed as "#defa" in the output window. Otherwise very nice! Thanks. Oliver --===============4277489257755489669==--