jruby での nokogiri 。チュートリアルの勝手なまとめ とりあえず最終回

さて、jruby での nokogiri チュートリアルの勝手なまとめ の最終回です。

前にも書きましたように、jruby 1.5.6 は cruby1.8.7 とほぼ同等ですが、マルチバイト文字の扱いはまったく同じではありません。私は cruby1.8.7 での動作の検証はやってません。

nokogiri のバージョンは 1.4.4.2 です。

ubuntu10.04 を使用していますので、文字環境は utf-8 がデフォです。

●整形式のマークアップ(不正の修正、厳格な適用の例)


# 整形式のマークアップ
# もし不正なマークアップがあれば、nokogiri は修正を試みる。

$KCODE = 'UTF8'

require 'rubygems'
require 'nokogiri'

badly_formed = <<-EOXML

foo
bar

EOXML

bad_doc = Nokogiri::XML badly_formed

puts 'bad_doc を出力'
puts bad_doc


=begin

実行結果
bad_doc を出力


foo
bar

=end

# 解析オプションNOERRORSとNOWARNINGSがオフの場合、
# エラーを追跡する。(デフォルトはオフ)

puts 'bad_doc.errors を出力'
puts bad_doc.errors

=begin

実行結果
bad_doc.errors を出力
Opening and ending tag mismatch: open line 2 and root
Premature end of data in tag root line 1

=end


# より厳格に整形式を扱う

puts 'Strict Well-Formedness の場合'

begin
bad_doc = Nokogiri::XML(badly_formed) { |config| config.strict }
rescue Nokogiri::XML::SyntaxError => e
puts "caught exception: #{e}"
end


=begin

実行結果
Strict Well-Formedness の場合
caught exception: Premature end of data in tag root line 1

=end

●Nokogiri_HTML_Builderの使い方


$KCODE = 'UTF8'

require 'rubygems'
require 'nokogiri'

builder = Nokogiri::HTML::Builder.new{
html{
body{
h1{ text "nokogiri 1.2.3 リリース" }
text "こんにちは!アーロンです! "
}
}
}

puts builder.to_html

=begin

実行結果(日本語は文字化け)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body>
<h1>nokogiri 1.2.3 &#12522;&#12522;&#12540;&#12473;</h1>&#12371;&#12435;&#12356;&#12385;&#12399;&#65281;&#12450;&#12540;&#12525;&#12531;&#12391;&#12377;&#65281; </body></html>

=end


# ## 日本語エンコーディングの復元操作

html_doc = Nokogiri::HTML(builder.to_html, nil, 'utf-8')

puts html_doc

=begin

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body>
<h1>nokogiri 1.2.3 リリース</h1>こんにちは!アーロンです! </body></html>

=end

いちおう、nokogiri チュートリアルの勝手なまとめ はこれにてとりあえず終了です。
たぶん、おまけ的にあと1、2回付け足しを書くと思います。

jruby での nokogiri 。チュートリアルの勝手なまとめ その4

さて、jruby での nokogiri チュートリアルの勝手なまとめ の第4回目です。

前にも書きましたように、jruby 1.5.6 は cruby1.8.7 とほぼ同等ですが、マルチバイト文字の扱いはまったく同じではありません。私は cruby1.8.7 での動作の検証はやってません。

nokogiri のバージョンは 1.4.4.2 です。

ubuntu10.04 を使用していますので、文字環境は utf-8 がデフォです。


●HTML / XMLのドキュメント の内容を変更する


このような HTMLドキュメントがあるとする。


$KCODE = 'UTF8'

require 'rubygems'
require 'nokogiri'

@doc = Nokogiri::HTML::DocumentFragment.parse <<-EOHTML
<body>
<h1>Three's Company</h1>
<div>A love triangle.</div>
</body>
EOHTML

# そのヘッダのテキストの内容を変更する。

h1_obj = @doc.at_css "h1"
h1_obj.content = "Snap, Crackle and Pop"

puts @doc.to_html

=begin

実行結果
<body>
<h1>Snap, Crackle and Pop</h1>
<div>A love triangle.</div>
</body>

=end

●ノード(xml の要素)の移動・属性変更・ノードの新規作成・ラッピング


$KCODE = 'UTF8'

require 'rubygems'
require 'nokogiri'

puts '■ ノード(xml の要素)の移動'
puts '■ ノードを移動する最も簡単な方法は、その親を割り当てること'

@doc = Nokogiri::HTML::DocumentFragment.parse <<-EOHTML
<body>
<h1>Three's Company</h1>
<div>A love triangle.</div>
</body>
EOHTML

h1_obj = @doc.at_css "h1"
div_obj = @doc.at_css "div"
h1_obj.parent = div_obj

puts @doc.to_html

=begin

実行結果
<body>

<div>A love triangle.<h1>Three's Company</h1>
</div>
</body>

=end


puts '■ そのノードを他の場所(次の隣)へ移動'

div_obj.add_next_sibling(h1_obj)

puts @doc.to_html

=begin

実行結果
<body>

<div>A love triangle.</div>
<h1>Three's Company</h1>
</body>

=end


puts '■ ノードと属性の変更'

h1_obj.name = 'h2'
h1_obj['class'] = 'show-title'

