èªåææ¸æ¤æ»ãã¼ã«RedPenãRubyãã使ããredpen-rubyãæ¸ãã¦ã¿ã¾ãã
æè¿ãRedPenã¨ããæè¡ææ¸åãæ ¡æ£ãã¼ã«ãç¥ãã¾ãããRedPenã«ã¤ãã¦ã¯ãRedPenã使ã£ã¦æè¡ææ¸ãæ軽ã«æ ¡æ£ãããï¼é£è¼ï½gihyo.jp ⦠æè¡è©è«ç¤¾ã«è©³ãã説æãããã¾ãã
æ¬æ ¼çã«æç« ãæ¸ãããã«ãªãããããã£ããã¼ã«ãæ±ãã¦ãããããæ©é試ãã¦ã¿ããã¨ã«ããã®ã§ãããepubcheckãepub_validatorã使ã£ã¦ãã身ã¨ãã¦ã¯ãRedPenãRubyãã使ããããªãã¨æã£ãã®ã§ãæè§ãªã®ã§æè¿è¦ããRubyã使ã£ã¦epub_validatorã®ã³ã¼ããåèã«ã©ããã¼ãã¼ã«ãä½ã£ã¦ã¿ããã¨ã«ãã¾ããã
RedPenRuby is a Ruby wrapper for redpen: a text inspection tool.
ã¨ãããããå¸æããåä½ã確ä¿ã§ããã®ã§ãGitHubã«ãªãã¸ããªãå ¬éãã¦ãRubyGems.orgã«ãç»é²ãã¾ããã
ã¤ã³ã¹ãã¼ã«ã¨ä½¿ãæ¹
GitHubã®README.mdã«ãè¨è¼ãã¦ãã¾ãããããã§ã解説ãã¦ããã¾ãã
ã¤ã³ã¹ãã¼ã«
RubyGems.orgã«ç»é²ãã¦ããã¾ãã®ã§ã
$ gem install redpen_ruby
ã§ã¤ã³ã¹ãã¼ã«ã§ãã¾ãããããã¯ãGemfileã«
gem 'redpen_ruby'
ã¨è¨å ¥ãã¦ã
$ bundle install
ãå®è¡ãã¾ãããã
ã³ãã³ãã©ã¤ã³ããã®ä½¿ãæ¹
ã¾ããã³ãã³ãã©ã¤ã³ããã®ä½¿ãæ¹ã§ãããgem install redpen_ruby
ã§ã¤ã³ã¹ãã¼ã«ãã¦ããå ´åã$ redpen_ruby /path/to/config_file /path/to/target_file
ã¨ããå½¢å¼ã§å®è¡ã§ãã¾ãã
$ redpen_ruby ./lib/redpen-cli-1.0/conf/redpen-conf-ja.xml ./lib/redpen-cli-1.0/sample-doc/ja/sampledoc-ja.md Checking....FAILED! This is not a valid document. Checking by RedPen CLI v1.0.1 sampledoc-ja.md:2: ValidationError[SentenceLength], æé·ãæå¤§å¤ "107" ãè¶ ãã¦ãã¾ã at line: # åæ£å¦çæè¿å©ç¨ããã¦ããã½ããã¦ã§ã¢ã®ä¸ã«ã¯è¤æ°ã®è¨ç®æ©ä¸ã§åä½ï¼åæ£ï¼ãããã®ãå¤ãåå¨ãããã®ãããªåæ£ã½ããã¦ã§ã¢ã¯è¤æ°ã®è¨ç®æ©ã§åä½ãããã¨ã§å¤§éã®ãã¼ã¿ãæ±ããã ãé«è² è·ãªç¶æ³ã«å¯¾å¦ã§ããããã¾ãã sampledoc-ja.md:2: ValidationError[InvalidSymbol], ä¸æ£ãªã·ã³ãã« "#" ãã¿ã¤ããã¾ãã at line: # åæ£å¦çæè¿å©ç¨ããã¦ããã½ããã¦ã§ã¢ã®ä¸ã«ã¯è¤æ°ã®è¨ç®æ©ä¸ã§åä½ï¼åæ£ï¼ãããã®ãå¤ãåå¨ãããã®ãããªåæ£ã½ããã¦ã§ã¢ã¯è¤æ°ã®è¨ç®æ©ã§åä½ãããã¨ã§å¤§éã®ãã¼ã¿ãæ±ããããé«è² è·ãªç¶æ³ã«å¯¾å¦ã§ããããã¾ãã sampledoc-ja.md:3: ValidationError[InvalidSymbol], ä¸æ£ãªã·ã³ãã« "," ãã¿ã¤ããã¾ãã at line: æ¬ç¨¿ã§ã¯,è¤æ°ã®è¨ç®æ©ï¼ã¯ã©ã¹ã¿ï¼ã§ã§åä½ããåãµã¼ãã¼ã**ã¤ã³ã¹ã¿ã³ã¹**ã¨å¼ã³ã¾ã¾ãã sampledoc-ja.md:3: ValidationError[KatakanaEndHyphen], ã«ã¿ã«ãåèª "ãµã¼ãã¼" ã«ä¸æ£ãªãã¤ãã³ãè¦ã¤ããã¾ãã at line: æ¬ç¨¿ã§ã¯,è¤æ°ã®è¨ç®æ©ï¼ã¯ã©ã¹ã¿ï¼ã§ã§åä½ããåãµã¼ãã¼ã**ã¤ã³ã¹ã¿ã³ã¹**ã¨å¼ã³ã¾ã¾ãã sampledoc-ja.md:2: ValidationError[DoubledWord], ä¸æã«äºå以ä¸å©ç¨ããã¦ããåèª "åæ£" ãã¿ã¤ããã¾ãã at line: # åæ£å¦çæè¿å©ç¨ããã¦ããã½ããã¦ã§ã¢ã®ä¸ã«ã¯è¤æ°ã®è¨ç®æ©ä¸ã§åä½ï¼åæ£ï¼ãããã®ãå¤ãåå¨ãããã®ãããªåæ£ã½ããã¦ã§ã¢ã¯è¤æ°ã®è¨ç®æ©ã§åä½ãããã¨ã§å¤§ éã®ãã¼ã¿ãæ±ããããé«è² è·ãªç¶æ³ã«å¯¾å¦ã§ããããã¾ãã sampledoc-ja.md:2: ValidationError[DoubledWord], ä¸æã«äºå以ä¸å©ç¨ããã¦ããåèª "åæ£" ãã¿ã¤ããã¾ãã at line: # åæ£å¦çæè¿å©ç¨ããã¦ããã½ããã¦ã§ã¢ã®ä¸ã«ã¯è¤æ°ã®è¨ç®æ©ä¸ã§åä½ï¼åæ£ï¼ãããã®ãå¤ãåå¨ãããã®ãããªåæ£ã½ããã¦ã§ã¢ã¯è¤æ°ã®è¨ç®æ©ã§åä½ãããã¨ã§å¤§ éã®ãã¼ã¿ãæ±ããããé«è² è·ãªç¶æ³ã«å¯¾å¦ã§ããããã¾ãã sampledoc-ja.md:2: ValidationError[DoubledWord], ä¸æã«äºå以ä¸å©ç¨ããã¦ããåèª "ã½ããã¦ã§ã¢" ãã¿ã¤ããã¾ãã at line: # åæ£å¦çæè¿å©ç¨ããã¦ããã½ããã¦ã§ã¢ã®ä¸ã«ã¯è¤æ°ã®è¨ç®æ©ä¸ã§åä½ï¼åæ£ï¼ãããã®ãå¤ãåå¨ãããã®ãããªåæ£ã½ããã¦ã§ã¢ã¯è¤æ°ã®è¨ç®æ©ã§åä½ãã ãã¨ã§å¤§éã®ãã¼ã¿ãæ±ããããé«è² è·ãªç¶æ³ã«å¯¾å¦ã§ããããã¾ãã sampledoc-ja.md:2: ValidationError[DoubledWord], ä¸æã«äºå以ä¸å©ç¨ããã¦ããåèª "è¤æ°" ãã¿ã¤ããã¾ãã at line: # åæ£å¦çæè¿å©ç¨ããã¦ããã½ããã¦ã§ã¢ã®ä¸ã«ã¯è¤æ°ã®è¨ç®æ©ä¸ã§åä½ï¼åæ£ï¼ãããã®ãå¤ãåå¨ãããã®ãããªåæ£ã½ããã¦ã§ã¢ã¯è¤æ°ã®è¨ç®æ©ã§åä½ãããã¨ã§å¤§ éã®ãã¼ã¿ãæ±ããããé«è² è·ãªç¶æ³ã«å¯¾å¦ã§ããããã¾ãã sampledoc-ja.md:2: ValidationError[DoubledWord], ä¸æã«äºå以ä¸å©ç¨ããã¦ããåèª "è¨ç®" ãã¿ã¤ããã¾ãã at line: # åæ£å¦çæè¿å©ç¨ããã¦ããã½ããã¦ã§ã¢ã®ä¸ã«ã¯è¤æ°ã®è¨ç®æ©ä¸ã§åä½ï¼åæ£ï¼ãããã®ãå¤ãåå¨ãããã®ãããªåæ£ã½ããã¦ã§ã¢ã¯è¤æ°ã®è¨ç®æ©ã§åä½ãããã¨ã§å¤§ éã®ãã¼ã¿ãæ±ããããé«è² è·ãªç¶æ³ã«å¯¾å¦ã§ããããã¾ãã sampledoc-ja.md:2: ValidationError[DoubledWord], ä¸æã«äºå以ä¸å©ç¨ããã¦ããåèª "åä½" ãã¿ã¤ããã¾ãã at line: # åæ£å¦çæè¿å©ç¨ããã¦ããã½ããã¦ã§ã¢ã®ä¸ã«ã¯è¤æ°ã®è¨ç®æ©ä¸ã§åä½ï¼åæ£ï¼ãããã®ãå¤ãåå¨ãããã®ãããªåæ£ã½ããã¦ã§ã¢ã¯è¤æ°ã®è¨ç®æ©ã§åä½ãããã¨ã§å¤§ éã®ãã¼ã¿ãæ±ããããé«è² è·ãªç¶æ³ã«å¯¾å¦ã§ããããã¾ãã sampledoc-ja.md:2: ValidationError[DoubledWord], ä¸æã«äºå以ä¸å©ç¨ããã¦ããåèª "ãã" ãã¿ã¤ããã¾ãã at line: # åæ£å¦çæè¿å©ç¨ããã¦ããã½ããã¦ã§ã¢ã®ä¸ã«ã¯è¤æ°ã®è¨ç®æ©ä¸ã§åä½ï¼åæ£ï¼ãããã®ãå¤ãåå¨ãããã®ãããªåæ£ã½ããã¦ã§ã¢ã¯è¤æ°ã®è¨ç®æ©ã§åä½ãããã¨ã§å¤§ éã®ãã¼ã¿ãæ±ããããé«è² è·ãªç¶æ³ã«å¯¾å¦ã§ããããã¾ãã sampledoc-ja.md:5: ValidationError[SpaceBetweenAlphabeticalWord], ã¢ã«ãã¡ãããåèªã®åã«ã¹ãã¼ã¹ãåå¨ãã¾ãã at line: ãã®ãããªå ´åãåã¤ã³ãã¯ã¹ã®çµæããã¼ã¸ãã¦clientããã°ã©ã ã«æ¸¡ãæ©æ§ãå¿ è¦ã¨ãªãã¾ãã sampledoc-ja.md:5: ValidationError[SpaceBetweenAlphabeticalWord], ã¢ã«ãã¡ãããåèªã®å¾ã«ã¹ãã¼ã¹ãåå¨ãã¾ãã at line: ãã®ãããªå ´åãåã¤ã³ãã¯ã¹ã®çµæããã¼ã¸ãã¦clientããã°ã©ã ã«æ¸¡ãæ©æ§ãå¿ è¦ã¨ãªãã¾ãã sampledoc-ja.md:3: ValidationError[SuccessiveWord], åèª "ã§" ã¯é£ç¶ãã¦ä½¿ç¨ããã¦ãã¾ã at line: æ¬ç¨¿ã§ã¯,è¤æ°ã®è¨ç®æ©ï¼ã¯ã©ã¹ã¿ï¼ã§ã§åä½ããåãµã¼ãã¼ã**ã¤ã³ã¹ã¿ã³ã¹**ã¨å¼ã³ã¾ã¾ãã
ãã®åºåçµæã¯ãredpen_rubyã®ããã¸ã§ã¯ãã«ã¼ãã§å®è¡ããå ´åã§ããbundle install
ããå ´åã¯ãbundle exec
ãä»ãã¾ãããã
redpen-cli-1.0ãå梱ãã¦ãããããRedPenæ¬ä½ãã¤ã³ã¹ãã¼ã«ããå¿
è¦ã¯ããã¾ããããç°å¢å¤æ°JAVA_HOMEã¯ãã¶ãè¨å®ããå¿
è¦ãããã¾ããç§ã¯.zshenv
ã«æ¬¡ã®è¨å®ãæ¸ãã¦ãã¾ãã
export JAVA_HOME=`/usr/libexec/java_home
ã¡ãªã¿ã«ãã³ãã³ãã©ã¤ã³ããã®å®è¡ã¯ãé常ã®redpen-cliã¨ã»ã¨ãã©å¤ãã¾ããã®ã§ããã¾ãå¬ããããã¾ãããéãã¨ãã¦ã¯ããããã°ã¡ãã»ã¼ã¸ãæ¶ãã¦ãããããã§ãã
Rubyã³ã¼ãå ããã®ä½¿ãæ¹
redpen_rubyã®å©ç¹ã¯ãRubyã³ã¼ãå ã§å©ç¨ã§ããã¨ããã§ãã
require 'redpen_ruby' config_file = './lib/redpen-cli-1.0/conf/redpen-conf-en.xml' target_file = './lib/redpen-cli-1.0/sample-doc/en/sampledoc-en.md' redpen = RedpenRuby.check(config_file, target_file) if redpen.valid? puts 'Ok, Valid!' else puts redpen.messages end
epub_validatorã¨åæ§ã«ãä¸è¨ã®ãããªã³ã¼ããæ¸ããã¨ã§ãRubyã³ã¼ãã§RedPenã使ããã¨ãã§ãã¾ãã
ããã§ãRakeã使ã£ã¦æãéãã«å®è¡ã§ãããã§ãã
åãã¦ã®RubyGemãæ¸ãã¦ã¿ãææ³
ã²ã¨ãã¨ã§è¨ãã¨ãã¨ã¦ãç°¡åã§ããã
ã¾ããbundle gem redpen_ruby -t -b
ãå®è¡ããã ãã§ãå¿
è¦ãªãã¡ã¤ã«ç¾¤ãèªåçæãã¦ããããããæ
£ãã¦ããªãç§ã§ããæ¬ä½ã³ã¼ããæ¸ããã¨ã ãã«éä¸ãããã¨ãã§ãã¾ããã
ã¾ããã³ã¼ããæ¸ããå¾ã¯rake spec
ã§ãã¹ããã¤ã¤ãrake install
ã§å®éã«ã¤ã³ã¹ãã¼ã«ãã¦æçµã®åä½ç¢ºèªããã¦ãç¡äºã«å©ç¨ã§ãããrake release
ãå®è¡ããã ãã§å
¬éã¾ã§è¡ãªãã¾ããã
CIã«ã¤ãã¦ããbundle gemã§çæããã.travis.yml
ããã®ã¾ã¾GitHubã«pushããã ãã§ãTravis CIãå©ç¨ã§ãã¦ãè³ããå°½ãããã§ããã
ã¡ãªã¿ã«ãæåã¯æ®æ®µä½¿ã£ã¦ããCircleCIã«æããããã¨æã£ãã®ã§ãããbundle installã§ãã«ãã¨ã©ã¼ã«ãªã£ã¦ãã¾ã£ãã®ã§ãgemã®å ´åã¯Travis CIã®æ¹ããæ軽ã§ããã
æ°ã«ãªããã¨
ãããã£ãå½¢ã§ãå¤é¨ãã¼ã«ãå«ãããã°ã©ã ãä½ã£ã¦å ¬éããã®ã¯åãã¦ã§ãããããã©ã¤ã»ã³ã¹ä¸åé¡ããªããæ°ã«ãªã£ã¦ãã¾ãã
RedPenã¯Apache License, Version 2.0ã§ãããããã©ã¤ã»ã³ã¹ãæ示ãã¦ããã°åé¡ãªãã¨æãã¾ããã®ã§ãredpen_rubyã®ã©ã¤ã»ã³ã¹ã«RedPenã®LICENSE-HEADER.txtãè²¼ãä»ãã¦ããã®ä¸ã§ãredpen_ruby/lib/redpen-cli-1.0ã®ä¸ã«ããLICENSE.txtãæ¾ãè¾¼ãã§ããã¾ããã
ãªããredpen-cli-1.0ã¯RedPenã®ã½ã¼ã¹ã³ã¼ããæå ã§ãã«ããããã®ãå©ç¨ãã¦ãã¾ãã
ã¨ããããã§ããããã®è¨äºãè¦ãRedPené¢ä¿è ã®æ¹ããããã¾ããããåé¡ããªããæãã¦ããã ããã¨å¬ããã§ãã
追è¨
Twitterã§ã³ããã¿ã®ä¼è¤ããããåé¡ãªãã¨ã®ãè¿äºãé ãã¾ããï¼
@akinomurasame åé¡ãä½ãããããã¨ããããã¾ãï¼
— Takahiko Ito (@takahi_i) 2014, 12æ 29
ã¾ã¨ã
ã¾ã æ¬æ ¼çã«RedPenã使ãå§ããããã§ã¯ãªãã®ã§ãããããã§å©ç¨ç°å¢ãæ´ã£ããã¨ããããå·çãä¸æ®µè½ããã¨ãã«ãRedPenãæ¬æ ¼å°å ¥ãã¦ã¿ããã¨æãã¾ãã
ã¾ãã調åã«ä¹ã£ã¦ãIssueãç«ã¦ã¦ã¿ãããã¦ã¿ãã®ã§ããã@takahi_i ããã«ããã対å¿é ãã¾ããããã®ç¯ã¯æ¬å½ã«ãããã¨ããããã¾ããã
ä»å¾ãããããã£ããã¼ã«ãæ´»ç¨ããå¹ççã«å·ççæ´»ãç¶ãã¦ãããã°ã¨æãã¾ãã®ã§ãã¿ãªãã¾ã©ããå®ãããé¡ããã¾ãã
追è¨
RedPenã®ããã¸ã§ã¯ããã¼ã¸ãããªã³ã¯ãã¦ãããã¾ããï¼