Between design and implementation

I'm a monster but not evil

Windows7 64bitでjekyllをセットアップする祭

何かナウなヤングはモダンなブログシステムをGitHubPagesで使うらしいので試してみたくなった。

Rubyのオレオレビルドを作り始めたりすると目的を見失いかねないので簡単そうなインストーラを使う。

rubyinstaller.org

rubyinstaller-1.9.3-p125.exe

をダウンロードしてインストール。

Gitクライアントが必要らしいが、msysgitはハマるので普段使っているegitを使う。

egit

後は、Jekyllのドキュメント通りにやる感じで。

Jekyll Quick Start

1
 gem install jekyll

エラーがでよる…

どうやらDevKitというやつをインストールしないといけないらしい。

1
2
3
4
5
6
7
8
 Fetching: liquid-2.3.0.gem (100%)
 Fetching: fast-stemmer-1.0.0.gem (100%)
 ERROR:  Error installing jekyll:
        The 'fast-stemmer' native gem requires installed build tools.

 Please update your PATH to include build tools or download the DevKit
 from 'http://rubyinstaller.org/downloads' and follow the instructions
 at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'

DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe

は単なる自己解凍書庫なので指定したパスに何か色々解凍される。
とりあえずこのパスに解凍した。

C:\Ruby193\devkit

エラーメッセージに入ってるURLに書いてある通りに操作する。

1
2
3
4
5
6
7
8
 cd C:\Ruby193\devkit
 ruby dk.rb init

 [INFO] found RubyInstaller v1.9.3 at C:/Ruby193
 
 Initialization complete! Please review and modify the auto-generated
 'config.yml' file to ensure it contains the root directories to all
 of the installed Rubies you want enhanced by the DevKit.

config.ymlが生成されてさっきインストールしたrubyのパスが入っている。
僕の環境にはRubyは1つしか無いので特に修正する必要は無いようだ。
何かdevkitのインストール的なアレを実行。

1
2
3
4
 ruby dk.rb install

 [INFO] Updating convenience notice gem override for 'C:/Ruby193'
 [INFO] Installing 'C:/Ruby193/lib/ruby/site_ruby/devkit.rb'

何かメッセージが出た。成功したのかね。テストインストールしてみれとあるのでやる。

1
2
3
4
5
6
7
8
9
 gem install rdiscount --platform=ruby

 Fetching: rdiscount-1.6.8.gem (100%)
 Temporarily enhancing PATH to include DevKit...
 Building native extensions.  This could take a while...
 Successfully installed rdiscount-1.6.8
 1 gem installed
 Installing ri documentation for rdiscount-1.6.8...
 Installing RDoc documentation for rdiscount-1.6.8...

ズラズラとログが流れる。上手くいってる様だ。
このrdiscountが動くかどうか確かめる。

1
2
3
 ruby -rubygems -e "require 'rdiscount'; puts RDiscount.new('**Hello RubyInstaller**').to_html"
 
 <p><strong>Hello RubyInstaller</strong></p>

それっぽいHTMLが標準出力されるので動いている。

では、もう一回jekyllをインストールしようとしてみる。

1
 gem install jekyll

沢山のログがでる。上手くいっている様だ。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 Temporarily enhancing PATH to include DevKit...
 Building native extensions.  This could take a while...
 Fetching: classifier-1.3.3.gem (100%)
 Fetching: directory_watcher-1.4.1.gem (100%)
 Fetching: syntax-1.0.0.gem (100%)
 Fetching: maruku-0.6.0.gem (100%)
 Fetching: kramdown-0.13.5.gem (100%)
 Fetching: posix-spawn-0.3.6.gem (100%)
 Building native extensions.  This could take a while...
 Fetching: albino-1.3.3.gem (100%)
 Fetching: jekyll-0.11.2.gem (100%)
 Successfully installed fast-stemmer-1.0.0
 Successfully installed classifier-1.3.3
 Successfully installed directory_watcher-1.4.1
 Successfully installed syntax-1.0.0
 Successfully installed maruku-0.6.0
 Successfully installed kramdown-0.13.5
 Successfully installed posix-spawn-0.3.6
 Successfully installed albino-1.3.3
 Successfully installed jekyll-0.11.2
 9 gems installed
 Installing ri documentation for fast-stemmer-1.0.0...
 Installing ri documentation for classifier-1.3.3...
 Installing ri documentation for directory_watcher-1.4.1...
 Installing ri documentation for syntax-1.0.0...
 Installing ri documentation for maruku-0.6.0...
 Couldn't find file to include 'MaRuKu.txt' from lib/maruku.rb
 Installing ri documentation for kramdown-0.13.5...
 Installing ri documentation for posix-spawn-0.3.6...
 Installing ri documentation for albino-1.3.3...
 Installing ri documentation for jekyll-0.11.2...
 Installing RDoc documentation for fast-stemmer-1.0.0...
 Installing RDoc documentation for classifier-1.3.3...
 Installing RDoc documentation for directory_watcher-1.4.1...
 Installing RDoc documentation for syntax-1.0.0...
 Installing RDoc documentation for maruku-0.6.0...
 Couldn't find file to include 'MaRuKu.txt' from lib/maruku.rb
 Installing RDoc documentation for kramdown-0.13.5...
 Installing RDoc documentation for posix-spawn-0.3.6...
 Installing RDoc documentation for albino-1.3.3...
 Installing RDoc documentation for jekyll-0.11.2...