puts @doc.to_html

=begin

実行結果
<body>

<div>A love triangle.</div>
<h2 class="show-title">Three's Company</h2>
</body>

=end


puts '■ 新しいノードの作成'

h3_obj = Nokogiri::XML::Node.new "h3", @doc
h3_obj.content = "1977 - 1984"
h1_obj.add_next_sibling(h3_obj)

puts @doc.to_html

=begin

実行結果
<body>

<div>A love triangle.</div>
<h2 class="show-title">Three's Company</h2>
<h3>1977 - 1984</h3>
</body>

=end


puts '■ ノードセットのラッピング'

nodes = @doc.css "h1,div"
wrapper = nodes.wrap("<div class='container'></div>")

puts @doc.to_html

=begin

実行結果
<body>

<div class="container"><div>A love triangle.</div></div>
<h2 class="show-title">Three's Company</h2>
<h3>1977 - 1984</h3>
</body>
=end

この項、まだ続きます。

jruby での nokogiri 。チュートリアルの勝手なまとめ その3

さて、jruby での nokogiri チュートリアルの勝手なまとめ の第3回目です。

前にも書きましたように、jruby 1.5.6 は cruby1.8.7 とほぼ同等ですが、マルチバイト文字の扱いはまったく同じではありません。私は cruby1.8.7 での動作の検証はやってません。

nokogiri のバージョンは 1.4.4.2 です。

ubuntu10.04 を使用していますので、文字環境は utf-8 がデフォです。


名前空間について


url は一意であるので、それに対応付けられた も一意となる。
(世界で公開されている xml 上で名前が衝突しない、ということ)

いま、ホームディレクトリに parts.xml があるとして、
サンプル・コードを示す。

[parts.xml]


<parts>
<!-- Alice's Auto Parts Store -->
<inventory xmlns="http://alicesautoparts.com/">
<tire>all weather</tire>
<tire>studded</tire>
<tire>extra wide</tire>
</inventory>

<!-- Bob's Bike Shop -->
<inventory xmlns="http://bobsbikes.com/">
<tire>street</tire>
<tire>mountain</tire>
</inventory>
</parts>

サンプル・コード


$KCODE = 'UTF8'

require 'rubygems'
require 'nokogiri'

# カレントディレクトを HomeDirectory に指定
Dir.chdir(File.expand_path("~/"))

@doc = Nokogiri::XML(File.read("parts.xml"))

car_tires = @doc.xpath('//car:tire', 'car' => 'http://alicesautoparts.com/')

puts '■ car_tires の要素 を出力'
car_tires.each{|elem| puts elem}

bike_tires = @doc.xpath('//bike:tire', 'bike' => 'http://bobsbikes.com/')

puts '■ bike_tires の要素 を出力'
bike_tires.each{|elem| puts elem}

=begin

実行結果
■ car_tires の要素 を出力
<tire>all weather</tire>
<tire>studded</tire>
<tire>extra wide</tire>
■ bike_tires の要素 を出力
<tire>street</tire>
<tire>mountain</tire>

=end


命名規則に従うなら、コードをより短くできる。

例として、あるAtomフィードの処理を示す。

[atom.xml]


<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

<title>Example Feed</title>
<link href="http://example.org/"/>
<updated>2003-12-13T18:30:02Z</updated>
<author>
<name>John Doe</name>
</author>
<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>

<entry>
<title>Atom-Powered Robots Run Amok</title>
<link href="http://example.org/2003/12/13/atom03"/>
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
<updated>2003-12-13T18:30:02Z</updated>
<summary>Some text.</summary>
</entry>

</feed>

規約に従うなら、我々はこのようにすべてのタイトル・タグを取得することが出来る。
atom.xml を ホームディレクトリに置く)

サンプル・コード


$KCODE = 'UTF8'

require 'rubygems'
require 'nokogiri'

# カレントディレクトを HomeDirectory に指定
Dir.chdir(File.expand_path("~/"))

@doc = Nokogiri::XML(File.read("atom.xml"))

tag_titles = @doc.xpath('//xmlns:title')
tag_titles.each{|elem| puts elem}

=begin

実行結果
<title>Example Feed</title>
<title>Atom-Powered Robots Run Amok</title>

=end

名前空間の利点を得るには、XPathを使用しないで、
CSSセレクタを使用することも出来る。

CSSの使用例


$KCODE = 'UTF8'

require 'rubygems'
require 'nokogiri'

# カレントディレクトを HomeDirectory に指定
Dir.chdir(File.expand_path("~/"))

@doc = Nokogiri::XML(File.read("atom.xml"))

tag_titles2 = @doc.css('xmlns|title')

tag_titles2.each{|elem| puts elem}

=begin

実行結果

<title>Example Feed</title>
<title>Atom-Powered Robots Run Amok</title>

=end

CSSを使用するとき、
名前空間が"xmlns"と呼ばれている場合、名前空間の名を省略出来る。


$KCODE = 'UTF8'

require 'rubygems'
require 'nokogiri'

# カレントディレクトを HomeDirectory に指定
Dir.chdir(File.expand_path("~/"))

@doc = Nokogiri::XML(File.read("atom.xml"))

tag_titles3 = @doc.css('title')

