Skip to content

Instantly share code, notes, and snippets.

@osima
osima / CmdParser.groovy
Created June 1, 2010 03:48
ファイルの入出力指定に限定したコマンドラインパーサ
class CmdParser {
def args
def cli
def CmdParser( def args ){
this.args = args
cli = new CliBuilder()
cli.i(argName:'input', required:true ,args:1 , 'input file')
cli.o(argName:'output', required:true ,args:1 , 'output file')
@osima
osima / pretty.xsl
Created June 2, 2010 23:47
XML文書にインデントを追加するXSL
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="xml" indent="yes" encoding="UTF-8" />
<xsl:template match="@*|node()" >
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
@osima
osima / compact.groovy
Created June 3, 2010 01:34
XML文書をコンパクト形式に変換
//
// [使い方]
// groovy -c UTF-8 -i src.xml -o compact.xml
//
// [機能]
// src.xml のインデント・改行等を削除してコンパクト形式に変換する/Pretty形式にも変換可能
//
// [依存]
// - jdom.jar
// - CmdProc.groovy
@osima
osima / IndUtil.groovy
Created June 3, 2010 03:49
InDesignのjsxで有効なパスへの変換
class IndUtil {
// Windows専用
// WindowsスタイルのファイルパスをExtendScriptで使える形式に変換して返す.
static String toIndPath( File filePath ){
//def path = filePath.absolutePath
def path = filePath.canonicalPath
path.replaceAll('\\\\','/')
}
}
@osima
osima / chkImageEle.jsx
Created June 3, 2010 06:20
InDesignのXMLへのアクセス
//
// InDesign ドキュメントのXMLツリーから 要素 "Image" を探し出し、その position 属性の値を表示.
//
function procImage( eImage ){
var attrs = eImage.xmlAttributes
for(var i=0; i<attrs.length; i++){
var attr = attrs.item(i);
if( attr.name == 'position' ){
alert( attr.value );
@osima
osima / readtext.js
Created June 5, 2010 22:42
javascriptでローカルファイルを読む
//
// Rhino を使って JavaScript からローカルファイルを読む.
//
importPackage(java.io);
var filename = "foo.txt";
var br = BufferedReader( InputStreamReader( FileInputStream( filename ) ) );
while( line= br.readLine() ){
@osima
osima / touchDate.groovy
Created June 9, 2010 00:34
ブログエントリーに作成日マクロを追加
//
// {cdate:yyyy-mm-dd} 形式のタイムスタンプを必要なら追加する.
//
class BlogUtils {
static def ENC = 'UTF-8'
boolean hasCdate( File f ){
@osima
osima / MacroProcessor.groovy
Created June 10, 2010 23:58
{key:value} スタイル表記のマクロプロセッサ
//
// {key:value} スタイル表記のマクロプロセッサ
//
import java.util.regex.Pattern
class MacroProcessor {
@osima
osima / convert.groovy
Created June 11, 2010 00:25
MacroProcessor.groovyの利用例その1
//
// MacroProcessor.groovyの利用例
//
// マクロをどう処理するかを記述
def proc( macroText ){
def mp = new MacroProcessor( macroText )
'<span aid:cstyle="' + mp.key + '">' + mp.value + '</span>'
}
@osima
osima / TextProcessor.groovy
Created June 11, 2010 00:53
MacroProcessor.groovyを利用例その2
//
// MacroProcessor.groovyを利用する便利クラス
//
class TextProcessor {
def 変換処理のClosure
def TextProcessor(Closure 変換処理のClosure){
this.変換処理のClosure = 変換処理のClosure
}