Jekyllを動かす為にテンプレートとなるファイルをgit cloneする。

https://github.com/plusjade/jekyll-bootstrap.git

ブランチは全部とり込む。

出力先ディレクトリは作業用のものを指定する。例えばこんな感じ。 C:\development\ruby\taichi.github.com

で、当該ディレクトリに移動してJekyllをサーバモードで起動する。

1
2
 cd C:\development\ruby\taichi.github.com
 jekyll --server

どうもしっくりこないので、Octopress も試してみる事にする。

Octopress - Setup

RVMかrbenvが必要との事。無視して先の作業をやってみたが、

どうやら1.9.2に完全限定している様で1.9.3では動かない。最高に痺れる。

Windowsで複数のRubyランタイムをインストールするにはpikを使うらしい。

という訳でpikをインストール。

1
 gem install pik

PATH環境変数において現在動作しているRubyランタイムよりも前の部分にpikの環境をインストール為のディレクトリを指定する。

c:\pik;C:\Ruby193\bin

という風になる。

で、更にpikのインストール用シェルスクリプトを実行。

1
 pik_install C:\pik

pikを使ってruby1.9.2をインストールする。

1
2
3
4
5
6
7
8
9
 pik install ruby 1.9.2

 ** Downloading:  http://rubyforge.org/frs/download.php/71175/ruby-1.9.2dev-preview3-i386-mingw32-1.7z
   to:  C:\Users\taichi\.pik\downloads\ruby-1.9.2dev-preview3-i386-mingw32-1.7z
 
 ruby-1.9.2dev-preview3-i...7z: 100% |oooooooooo|   5.7MB/  5.7MB Time: 00:01:05
 
 You need the 7zip utility to extract this file.
 Would you like me to download it? (yes/no)  |yes|

yesしろと言っているのでyesと入力してEnter

やっとOctopressをcloneする。

git://github.com/imathis/octopress.git

ブランチは面倒なので全部とり込む。

出力先ディレクトリは作業用のものを指定する。

例えばこんな感じ。

C:\development\ruby\octpress

作業用のディレクトリに移動。

1
 cd C:\development\ruby\octpress

pikで1.9.2にrubyをスイッチ

1
 pik 192

bundlerを1.9.2環境にインストールする。

1
 gem install bundler

続けて、何か色々詰まったアレをインストールする。

1
2
3
4
5
6
7
8
9
10
11
 bundle install

 Fetching gem metadata from http://rubygems.org/.......
 Installing rake (0.9.2)
 Installing RedCloth (4.2.8) with native extensions Unfortunately, a fatal error has occurred. Please report this error to the Bundler issue tracker at https://github.com/carlhuda/bundler/issues so that we can fix it. Thanks!
 C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:483:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
 C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/bin/ruby.exe extconf.rb
 checking for main() in -lc... *** extconf.rb failed ***
 Could not create Makefile due to some reason, probably lack of
 necessary libraries and/or headers.  Check the mkmf.log file for more
 details.  You may need configuration options.

nativeなアレがインストール出来ないと言っている。

これはつまり、pikで構築した1.9.2環境にdevkitが入っていない為、怒られている。

devkitのディレクトリにはさっき使ったconfig.ymlがあるのでそれを修正する。

先ほどのエラーメッセージ内に1.9.2ランタイムが格納されているディレクトリが出力されているので、それをコピペ。

