helen's blog

ずっとおもしろいことしてたいな。

tomdocが思いの外大変だった話

helen.hatenablog.com

先の記事のpygmentsを入れるに至った理由がTomdocです
StyleGuideでpretty sweetとされているドキュメントがtomdocだったため
RdocからTomdocへ変更になり、その対応をしました

# Public: Duplicate some text an arbitrary number of times.
#
# text  - The String to be duplicated.
# count - The Integer number of times to duplicate the text.
#
# Examples
#
#   multiplex('Tom', 4)
#   # => 'TomTomTomTom'
#
# Returns the duplicated String.
def multiplex(text, count)
 text * count
end
  • Gemfile
gem 'tomdoc', '~> 0.2.5'

tomdoc | RubyGems.org | your community gem hostより

これででいい感じのドキュメントを生成してくれるはずでしたが

  • 実行
$ bundle exec tomdoc -c ./app/helpers/application_helper.rb
pygmentize: コマンドが見つかりません

pygmentsのgemを入れてみるが
pygments.rb | RubyGems.org | your community gem host

  • Gemfileに追加
gem 'pygments.rb', '~> 0.6.3'
$ bundle exec tomdoc ./app/helpers/application_helper.rb
in `spawn': No such file or directory - pygmentize (Errno::ENOENT)

pygmentizeが無いって言ってきました

VagrantにpipとPygmentsを入れて、Ansibleに組み込んだらみんな幸せになった話 - helen's blog
gemではなくpipからpygmentsを入れても同じくエラー

天の声:tomdocのバージョン古くね?

$ bundle exec tomdoc -v
TomDoc v0.2.5

ドキュメントでは1.0.0rcだったはずだぞ...

最終的に

  • Gemfile
# Use tomdoc for generate documentation
gem 'tomdoc', github: 'defunkt/tomdoc',
              branch: 'tomdoc.rb'

tomdocのgemが古いらしいので
tomdocをgithubの'defunkt/tomdoc'リポジトリ指定、
ブランチは 'tomdoc.rb' 指定でインストールしました

$ bundle exec tomdoc -i <filename>
-------------------------------------------------------------------
ApplicationHelper#multiplex(text, count)
Public: Duplicate some text an arbitrary number of times.
text  - The String to be duplicated.
count - The Integer number of times to duplicate the text.
Examples
  multiplex('Tom', 4)
  # => 'TomTomTomTom'
Returns the duplicated String.

成功!
結局バージョンは0.2.5ですが
こちらのほうが安定版のようです

ちなみにHTML形式の出力もできます

$ bundle exec tomdoc -f html <filename>
<ul>
<li><b>ApplicationHelper#multiplex(text, count)</b><pre>Public: Duplicate some text an abitrary number of times.
text  - The String to be duplicated.
count - The Integer number of times to duplicate the text.
Examples
  multiplex('Tom', 4)
  # => 'TomTomTomTom'
Returns the duplicated String.</pre></li>
</ul>


参考
TomDoc 1.0.0-rc1
Ruby · Styleguide · GitHub