tag_titles3.each{|elem| puts elem}

=begin

実行結果

<title>Example Feed</title>
<title>Atom-Powered Robots Run Amok</title>

=end


さて、この項、まだまだ続きます。

jruby での nokogiri 。チュートリアルの勝手なまとめ その2

さて、jruby での nokogiri チュートリアルの勝手なまとめ の第2回目です。

前回にも書きましたように、jruby 1.5.6 は cruby1.8.7 とほぼ同等ですが、マルチバイト文字の扱いはまったく同じではありません。私は cruby1.8.7 での動作の検証はやってません。

nokogiri のバージョンは 1.4.4.2 です。
ubuntu10.04 を使用していますので、文字環境は utf-8 がデフォです。

今回は、基本的な検索の例を。


○基本的な検索

[次の内容のファイル shows.xml が自分のホームディレクトリにあるとします]


<root>
<sitcoms>
<sitcom>
<name>Married with Children</name>
<characters>
<character>Al Bundy</character>
<character>Bud Bundy</character>
<character>Marcy Darcy</character>
</characters>
</sitcom>
<sitcom>
<name>Perfect Strangers</name>
<characters>
<character>Larry Appleton</character>
<character>Balki Bartokomous</character>
</characters>
</sitcom>
</sitcoms>
<dramas>
<drama>
<name>The A-Team</name>
<characters>
<character>John "Hannibal" Smith</character>
<character>Templeton "Face" Peck</character>
<character>"B.A." Baracus</character>
<character>"Howling Mad" Murdock</character>
</characters>
</drama>
</dramas>
</root>

この show.xml の中の タグの内容 を返してみる例


$KCODE = 'UTF8'

require 'rubygems'
require 'nokogiri'

# カレントディレクトを HomeDirectory に指定
Dir.chdir(File.expand_path("~/"))

@doc = Nokogiri::XML(File.open("shows.xml"))
tag_characters = @doc.xpath("//character")

puts '■ @doc.xpath("//character") の要素 を出力。'
tag_characters.each{|elem| puts elem}

puts '■ tag_characters[0] を出力。'
puts tag_characters[0]

tag_dramas_characters = @doc.xpath("//dramas//character")

puts '■ @doc.xpath("//dramas//character") の要素 を出力。'
tag_dramas_characters.each{|elem| puts elem}

css_sitcoms_names = @doc.css("sitcoms name")

puts '■ @doc.css("sitcoms name") の要素 を出力。'
css_sitcoms_names.each{|elem| puts elem}

puts '■ @doc.css("dramas name").first の出力'
puts @doc.css("dramas name").first

puts '■ @doc.at_css("dramas name") の出力'
puts @doc.at_css("dramas name")

=begin

実行結果

■ @doc.xpath("//character") の要素 を出力。
<character>Al Bundy</character>
<character>Bud Bundy</character>
<character>Marcy Darcy</character>
<character>Larry Appleton</character>
<character>Balki Bartokomous</character>
<character>John "Hannibal" Smith</character>
<character>Templeton "Face" Peck</character>
<character>"B.A." Baracus</character>
<character>"Howling Mad" Murdock</character>
■ tag_characters[0] を出力。
<character>Al Bundy</character>
■ @doc.xpath("//dramas//character") の要素 を出力。
<character>John "Hannibal" Smith</character>
<character>Templeton "Face" Peck</character>
<character>"B.A." Baracus</character>
<character>"Howling Mad" Murdock</character>
■ @doc.css("sitcoms name") の要素 を出力。
<name>Married with Children</name>
<name>Perfect Strangers</name>
■ @doc.css("dramas name").first の出力
<name>The A-Team</name>
■ @doc.at_css("dramas name") の出力
<name>The A-Team</name>

=end


この項、まだまだ続きます。

jruby での nokogiri 。チュートリアルの勝手なまとめ その1

これからしらばらく、
nokogiri のチュートリアルの 勝手なまとめをアップしたいと思います。


jruby のためのメモであって、cruby1.8.7 では参考にはなるとは思いますが、異なる部分があると思います。私は cruby での検証はしてません。jruby はcruby1.8.7 とほぼ同じですが、まったく同じではありません。マルチバイト文字の扱い部分など。


nokogiri は言うまでもなく ruby用の xml や html 処理のためのライブラリです。
チュートリアルhttp://nokogiri.org/ から辿れます。(当然、英語)

それを見つつ、勝手に自分でまとめ直しつつ書いたメモです。
そのまま忠実に訳したものじゃありませんので、オリジナルのチュートリアルの内容は、かならず http://nokogiri.org/ で確認してください。
(そもそも、自分だけのためのメモでアップしようとは思ってなかったので)

動作の検証は
jruby 1.5.6 (ruby 1.8.7 patchlevel 249) (2010-12-03 9cf97c3) (Java HotSpot(TM) Client VM 1.6.0_22) [i386-java]
ubuntu 10.04
(したがってデフォの文字コードutf-8 にはじめからなっている状態)です。


nokogiri のインストールは、
jruby -S gem install nokogiri
または
sudo jruby -S gem install nokogiri
となりましょうか。( linux の場合ですけど)