1
 - C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1

devkitを1.9.2環境にインストールする。
pikではコマンドプロンプト単位でしかrubyランタイムがスイッチされないので、
新しいプロンプトを起動したのなら明示的にスイッチしてからインストール。

1
2
 pik 192
 ruby dk.rb install

気を取りなおして色々詰まったアレをインストール。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 bundle install

 Fetching gem metadata from http://rubygems.org/.......
 Using rake (0.9.2)
 Installing RedCloth (4.2.8) with native extensions
 Installing posix-spawn (0.3.6) with native extensions
 Installing albino (1.3.3)
 Installing blankslate (2.1.2.4)
 Installing chunky_png (1.2.1)
 Installing fast-stemmer (1.0.0) with native extensions
 Installing classifier (1.3.3)
 Installing fssm (0.2.7)
 Installing sass (3.1.5)
 Installing compass (0.11.5)
 Installing directory_watcher (1.4.0)
 Installing ffi (1.0.9)
 Installing haml (3.1.2)
 Installing kramdown (0.13.3)
 Installing liquid (2.2.2)
 Installing syntax (1.0.0)
 Installing maruku (0.6.0)
 Installing jekyll (0.11.0)
 Installing rubypython (0.5.1)
 Installing pygments.rb (0.1.3)
 Installing rack (1.3.2)
 Installing rb-fsevent (0.4.3.1) with native extensions
 Installing rdiscount (1.6.8) with native extensions
 Installing rubypants (0.2.0)
 Installing tilt (1.3.2)
 Installing sinatra (1.2.6)
 Installing stringex (1.3.0)
 Using bundler (1.1.0)
 Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

今度は入った様だ。Octopressのディレクトリに移動する。

1
 cd C:\development\ruby\octpress

Octopressのテーマをインストールする。

1
 rake install

GitHubPagesにデプロイする予定なので、その為の作業を行う。

詳細はここに書いてある。

Deploying to Github Pages

ここにきてコマンドプロンプトで動くGitが無いとダメ等と言われたので仕方なくmsysgitをインストール。

msysgit/download

インストールディレクトリに半角スペースが含まれていると地獄を見る事になるので、その様な事がないようにディレクトリを選択する。

エクスプローラの拡張とかされても邪魔なだけなので全部外す。

Windowsのコマンドプロンプトから実行する。

改行コードを自動変換するとトラブるので無変換

GitHubPages用のセットアップを開始する。

1
2
3
4
5
6
7
8
9
10
11
12
13
 rake setup_github_pages

 Enter the read/write url for your repository: git@github.com:taichi/taichi.github.com.git
 Added remote git@github.com:taichi/taichi.github.com.git as origin
 Set origin as default remote
 Master branch renamed to 'source' for committing your blog source files
 Initialized empty Git repository in C:/development/ruby/octpress/_deploy/.git/
 'My Octopress Page is coming soon
 'hellip' は、内部コマンドまたは外部コマンド、
 操作可能なプログラムまたはバッチ ファイルとして認識されていません。
 [master (root-commit) 7001a8d] Octopress init
  0 files changed, 0 insertions(+), 0 deletions(-)
  create mode 100644 index.html

何かきいた事も無いようなコマンドを実行しようとしてエラーが出てindex.htmlが中身の無いものになるので、 Rakefileの336行目を修正する。

1
2
 -- 336 system "echo 'My Octopress Page is coming soon …' > index.html"
 ++ 336 system "echo 'My Octopress Page is coming soon ' > index.html"

静的コンテンツの生成を行う。

1
 rake generate

テスト的にデプロイしてみる。

1
 rake deploy

空っぽの何かがデプロイされた。鍵とかアカウント的なアレはOKな様だ。

新しいエントリを作る。

1
 rake new_post["setup_Octopress_on_Windows7_x64"]

この文章を出来たmarkdownファイルにコピペした上でコンテンツの生成。

1
 rake generate

