Permalink
Browse files

initial commit

  • Loading branch information...
ryanb committed Aug 14, 2008
0 parents commit 30043fc45004b79b07061862a2eba3b1b9888b85
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>command</key>
+ <string>#!/usr/bin/ruby -w
+
+# This is designed to work with a tab delimited document where
+# one column of that is delimited by commas. This will expand
+# on row into multiple rows, one for each segment of the commas.
+#
+# From:
+# a b, c, d e
+#
+# To:
+# a b e
+# a c e
+# a d e
+class CommaExpander
+ def initialize(text)
+ @rows = text.split("\n").map { |r| Row.new(r) }
+ end
+
+ def resulting_rows
+ @rows.map do |row|
+ if row.contains_commas?
+ row.split_by_commas
+ else
+ row
+ end
+ end.flatten
+ end
+
+ def result
+ resulting_rows.join("\n")
+ end
+end
+
+class Row
+ def initialize(columns = [])
+ if columns.kind_of? Array
+ @columns = columns
+ else
+ @columns = columns.split("\t")
+ end
+ end
+
+ def contains_commas?
+ @columns.any? { |c| c.include? ',' }
+ end
+
+ def split_by_commas
+ @columns.map do |column|
+ if column.include? ','
+ column.split(/\s*,\s*/).map do |col|
+ cols = @columns.dup
+ cols[cols.index(column)] = col
+ Row.new(cols)
+ end
+ end
+ end.flatten.compact
+ end
+
+ def to_s
+ @columns.join("\t")
+ end
+end
+
+print CommaExpander.new(STDIN.read).result
+</string>
+ <key>input</key>
+ <string>selection</string>
+ <key>name</key>
+ <string>Expand CVS Column</string>
+ <key>output</key>
+ <string>replaceSelectedText</string>
+ <key>scope</key>
+ <string>text</string>
+ <key>uuid</key>
+ <string>9DCC6BEB-568D-4040-AE20-8398A6054A4B</string>
+</dict>
+</plist>
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>command</key>
+ <string>#!/usr/bin/ruby -w
+
+# This is designed to work with a tab delimited document where
+# you need to do a find/replace on each col &amp; row value. This is
+# useful if you're trying to import database records and need to
+# match up names with id numbers.
+#
+# To get this to work, you need to copy a "key" into your pasteboard.
+# The first column is the replacement text, and every column after that
+# is the find text. It does an exact match.
+#
+# Pasteboard:
+# 1 apple apples
+# 2 banana naner
+#
+# Given:
+# apple naner
+# apples bananana
+# appleish banana
+#
+# Result:
+# 1 2
+# 1 bananana
+# applish 2
+class MultiReplace
+ def initialize(pattern)
+ @pattern = {}
+ pattern.split("\n").each do |row|
+ row = row.split("\t")
+ matcher = row.first
+ row.each do |column|
+ @pattern[column] = matcher unless column == matcher
+ end
+ end
+ end
+
+ def replace(text)
+ rows = text.split("\n").map { |r| r.split("\t") }
+ rows.map do |row|
+ row.map do |column|
+ @pattern[column] || column
+ end.join("\t")
+ end.join("\n")
+ end
+end
+
+print MultiReplace.new(`pbpaste`).replace(STDIN.read)
+</string>
+ <key>input</key>
+ <string>selection</string>
+ <key>name</key>
+ <string>Find and Replace Columns</string>
+ <key>output</key>
+ <string>replaceSelectedText</string>
+ <key>scope</key>
+ <string>text</string>
+ <key>uuid</key>
+ <string>EB8BDD64-CB27-43D7-B173-A18A3417F916</string>
+</dict>
+</plist>
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>command</key>
+ <string>fold -w 72 -s</string>
+ <key>fallbackInput</key>
+ <string>document</string>
+ <key>input</key>
+ <string>selection</string>
+ <key>name</key>
+ <string>Hard Wrap to 72</string>
+ <key>output</key>
+ <string>replaceSelectedText</string>
+ <key>uuid</key>
+ <string>B4636DAE-2905-434A-817F-997B2EEB8CC3</string>
+</dict>
+</plist>
@@ -0,0 +1,151 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>command</key>
+ <string>#!/usr/bin/ruby -w
+
+# This takes an HTML document with CSS in &lt;head&gt; and moves
+# all the CSS into the HTML tags themselves. This is
+# fairly brute-force and has some strict requirements.
+#
+# I often use this when formating an HTML email because
+# many viewers do not like CSS in the head.
+#
+# Requirements:
+# - Double quotes must be used in id/class attributes
+# - semi-colon must be at the end of each style specification
+# - inheritence isn't fully supported
+# - elements that end in a /&gt; should have a space before the slash
+class CSSInliner
+ def initialize(content)
+ @content = content
+ end
+
+ def css_content
+ @content[/&lt;style\b.*&gt;(.+)&lt;\/style&gt;/im, 1]
+ end
+
+ def styles
+ styles = {}
+ css_content.scan(/\s+(.+?)\s+\{(.+?)\}/im) do |names, values|
+ names.split(', ').each do |name|
+ styles[name] ||= []
+ styles[name] += values.scan(/\s*(.+);/).flatten
+ end
+ end
+ styles
+ end
+
+ def unique_styles
+ styles.each_value do |attributes|
+ attributes.reverse! # We want the last unique value to stay
+ attributes.uniq! { |a| a.split(':').first }
+ attributes.reverse!
+ end
+ end
+
+ def result
+ result = @content
+ unique_styles.each do |selector, attributes|
+ result.gsub!(ElementSelector.new(selector).to_regexp) do |full_match|
+ original_element = $1
+ element = $1
+ if element =~ /style=/i
+ element.gsub!(/style="(.+?)"/i) { "style=\"#{$1}; #{attributes.join('; ')}\"" }
+ else
+ if element =~ /\/$/
+ element.insert(-3, " style=\"#{attributes.join('; ')}\"")
+ else
+ element += " style=\"#{attributes.join('; ')}\""
+ end
+ end
+ full_match.sub "&lt;#{original_element}&gt;", "&lt;#{element}&gt;"
+ end
+ end
+ result
+ end
+end
+
+
+class ElementSelector
+ def initialize(selector_str)
+ selectors = selector_str.split(' ')
+ @selector = selectors.shift
+ if selectors.empty?
+ @child = nil
+ else
+ @child = ElementSelector.new(selectors.join(' ')) unless selectors.empty?
+ end
+ end
+
+ def to_regexp
+ /#{to_regexp_str}/im
+ end
+
+ def to_regexp_str
+ parts = []
+ parts &lt;&lt; element
+ parts &lt;&lt; "\\sid=\"#{element_id}\"" if element_id
+ parts &lt;&lt; "\\sclass=\"#{element_class}\"" if element_class
+ if @child.nil?
+ "&lt;(#{parts.join('[^&gt;]*')}[^&gt;]*)&gt;"
+ else
+ raise "Unable to determine inheritence without full element specified." if element.nil?
+ "&lt;#{parts.join('[^&gt;]*')}[^&gt;]*&gt;.*?#{@child.to_regexp_str}.*?&lt;\\/#{element}&gt;"
+ end
+ end
+
+ def element
+ @selector[/^([-\w]+)/i, 1]
+ end
+
+ def element_id
+ @selector[/#([-\w]+)/i, 1]
+ end
+
+ def element_class
+ @selector[/\.([-\w]+)/i, 1]
+ end
+end
+
+class Array
+ def uniq_with_block!
+ result = uniq_without_block!
+ return result unless block_given?
+ hash = {}
+ each do |element|
+ key = yield(element)
+ hash[key] = element unless hash.has_key? key
+ end
+ hash.size == size ? nil : reject! { |element| hash.delete(yield(element)).nil? }
+ end
+
+ def uniq_with_block(&amp;block)
+ ary = dup
+ ary.uniq!(&amp;block)
+ ary
+ end
+
+ alias_method :uniq_without_block!, :uniq!
+ alias_method :uniq!, :uniq_with_block!
+
+ alias_method :uniq_without_block, :uniq
+ alias_method :uniq, :uniq_with_block
+end
+
+print CSSInliner.new(STDIN.read).result</string>
+ <key>input</key>
+ <string>document</string>
+ <key>name</key>
+ <string>Move CSS Into HTML Tags</string>
+ <key>output</key>
+ <string>replaceDocument</string>
+ <key>scope</key>
+ <string>text.html</string>
+ <key>uuid</key>
+ <string>8908B218-3910-458A-9215-4011CDABB871</string>
+</dict>
+</plist>
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>command</key>
+ <string>#!/usr/bin/ruby -w
+
+results = STDIN.read.to_a
+results.delete_if { |l| !l.include?('|') }
+results.each { |l| l.gsub!(/^\s*\|\s*(.+?)\s*\|\s*$/, '\1') }
+results.each { |l| l.gsub!(/\s*\|\s*/, "\t") }
+
+
+print results.join("\n")</string>
+ <key>input</key>
+ <string>selection</string>
+ <key>name</key>
+ <string>MySQL to Tab Delimited</string>
+ <key>output</key>
+ <string>replaceSelectedText</string>
+ <key>scope</key>
+ <string>text</string>
+ <key>uuid</key>
+ <string>8908CD45-B9A8-47B3-A377-389E648DDC43</string>
+</dict>
+</plist>
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>command</key>
+ <string>#!/bin/sh
+/usr/bin/osascript &gt; /dev/null &lt;&lt;EOS
+ set stdin to "$(cat | sed -e 's/\\/\\\\/g' -e 's/\"/\\\"/g')"
+ tell application "Adobe After Effects CS3"
+ activate
+ DoScript stdin
+ end tell
+EOS
+</string>
+ <key>input</key>
+ <string>document</string>
+ <key>keyEquivalent</key>
+ <string>@r</string>
+ <key>name</key>
+ <string>Run AE Script</string>
+ <key>output</key>
+ <string>discard</string>
+ <key>scope</key>
+ <string>source.js</string>
+ <key>uuid</key>
+ <string>752A96B2-0E1D-445E-8EF6-BF0A8CD55DC6</string>
+</dict>
+</plist>
Oops, something went wrong.

0 comments on commit 30043fc

Please sign in to comment.