nokogiri のバージョンは 1.4.4.2 というのが入ってました。次のバージョンからはかなり速くなると聞きました。(java版がデフォになるかららしいが、よく分かってませんw)


では、チュートリアル勝手まとめの前に、小手調べに nokogiri によるちょっとした html処理、基本サンプル を。


$KCODE = 'UTF8'

require 'rubygems'
require 'nokogiri'

html_doc = Nokogiri::HTML("<h1>こんにちは</h1>", nil, 'utf-8')

puts html_doc.class
puts "h1タグを検索する"
puts html_doc.search("h1")

#=> Nokogiri::HTML::Document
#=> h1タグを検索する
#=> <h1>こんにちは</h1>


# ## 後から encoding を指定する例


$KCODE = 'UTF8'

require 'rubygems'
require 'nokogiri'

html_doc = Nokogiri::HTML("<h1>こんにちは</h1>")
html_doc.encoding=("utf-8") # 後から encoding を指定する

puts html_doc.class
puts "h1タグを検索する"
puts html_doc.search("h1")

#=> Nokogiri::HTML::Document
#=> h1タグを検索する
#=> <h1>こんにちは</h1>


# ## 実行結果サンプル
# ## (実際に html を処理させた場合、デフォルトの header がどうなっているか確認してみる)

$KCODE = 'UTF8'

require 'rubygems'
require 'nokogiri'

html_doc = Nokogiri::HTML("<html><body><h1>Mr. Belvedere Fan Club</h1></body></html>")

puts html_doc

=begin

実行結果

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><h1>Mr. Belvedere Fan Club</h1></body></html>

=end


それでは、早速 nokogiri チュートリアル その1 を。


htmlやxml の処理をするには、まず、それらのドキュメントのオブジェクトを生成します。
(日本語の扱い方は、下の方の ※重要 日本語の扱い方 を参照)


# ○sample 1 (HTMLオブジェクトの生成)
html_doc = Nokogiri::HTML("<html><body><h1>Mr. Belvedere Fan Club</h1></body></html>")

# ○sample 2 (XMLオブジェクトの生成)
xml_doc = Nokogiri::XML("<root><aliens><alien><name>Alf</name></alien></aliens></root>")

# ○sample 3 (xmlファイルから XMLオブジェクトの生成)
f = File.open("blossom.xml")
doc = Nokogiri::XML(f)
f.close

# ○sample 4 (インターネットから HTMLオブジェクトの生成)
require 'open-uri'
doc = Nokogiri::HTML(open("http://www.threescompany.com/"))


解析オプション

Nokogiriはドキュメントが解析において、いくつかのオプションを提供します。

* NOBLANKS - 空白ノードを削除
* NOENT - 代替エンティティ
* NOERROR - エラーレポートの抑制
* STRICT - 厳密な解析;不正な文書を解析するときにエラーを発生させる


# ○sample 5 (解析オプションの使用例)
doc = Nokogiri::XML(File.open("blossom.xml")) do |config|
config.strict.noent
end

# または

doc = Nokogiri::XML(File.open("blossom.xml")) do |config|
config.options = Nokogiri::XML::ParseOptions.STRICT | Nokogiri::XML::ParseOptions.NOENT
end


※重要 日本語の扱い方

文字列は内部的には常に utf-8 として処理されます。
しかし日本語を扱う場合には、明示的にエンコーディングを指定する必要があるかもしれません。


# ○sample 6 (utf-8 であることを明示しての XMLオブジェクトの生成)
html_doc = Nokogiri::HTML("<h1>こんにちは</h1>", nil, 'utf-8')

xml_doc = Nokogiri::XML('<foo><bar /></foo>', nil, 'utf-8')

この項、まだまだ続きます。

Redcar 使い方 (ユーザー・ガイドを勝手に翻訳)

netbeans7.0 でrubyサポート廃止される件、その後、JRuby team が開発を引き継ぐことになったようで、とりあえずは安心してよさそうです。( JRuby team は大変でしょうけれど)

しかし、今後もなにが起こるか分からないので、JRuby 開発のための代替手段は考えておいた方がよさそうです。そんなわけで、 JRuby で動作するエディタ Redcar のユーザー・ガイドを勝手に訳してみました。

Redcar のプロジェクトのトップページはこちら。
http://redcareditor.com/

ユーザー・ガイドは上記のページの wiki の中にありました。
https://github.com/redcar/redcar/wiki/Users-Guide

私もとりあえず訳した範囲の事しか知りません。

機能としては、gnome標準のエディタである gedit と似たような水準かな。
起動は少し遅いですが、立ち上がってしまえば悪くないスピードです。(うちのマシンの cpu は core2duo 3GHz E8400です。その場合のスピードしか分かりません)

あえて使う理由としては、Ruby(JRuby) で書かれているから、Plugin などのカスタマイズも Ruby で書けるだろうということでしょうね。でも、大事なポイントだと思います。

が、ユーザーガイドの中には、Plugin の書き方などは含まれていません。別な文書があるのか、ソース見ろ、ということか。まだ調べてません。まあ、Plugin なんて書かずにすめばそれが一番ですが。

あと、ユーザーガイドを読んだだけでは、どうにも分かりにくい点がいくつかあります。数日後くらいには、気のついた補足説明をアップしたいなと思ってます。では。