エンコーディングのエラーが出る。マジ痺れる。サイコーだ。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 ## Generating Site with Jekyll
 unchanged sass/screen.scss
 Configuration from C:/development/ruby/octpress/_config.yml
 Building site: source -> public
 C:/development/ruby/octpress/plugins/raw.rb:11:in `gsub': invalid byte sequence in Windows-31J (ArgumentError)
        from C:/development/ruby/octpress/plugins/raw.rb:11:in `unwrap'
        from C:/development/ruby/octpress/plugins/octopress_filters.rb:18:in `post_filter'
        from C:/development/ruby/octpress/plugins/octopress_filters.rb:30:in `post_render'
        from C:/development/ruby/octpress/plugins/post_filters.rb:124:in `block in post_render'
        from C:/development/ruby/octpress/plugins/post_filters.rb:123:in `each'
        from C:/development/ruby/octpress/plugins/post_filters.rb:123:in `post_render'
        from C:/development/ruby/octpress/plugins/post_filters.rb:151:in `transform'
        from C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/lib/ruby/gems/1.9.1/gems/jekyll-0.11.0/lib/jekyll/convertible.rb:84:in `do_layout'
        from C:/development/ruby/octpress/plugins/post_filters.rb:167:in `do_layout'
        from C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/lib/ruby/gems/1.9.1/gems/jekyll-0.11.0/lib/jekyll/post.rb:189:in `render'
        from C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/lib/ruby/gems/1.9.1/gems/jekyll-0.11.0/lib/jekyll/site.rb:193:in `block in render'
        from C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/lib/ruby/gems/1.9.1/gems/jekyll-0.11.0/lib/jekyll/site.rb:192:in `each'
        from C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/lib/ruby/gems/1.9.1/gems/jekyll-0.11.0/lib/jekyll/site.rb:192:in `render'
        from C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/lib/ruby/gems/1.9.1/gems/jekyll-0.11.0/lib/jekyll/site.rb:40:in `process'
        from C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/lib/ruby/gems/1.9.1/gems/jekyll-0.11.0/bin/jekyll:250:in `<top (required)>'
        from C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/bin/jekyll:19:in `load'
        from C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/bin/jekyll:19:in `<main>'

RubyではLANG環境変数を見てアレコレする様なので、環境変数を設定する。

1
 set LANG=ja_JP.utf8

今度こそ…

1
 rake generate

生成されたリソースを確認する。

1
2
3
4
5
 rake preview

 Starting to watch source with Jekyll and Compass. Starting Rack on port 4000
 Configuration from C:/development/ruby/octpress/_config.yml
 Auto-regenerating enabled: source -> public

という訳でWEBrickにブラウザでアクセス。

何か出来たけどレイアウトgdgdなので、Markdown記法を再確認しながら調整。

編集しているといつの間にか更新しても反映されなくなっておかしいな…と思ったのでWEBrickを停止してgenerateしてみる。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
 rake generate

## Generating Site with Jekyll
unchanged sass/screen.scss
Configuration from C:/development/ruby/octpress/_config.yml
Building site: source -> public
  File "<string>", line 1
    'import
          ^
SyntaxError: EOL while scanning string literal
  File "<string>", line 1
    'import
          ^
SyntaxError: EOL while scanning string literal
C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/lib/ruby/gems/1.9.1/gems/ffi-1.0.9-x86-mingw32/lib/ffi/library.rb:75:in `block in ffi_lib': Could not open library '.dll': 指定された(LoadError)見つかりません。
        from C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/lib/ruby/gems/1.9.1/gems/ffi-1.0.9-x86-mingw32/lib/ffi/library.rb:54:in `map'
        from C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/lib/ruby/gems/1.9.1/gems/ffi-1.0.9-x86-mingw32/lib/ffi/library.rb:54:in `ffi_lib'
        from C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/lib/ruby/gems/1.9.1/gems/rubypython-0.5.1/lib/rubypython/python.rb:29:in `<module:Python>'
        from C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/lib/ruby/gems/1.9.1/gems/rubypython-0.5.1/lib/rubypython/python.rb:21:in `<top (required)>'
        from C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/lib/ruby/gems/1.9.1/gems/rubypython-0.5.1/lib/rubypython.rb:261:in `load'
        from C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/lib/ruby/gems/1.9.1/gems/rubypython-0.5.1/lib/rubypython.rb:261:in `reload_library'
        from C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/lib/ruby/gems/1.9.1/gems/rubypython-0.5.1/lib/rubypython.rb:104:in `start'
        from C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/lib/ruby/gems/1.9.1/gems/pygments.rb-0.1.3/lib/pygments/ffi.rb:8:in `start'
        from C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/lib/ruby/gems/1.9.1/gems/pygments.rb-0.1.3/lib/pygments/ffi.rb:82:in `highlight'
        from C:/development/ruby/octpress/plugins/pygments_code.rb:24:in `pygments'
        from C:/development/ruby/octpress/plugins/pygments_code.rb:14:in `highlight'
        from C:/development/ruby/octpress/plugins/backtick_code_block.rb:37:in `block in render_code_block'
        from C:/development/ruby/octpress/plugins/backtick_code_block.rb:13:in `gsub'
        from C:/development/ruby/octpress/plugins/backtick_code_block.rb:13:in `render_code_block'
        from C:/development/ruby/octpress/plugins/octopress_filters.rb:12:in `pre_filter'
        from C:/development/ruby/octpress/plugins/octopress_filters.rb:27:in `pre_render'
        from C:/development/ruby/octpress/plugins/post_filters.rb:112:in `block in pre_render'
        from C:/development/ruby/octpress/plugins/post_filters.rb:111:in `each'
        from C:/development/ruby/octpress/plugins/post_filters.rb:111:in `pre_render'
        from C:/development/ruby/octpress/plugins/post_filters.rb:166:in `do_layout'
        from C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/lib/ruby/gems/1.9.1/gems/jekyll-0.11.0/lib/jekyll/post.rb:189:in `render'
        from C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/lib/ruby/gems/1.9.1/gems/jekyll-0.11.0/lib/jekyll/site.rb:193:in `block in render'
        from C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/lib/ruby/gems/1.9.1/gems/jekyll-0.11.0/lib/jekyll/site.rb:192:in `each'
        from C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/lib/ruby/gems/1.9.1/gems/jekyll-0.11.0/lib/jekyll/site.rb:192:in `render'
        from C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/lib/ruby/gems/1.9.1/gems/jekyll-0.11.0/lib/jekyll/site.rb:40:in `process'
        from C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/lib/ruby/gems/1.9.1/gems/jekyll-0.11.0/bin/jekyll:250:in `<top (required)>'
        from C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/bin/jekyll:19:in `load'
        from C:/Users/taichi/.pik/rubies/Ruby-192dev-preview3-1/bin/jekyll:19:in `<main>'

問題の原因はこの辺らしい。

Octopressのコードブロックでutf-8が使えないのが直った

パッチはどうやら取り込まれていて、rubypython-0.5.3というのがリリース済な様だ。

ライブラリのアップデートをかける。

1
2
 gem update
 bundle update

ちょっと雑にアップデートし過ぎたかな…。これでも同じ様にエラーがでて上手く動かない。

更に調べていくと、rubypython-0.5.3 でもまだ適切に動作しない様だ。

Lib.so issues when calling Pygments::Lexer

この中を読んでいくと、コードを修正したら上手く動いたよとある。

こんな感じのパスにpythonexec.rbというファイルがあるので当該箇所を修正してみる。

1
2
3
4
C:\Users\taichi\.pik\rubies\Ruby-192dev-preview3-1\lib\ruby\gems\1.9.1\gems\rubypython-0.5.3\lib\rubypython\pythonexec.rb

-- 126 %x(#{@python} -c "#{command}").chomp if @python
++ 126 %x("#{@python} -c #{command}").chomp if @python

126行目のダブルクォーテーションの位置が問題らしい。

という訳で一晩かかってOctopressが動きましたとさ。。。もう疲れたよ…

一応、考えられる事を整理しておこう。

OctopressなのかJekyllなのか分からないけど、何かエラーが発生した時に黙って正常終了した上で、
出力されるテキストファイルが0KBになるのは色々間違っている。

rubypythonは、その名前から類推可能な程度にはヤバいモジュールで近づくと焼かれる。

Jekyllの問題でもOctopressの問題でも無く、backtickの問題なんだろうけど、
_config.ymlでpygments: falseになってるのにcode block使うとpygmentsが動くのは騙し討ちとしか思えない。
どう考えてもおかしい。結局Octopressってあんまり使われてないんじゃねぇの?

gemsだのbundleだの何か色々ありすぎて門外漢にとっては辛い。 似たような機能であるかの様な印象をうけるものが複数あるのは普通にドハマリする。 bundle updateしたら、gem updateってしなくても良かったんかな?

Rubyランタイム入れてリポジトリをcloneした後に、

1
rake install

で全て終るようにして欲しい。

GitHubPagesはpushした後、反映されるまで数分掛かるので、その時間待ちがダルい。
プロダクトサイトとして使うのは悪くない気がするけど、Blogとして使うのはイマイチ感タプシ。

当分Rubyとは遊ばない。