以下、Redcar ユーザー・ガイドの勝手な翻訳(原文は青字)。


Users Guide What is Redcar


What is Redcar?
Redcar とは何ですか?

Redcar is an open-source programmers’ text editor for Ruby, written in Ruby. It is designed to be compatible with Textmate bundles (a work in progress) and run cross-platform on JRuby.
Redcar は、Rubyで書かれたRuby用のオープンソースプログラマー向けテキストエディタです。Macintosh上のエディタであるTextMateと互換性があり(作業中)、JRuby上でクロスプラットフォームに実行されるよう設計されています。


Getting Help
困ったときは

Redcar has an active group of users.The mailing list is the best place to post questions concerning Redcar.Help can also be found at on the #redcar IRC channel on FreeNode.Found a bug? File it on the Redcar Bug Tracker
Redcar は、活発なユーザー・グループがあります。
メーリングリストhttp://groups.google.com/group/redcar-editor )は、Redcar に関する質問を投稿するには最適の場所です。
ヘルプは、freenodeの##redcar IRC channel で見つけることができます。
バグの報告ファイルは the Redcar Bug Tracker ( https://redcar.lighthouseapp.com/dashboard )へ。


Users guide getting started

Getting Started
はじめに

Before using Redcar you must install it. Redcar will work on most Unix, Windows, and Mac platforms. Check the Platform Support Page for a list of all platforms Redcar has been tested on (mileage may vary).
Redcar を使用する前に、それをインストールする必要があります。Redcar がテストされているすべてのプラットフォームのリストについては、プラットフォームのサポートページ( https://github.com/redcar/redcar/wiki/List-of-Platforms )を確認してください。


Installation
インストール

Redcar can be installed on many versions of Windows, Unix, and Mac. Any platform that supports Java should support Redcar. Redcar will install the version of JRuby it needs during installation.
Redcar は、WindowsUnix、およびMacの多くのバージョンにインストールすることができます。Java をサポートするプラットフォームは、Redcar をサポートします。Redcar は、インストール時に必要なバージョンのJRubyをインストールします。

Prerequisites
前提条件

Redcar requires:
Redcar の動作要件

* Ruby 1.8.7 or later to be installed
* Ruby 1.8.7 以降がインストールされていること
* Java 1.4.0 or later to be installed
* Java 1.4.0 以降がインストールされていること


Installing on OS X
OS X 上でのインストール

Installation on OS X should be the same as on Linux.
linux と同じ。

Installing on Linux
Linuxへのインストール

Open a command shell and type the following two commands:
コマンドシェルを開き、次の二つのコマンドを打ちます。


sudo gem install redcar
redcar install

Installing on Windows
Windows上でのインストール

Make sure that the Ruby bin directory is in your path (e.g. c:\Ruby1.8.7\bin)
Rubyのbinディレクトリがパスに含まれていることを確認してください(例:c:\ Ruby1.8.7\ bin)
(要するに ruby が動作するようにしておいて下さい、という意味。コマンドプロンプトから ruby -v と打ったとき、ruby のバージョンが表示されますか? されなければ、ruby は動作してません)

Open a command prompt and type the following two commands:
コマンドプロンプトを開き、次の二つのコマンドを打ちます。


gem install redcar
redcar install


Building from Source
ソースからのビルド

To install the latest version of Redcar directly from the source tree run the following commands
ソースツリーから直接レッドカーの最新バージョンをインストールするには、次のコマンドを実行してください。


git clone git://github.com/redcar/redcar.git
cd redcar
git submodule init
git submodule update
jruby bin/redcar install
jruby -S rake build

See How to Contribute to learn the best practices for contributing the the Redcar Editor project.
Redcar エディター・プロジェクトに貢献するためのベストプラクティスを学ぶために貢献する方法を参照してください。( https://github.com/redcar/redcar/wiki/How-to-contribute

See Developing on Windows for tips on setting up github friendly test setup on Windows.
Windows上でgithubのフレンドリーなテストセットアップを設定するためのヒントについては、Windows上での開発を参照してください。( https://github.com/redcar/redcar/wiki/developing-on-windows


Users guide running redcar


Running Redcar
Redcar を実行する

Redcar can be run from a shortcut or from the command line.
Redcar は、ショートカットから、またはコマンドラインから実行することができます。


Common command line options
一般的なコマンドラインオプション

Running Redcar from the command line offers many additional options not exposed through the menu.
コマンドラインからRedcar を実行するメニューから、公開されていない多くの追加オプションを提供しています。
Typing redcar --help gives you the following information
redcar --help と入力すると情報を提供します。


redcar --help
Redcar 0.3.6 ( i386-mingw32 )
Usage: redcar [OPTIONS] [FILE|DIR]*
--multiple-instance Don't attempt to open files and dirs in an already running instance
--debug JRuby debugging mode: activates the profiling commands in the Debug menu
--untitled-file=PATH Open the given file as an untitled tab.
--ignore-stdin Ignore stdin

In addition the following command line options are available:


--font=FONT Choose font
--font-size=SIZE Choose font point size
--theme=THEME Choose Textmate theme

A complete list of themes can be found in the ${redcar-home}/plugins/textmate/vendor/redcar-bundles/themes and ~/.redcar/textmate/themes directory.
テーマの完全なリストは ${redcar-home}/plugins/textmate/vendor/redcar-bundles/themes または ~/.redcar/textmate/themes ディレクトリに見つけることができます。 


Navigating the UI
ユーザーインターフェースの案内

ユーザーインターフェースの画像


Main Window
メイン・ウィンドウ

The main window contains all of the other UI elements.
メインウィンドウには、他のUI要素のすべてが含まれています。

Menu Bar
メニューバー

The menu bar is a panel at the top of the main window. It contains 8 sub-menus by default. Plugins may add their own sub-menus or menu-items. See the section on Menus for additional information.
メニューバーには、メインウィンドウの上部にあるパネルです。これは、デフォルトでは8のサブメニューが含まれています。プラグインは独自のサブメニューまたはメニュー項目を追加することができます。追加情報については、メニューのセクションを参照してください。

Directory
ディレクト

The directory panel is only displayed when specifying a directory when opening Redcar or by using the Open Directory command (File » Open Directory).
ディレクトリパネルはレッドカーで開くディレクトリを指定するときに表示されたり、またはオープンディレクトリのコマンドを(ファイル→オープンディレクトリ)を使用したときに表示されます。

The directory panel displays a tree view of all of the files and sub directories under the selected directory. Directories are listed first and have a folder icon displayed to their left. Click on the little triangle displayed to the left of the folder icon or double click on the directory name or folder icon to open the directory. Click on the little triangle or double click the directory name or icon to close.
ディレクトリパネルには、選択したディレクトリの下にあるファイルとサブディレクトリのすべてのツリービューが表示されます。
ディレクトリが最初に表示され、その左側に表示されているフォルダのアイコンを持っています。
フォルダアイコンの左に表示される小さな三角形をクリックしてください。
またはディレクトリ名またはフォルダのアイコンをダブルクリックしてディレクトリを開きます。
小さな三角形をクリックするか、またはディレクトリ名をダブルクリック。またはアイコンを閉じて下さい。

Files are listed second and have a file icon to their left. Double click on the filename or file icon to open the file in a new Tab.
ファイルが2番目に表示され、その左にあるファイルのアイコンを持っています。新しいタブ上でファイルをオープンするために、ファイルネーム上でダブルクリックするか、ファイルアイコンをダブルクリックします。

Right click in the Directory pane to bring up a context menu. The following options are available on the context menu:
コンテキスト・メニューを表示するために、ディレクトリー・ペインで右クリックします。次のオプションは、コンテキストメニューで利用可能です:

New File – Creates a new file in the selected directory. The file is named “New File” by default.
New File – 選択したディレクトリに新しいファイルを作成します。ファイルは、デフォルトで"New File"と命名されます。

New Directory – Creates a new directory in the selected directory. The directory is named “New Directory” by default.
New Directory – 選択されたディレクトリ内に新しいディレクトリを作成します。ディレクトリは、デフォルトで"New Directory"という名前が付けられます。

Rename – Renames the selected file or directory.
Rename – 選択されたファイルやディレクトリをリネームします。

Delete – Deletes the selected file or directory. A prompt is displayed asking to confirm the operation. Click cancel to cancel the delete and leave the file or directory.
Delete – 選択されたファイルかディレクトリを削除します。操作の確認のためのプロンプトが表示されます。削除の取り消しのためには、キャンセルをクリックします。

Show Hidden Files/Hide Hidden Files – Shows hidden files and directories (e.g. .gitignore). Hidden files can be hidden again by selecting Hide Hidden Files.
Show Hidden Files/Hide Hidden Files – 隠しファイルとディレクトリを表示します。再度選択すると、再び隠されます。


Tabs
タブ

Tabs or listed across the top of the editor panel. The Tab title is the same as the file name (not including it’s path). New Tabs are given the label ‘untitled’. To switch between Tabs click on the other Tab’s tab area. It is also possible to switch between Tabs by using the Previous Tab (Ctrl-Page Up), Next Tab (Ctrl-Page Down), or Switch Tab (Alt-1..9) commands under the View menu.
タブはエディター・パネルの上部にリストされます。
タブのタイトルは、ファイル名(それのパスを含む)と同じです。
新しいタブは ‘untitled’ とラベルが与えられます。
他のタブの領域をクリックすることで、タブを切り替えられます。
また、Ctrl キーと Page Up キーの同時押しで、前のタブへ切り替えることが可能です
Ctrl キーと Page Down キーの同時押しで、次のタブへ切り替えることが可能です
また、Alt キーと1..9 の数字キーの同時押しでもタブを切り替えられます。

The order of Tabs may be changed by dragging a Tab’s tab area to a new position in the Tab list.
タブの順序は、タブのリスト内の新しい位置にタブをドラッグして変更することができます。

Tabs display an asterisks before the filename if the file has been modified since the last time it was opened or last saved (commonly referred to as dirty.)
ファイルが最後に保存された以降に変更されていて、まだ保存されていないとき、タブのファイル名の前にアスタリスクを表示します。


Editor Window
エディタ・ウィンドウ

The Editor Panel (also referred to the Editor Window) is the main area in Redcar. The Editor Panel is where you will view and edit the source code you are working on. The Editor panel will take on different appearance depending on the Theme selected. The Editor panel supports common navigation operations (Top, End, Page Down…), editing operations (Cut-Copy-Paste), Undo, Redo, Syntax Highlighting, and command/snippet completion.
エディタパネル(また、エディタウィンドウと呼ばれる)は、Redcar の主要なエリアです。
あなたが取り組んでいるソースコードを表示・編集する場所です。
エディタパネルには、選択したテーマに応じて異なる外観に変わります。
エディタパネルは、一般的なナビゲーション操作(トップ、終わり、Page Downキー...)をサポートしています。編集操作(カットコピーペースト)、元に戻す、やり直し、構文の強調表示、およびcommand/snippet(コマンド・断片的なコマンド)を使用します。


Speed Bars
スピードバー(上部のツールバーのことか?)

Speed bars are panels displayed at the button of the Editor panel. Only one Speed Bar can be displayed at a time. To close a Speed Bar click on the ‘X’ icon at the left end of the Speed Bar.
スピードバーは、エディタパネルのボタンに表示されるパネルです。一度にただ一つのスピードバーを表示できます。スピードバーの左端にある'X'アイコンをクリックしてスピードバーを閉じます。


Tab Info Speed Bar
タブ情報スピードバー( Edit メニューの一番最初の項目に tab info なるコマンドがあり、実行すると、ウィンドウ下部にバーが表示される。これのこと)

The Tab Info Speed bar displays tab specific settings.
タブ情報スピードバーでは、タブ固有の設定が表示されます。


Grammar
言語の文法(タブ情報スピードバー の中の項目として。言語が選択できる)

The language to use for syntax highlighting. There are about 80 plus languages provided in the default bundles inside of Redcar.
言語の構文をハイライト表示します。Redcar は80以上の言語のサポートをします。


Tab Size
タブサイズ(タブ情報スピードバー の中の項目として。タブ幅が選択できる)

The number of characters that a tab character represents: the values may lie between 2 and 8 characters.
2から8文字幅で、タブ幅を選択できる。


Soft Tabs
ソフト・タブ(タブ情報スピードバー の中の項目として)

This option allows you to switch between using real tab characters when you press the tab key (often referred to as Hard Tabs) or to use an equivalent number of spaces (as specified in the Tab Size drop down).
タブとして、半角スペースを使うか、実際のタブ文字を使うか切り替える。


Word Wrap
折り返し(タブ情報スピードバー の中の項目として)

Wraps the contents on screen at the end of the visible screen (the file contents are not modified.)
ファイルの内容葉変更せずに、画面上の指定の端で文を折り返します。


Margin
マージン(タブ情報スピードバー の中の項目として)

Displays text that extends beyond the margin column in a different background color.
(テキストの折り返し位置を表示するか切り替える)


Margin Column
マージン幅(タブ情報スピードバー の中の項目として)

Sets the column that the margin color will take affect on.
文の折り返し位置を指定する。


Goto Line Speedbar
ライン・スピードバーへ(vier メニューの項目 Show Line Numbers で表示される行番号表示欄)

The Goto Line Speedbar displays a simple speedbar that allows you to enter in a line number.
あなたが入力するにしたがって、行番号が表示される。

Line Number
ライン・ナンバー(Edit メニューの Document Navigation で表示される)

Sets the line number to go to
設定した行番号へ飛ぶ

Go Button
ボトムへ(Edit メニューの Document Navigation で表示される)

Jumps to the line specified in the line number field.
文の末尾へ飛ぶ


Regex Search Speedbar
正規表現スピードバー(Edit メニューの Find からFind を選択すると検索ダイアログが出てくる。デフォルトで plain と表示されてるボックスから redexp を選択できるが、それのことか?)

Search Term
Regex
Match case
(大文字・小文字を区別するかしないか)
Search Button


Menus
メニュー

The menu system in Redcar is extremly flexible. The menu items described here refer to the most recent version with the default plugins installed. Additonal plugins may add addtional menu items. Keyboard shortcuts are included but may also be changed by additional plugins.
Redcar のメニューシステムがとても柔軟性があります。
デフォルトのプラグインが導入された最新バージョンのメニュー項目を説明します。
追加されたプラグインは、メニュー項目を追加する事があります。
キーボードショートカットが含まれていますが、追加プラグインによって変更されることがあります。


File
ファイル (メニューとして)

New Ctrl-N | Cmd-N

Opens a new tab in the current edtior window. The tab defaults to Plain Text and the default settings for Word Wrap and Margin width.

現在の編集ウィンドウで新しいタブを開く。そのタブの初期設定はプレーンなテキストで、折り返しとマージン幅の初期値が使われる。

New Window Ctrl-Alt-N | Cmd-Alt-N

Opens a new editor window.
新しい編集ウィンドウを開く。

Open Ctrl-O | Cmd-O

Open Directory Ctrl-Shift-O | Cmd-Shift-O
ディレクトリを開く。

Open Recent

Displays a list of the most recently opened files.
最近開いたファイルの一覧を表示します。

Save Ctrl-S | Cmd-S

Saves contents of the currently opened tab using the file name of the tab. If the tab does not have a name then a Save-As dialog is displayed.
タブのファイル名を使用して、現在開いているタブの保存内容を保存します。
その名前を持っていない場合は、Save-As ダイアログを表示して保存します。

Save As Ctrl-Shift-S | Cmd-Shift-S

Saves the contents of the currently opened tab prompting for a new file name. The tab is renamed to the new file name.
現在開いているファイルを、新しいファイル名で保存します。タブの名は、その新しいファイル名に変わります。

Close Tab Ctrl-W | Cmd-W

Closes the currently opened tab. If the tab has unsaved content then you are prompted to save the tab.
現在開いているタブを閉じます。もしそのタブを保存していなければ、保存するよう求められます。

Close Window Ctrl-Shift-W | Cmd-Shift-W

Closes the currently opened window. All tabs are closed as well. Any tabs with unsaved contents will prompt you to save the data before exiting.
現在開いているウィンドウを閉じます。すべてのタブも閉じられます。もし保存していなければ、保存が求められます。

Close Directory Quit Ctrl-Q | Cmd-Q

Quits all windows. If any of the windows contain tabs with unsaved contents you will be prompted to save the tab before exiting.
すべてのウィンドウを終了します。内容が保存されていないタブがあれば、保存を求められます。


Edit
編集(メニューとして)

Tab Info Ctrl-Shift-E | Cmd-Shift-E

Displays the Tab Info Speed Bar at the bottom of the Tab window. See Tab Info Speed Bar for more details.

選択すると、タブウィンドウの下部にタブ情報スピードバーが表示される。

Undo Ctrl-Z | Cmd-Z

Undoes the last action.
直前の操作を取り消す。

Redo Ctrl-Y | Cmd-Y

Redoes the last undo action.
最後に取り消した命令をやり直す。

Cut Ctrl-X | Cmd-X
カット

Copy Ctrl-C | Cmd-C
コピー

Paste Ctrl-V | Cmd-V
ペースト

Duplicate Region Ctrl-D | Cmd-D

DocumentNavigation
Goto Line
Top
Home
End
Buttom

Increase Indent
Decrease Indent

Regex Search

Repeat Last Search

Select
All
Line
Toggle Block Selection

Auto Complete
自動補完

Menu Auto Complete
自動補完メニュー


Project

Find File
Refresh Directory


Debug

Task Manager
Print Scpone at Cursor


View

Appearance
Font
Font Size
Theme

New Notebook Ctrl-Shift-N | Cmd-Shift-N
新規ノートブック( View メニューの項目として)
(注 開いたファイルのタブをドラッグして、別のノーブックへそのタブを移動できる機能)

Opens a new notebook. Only two notebooks may be opened at a time. Tabs may be moved between notebooks by dragging the Tab’s tab area from one to the other or by using the Move Tab to Other Notebook
新しいノートブックを開く。2つだけのノートブックは、一度に開くことができます。
タブは、一方から他方へのタブをドラッグするか、その他のノートブックにタブを移動して、ノート間で移動することができる

Close Notebook
ノートブックを閉じる

Closes a notebook. At least one notebook must be left open. All of the open Tabs are moved to the remaining notebook.
ノートブックを閉じます。
少なくとも1つのノートブックをオープンしておく必要があります。
開いているタブのすべては、残りのノートブックに移動されます。

Rotate Notebook
ノートブックを回転させる

Rotates the notebooks between horizontal and vertical orientation.
ノートブックを水平・垂直に回転させます。

Move Tab to Other Notebook Ctrl-Shift-Alt-O | Cmd-Shift-Alt-O
タブを他のノートブックへ移動

Moves the current tab to the other notebook.
現在のタブを他のノートブックへ移動させます。

Switch Notebooks Ctrl-Alt-O | Cmd-Alt-O
ノートブックの切り替え

Switches the focus from the active Tab in the active notebook to the active Tab in the inactive notebook.
アクティブなタブから、別のノートブックのタブへフォーカスを移動。

Previous Tab
Next Tab
Switch Tab
Tab 1..9
Toggle Invisible
Toggle Line Numbers
Toggle Annotations


Plugins

Plugin Manager
Reload Again
Edit Preferences
Plugin Specfic


Bundles

Find Snippet


Help

About
New in This Version


Themes

Themes allow you to change the appearance of the Editor panel, they do not affect the appearance of the rest of the application.
テーマは、エディタパネルの外観を変更します。アプリケーションの残りの部分の外観には影響しません。


keyboard shortcuts
キーボード・ショートカット(詳細、略。Redcar のHelp メニューの項目に一覧あり)

netbeans 7 では Rails サポートどころか Ruby サポートも廃止される模様…

あひゃー、
netbeans 最新開発版を見てみたら、Rails どころか Ruby サポートも廃止されてたわ(笑)
いや、笑い事ではないけどー。
Jruby Team がなんとかするらしい、という話も流れているけど、はっきり分からないし。
私はいま、Redcar のユーザーガイドを勝手に訳しているよ。
もう、どうとでもなれ。
Jruby Team が頑張ってくれたら嬉しいけど、彼らも忙しいだろうしなぁ。


※ その後、netbeans7 のruby サポートの公式版廃止の件は Jruby Team がコミュニティー版として引き継ぐ事に決まったようです。