chess_engine 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (292) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +5 -0
  3. data/Gemfile.lock +21 -0
  4. data/README.md +26 -0
  5. data/chess_engine.gemspec +14 -0
  6. data/lib/chess_engine/board.rb +95 -0
  7. data/lib/chess_engine/cli.rb +105 -0
  8. data/lib/chess_engine/game.rb +148 -0
  9. data/lib/chess_engine/input.rb +19 -0
  10. data/lib/chess_engine/move.rb +35 -0
  11. data/lib/chess_engine/piece.rb +97 -0
  12. data/lib/chess_engine/validator.rb +87 -0
  13. data/lib/chess_engine.rb +1 -0
  14. data/spec/board_spec.rb +70 -0
  15. data/spec/game_helper.rb +5 -0
  16. data/spec/game_spec.rb +79 -0
  17. data/spec/spec_helper.rb +100 -0
  18. data/spec/validator_spec.rb +26 -0
  19. data/vendor/bundle/bin/coderay +27 -0
  20. data/vendor/bundle/bin/pry +27 -0
  21. data/vendor/bundle/cache/coderay-1.1.2.gem +0 -0
  22. data/vendor/bundle/cache/colorize-0.8.1.gem +0 -0
  23. data/vendor/bundle/cache/method_source-0.9.2.gem +0 -0
  24. data/vendor/bundle/cache/pry-0.12.2.gem +0 -0
  25. data/vendor/bundle/cache/rb-readline-0.5.5.gem +0 -0
  26. data/vendor/bundle/gems/coderay-1.1.2/MIT-LICENSE +22 -0
  27. data/vendor/bundle/gems/coderay-1.1.2/README_INDEX.rdoc +123 -0
  28. data/vendor/bundle/gems/coderay-1.1.2/bin/coderay +215 -0
  29. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/duo.rb +81 -0
  30. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/_map.rb +17 -0
  31. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/comment_filter.rb +25 -0
  32. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/count.rb +39 -0
  33. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/debug.rb +49 -0
  34. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/debug_lint.rb +63 -0
  35. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/div.rb +23 -0
  36. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/encoder.rb +190 -0
  37. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/filter.rb +58 -0
  38. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html/css.rb +65 -0
  39. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html/numbering.rb +108 -0
  40. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html/output.rb +166 -0
  41. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html.rb +333 -0
  42. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/json.rb +83 -0
  43. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/lines_of_code.rb +45 -0
  44. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/lint.rb +59 -0
  45. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/null.rb +18 -0
  46. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/page.rb +24 -0
  47. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/span.rb +23 -0
  48. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/statistic.rb +95 -0
  49. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/terminal.rb +195 -0
  50. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/text.rb +46 -0
  51. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/token_kind_filter.rb +111 -0
  52. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/xml.rb +72 -0
  53. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/yaml.rb +50 -0
  54. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders.rb +18 -0
  55. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/for_redcloth.rb +95 -0
  56. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/file_type.rb +151 -0
  57. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/plugin.rb +55 -0
  58. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/plugin_host.rb +221 -0
  59. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/word_list.rb +72 -0
  60. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/_map.rb +24 -0
  61. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/c.rb +189 -0
  62. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/clojure.rb +217 -0
  63. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/cpp.rb +217 -0
  64. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/css.rb +196 -0
  65. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/debug.rb +75 -0
  66. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/delphi.rb +144 -0
  67. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/diff.rb +221 -0
  68. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/erb.rb +81 -0
  69. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/go.rb +208 -0
  70. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/groovy.rb +268 -0
  71. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/haml.rb +168 -0
  72. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/html.rb +275 -0
  73. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/java/builtin_types.rb +421 -0
  74. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/java.rb +174 -0
  75. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/java_script.rb +237 -0
  76. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/json.rb +98 -0
  77. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/lua.rb +280 -0
  78. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/php.rb +527 -0
  79. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/python.rb +287 -0
  80. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/raydebug.rb +75 -0
  81. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/ruby/patterns.rb +178 -0
  82. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/ruby/string_state.rb +79 -0
  83. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/ruby.rb +477 -0
  84. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/sass.rb +232 -0
  85. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/scanner.rb +337 -0
  86. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/sql.rb +169 -0
  87. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/taskpaper.rb +36 -0
  88. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/text.rb +26 -0
  89. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/xml.rb +17 -0
  90. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/yaml.rb +140 -0
  91. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners.rb +27 -0
  92. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles/_map.rb +7 -0
  93. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles/alpha.rb +153 -0
  94. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles/style.rb +18 -0
  95. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles.rb +15 -0
  96. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/token_kinds.rb +85 -0
  97. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/tokens.rb +161 -0
  98. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/tokens_proxy.rb +55 -0
  99. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/version.rb +3 -0
  100. data/vendor/bundle/gems/coderay-1.1.2/lib/coderay.rb +284 -0
  101. data/vendor/bundle/gems/colorize-0.8.1/CHANGELOG +65 -0
  102. data/vendor/bundle/gems/colorize-0.8.1/LICENSE +339 -0
  103. data/vendor/bundle/gems/colorize-0.8.1/README.md +105 -0
  104. data/vendor/bundle/gems/colorize-0.8.1/Rakefile +13 -0
  105. data/vendor/bundle/gems/colorize-0.8.1/colorize.gemspec +36 -0
  106. data/vendor/bundle/gems/colorize-0.8.1/lib/colorize/class_methods.rb +120 -0
  107. data/vendor/bundle/gems/colorize-0.8.1/lib/colorize/instance_methods.rb +132 -0
  108. data/vendor/bundle/gems/colorize-0.8.1/lib/colorize.rb +12 -0
  109. data/vendor/bundle/gems/colorize-0.8.1/lib/colorized_string.rb +19 -0
  110. data/vendor/bundle/gems/colorize-0.8.1/test/test_colorize.rb +164 -0
  111. data/vendor/bundle/gems/method_source-0.9.2/Gemfile +2 -0
  112. data/vendor/bundle/gems/method_source-0.9.2/LICENSE +25 -0
  113. data/vendor/bundle/gems/method_source-0.9.2/README.markdown +91 -0
  114. data/vendor/bundle/gems/method_source-0.9.2/Rakefile +81 -0
  115. data/vendor/bundle/gems/method_source-0.9.2/lib/method_source/code_helpers.rb +154 -0
  116. data/vendor/bundle/gems/method_source-0.9.2/lib/method_source/source_location.rb +138 -0
  117. data/vendor/bundle/gems/method_source-0.9.2/lib/method_source/version.rb +3 -0
  118. data/vendor/bundle/gems/method_source-0.9.2/lib/method_source.rb +141 -0
  119. data/vendor/bundle/gems/method_source-0.9.2/method_source.gemspec +35 -0
  120. data/vendor/bundle/gems/method_source-0.9.2/spec/method_source/code_helpers_spec.rb +43 -0
  121. data/vendor/bundle/gems/method_source-0.9.2/spec/method_source_spec.rb +143 -0
  122. data/vendor/bundle/gems/method_source-0.9.2/spec/spec_helper.rb +101 -0
  123. data/vendor/bundle/gems/pry-0.12.2/CHANGELOG.md +953 -0
  124. data/vendor/bundle/gems/pry-0.12.2/LICENSE +25 -0
  125. data/vendor/bundle/gems/pry-0.12.2/README.md +390 -0
  126. data/vendor/bundle/gems/pry-0.12.2/bin/pry +8 -0
  127. data/vendor/bundle/gems/pry-0.12.2/lib/pry/basic_object.rb +6 -0
  128. data/vendor/bundle/gems/pry-0.12.2/lib/pry/cli.rb +218 -0
  129. data/vendor/bundle/gems/pry-0.12.2/lib/pry/code/code_file.rb +110 -0
  130. data/vendor/bundle/gems/pry-0.12.2/lib/pry/code/code_range.rb +71 -0
  131. data/vendor/bundle/gems/pry-0.12.2/lib/pry/code/loc.rb +98 -0
  132. data/vendor/bundle/gems/pry-0.12.2/lib/pry/code.rb +353 -0
  133. data/vendor/bundle/gems/pry-0.12.2/lib/pry/code_object.rb +195 -0
  134. data/vendor/bundle/gems/pry-0.12.2/lib/pry/color_printer.rb +65 -0
  135. data/vendor/bundle/gems/pry-0.12.2/lib/pry/command.rb +723 -0
  136. data/vendor/bundle/gems/pry-0.12.2/lib/pry/command_set.rb +415 -0
  137. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/amend_line.rb +98 -0
  138. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/bang.rb +20 -0
  139. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/bang_pry.rb +17 -0
  140. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/abstract_formatter.rb +27 -0
  141. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/exception_formatter.rb +79 -0
  142. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/file_formatter.rb +71 -0
  143. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
  144. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat.rb +63 -0
  145. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cd.rb +41 -0
  146. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/change_inspector.rb +27 -0
  147. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/change_prompt.rb +46 -0
  148. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/clear_screen.rb +14 -0
  149. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/code_collector.rb +167 -0
  150. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/disable_pry.rb +27 -0
  151. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/disabled_commands.rb +2 -0
  152. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/easter_eggs.rb +112 -0
  153. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/edit/exception_patcher.rb +25 -0
  154. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/edit/file_and_line_locator.rb +36 -0
  155. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/edit.rb +200 -0
  156. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/exit.rb +43 -0
  157. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/exit_all.rb +29 -0
  158. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/exit_program.rb +23 -0
  159. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/find_method.rb +191 -0
  160. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/fix_indent.rb +19 -0
  161. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_cd.rb +26 -0
  162. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_install.rb +32 -0
  163. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_list.rb +33 -0
  164. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_open.rb +29 -0
  165. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_readme.rb +25 -0
  166. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_search.rb +40 -0
  167. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_stats.rb +83 -0
  168. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gist.rb +102 -0
  169. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/help.rb +164 -0
  170. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/hist.rb +181 -0
  171. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/import_set.rb +23 -0
  172. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/install_command.rb +54 -0
  173. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/jump_to.rb +29 -0
  174. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/list_inspectors.rb +35 -0
  175. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/constants.rb +58 -0
  176. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/formatter.rb +51 -0
  177. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/globals.rb +46 -0
  178. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/grep.rb +19 -0
  179. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/instance_vars.rb +38 -0
  180. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/interrogatable.rb +18 -0
  181. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/jruby_hacks.rb +49 -0
  182. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/local_names.rb +33 -0
  183. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/local_vars.rb +37 -0
  184. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/ls_entity.rb +69 -0
  185. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/methods.rb +54 -0
  186. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/methods_helper.rb +46 -0
  187. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/self_methods.rb +33 -0
  188. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls.rb +113 -0
  189. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/nesting.rb +25 -0
  190. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/play.rb +102 -0
  191. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/pry_backtrace.rb +25 -0
  192. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/pry_version.rb +17 -0
  193. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/raise_up.rb +33 -0
  194. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/reload_code.rb +62 -0
  195. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/reset.rb +18 -0
  196. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ri.rb +65 -0
  197. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/save_file.rb +61 -0
  198. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/shell_command.rb +75 -0
  199. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/shell_mode.rb +25 -0
  200. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_doc.rb +81 -0
  201. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_info.rb +216 -0
  202. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_input.rb +17 -0
  203. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_source.rb +53 -0
  204. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/stat.rb +40 -0
  205. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/switch_to.rb +23 -0
  206. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/toggle_color.rb +24 -0
  207. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/watch_expression/expression.rb +38 -0
  208. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/watch_expression.rb +107 -0
  209. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/whereami.rb +197 -0
  210. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/wtf.rb +70 -0
  211. data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands.rb +6 -0
  212. data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/behavior.rb +255 -0
  213. data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/convenience.rb +28 -0
  214. data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/default.rb +159 -0
  215. data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/memoization.rb +48 -0
  216. data/vendor/bundle/gems/pry-0.12.2/lib/pry/config.rb +35 -0
  217. data/vendor/bundle/gems/pry-0.12.2/lib/pry/core_extensions.rb +142 -0
  218. data/vendor/bundle/gems/pry-0.12.2/lib/pry/editor.rb +128 -0
  219. data/vendor/bundle/gems/pry-0.12.2/lib/pry/exceptions.rb +76 -0
  220. data/vendor/bundle/gems/pry-0.12.2/lib/pry/forwardable.rb +23 -0
  221. data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/base_helpers.rb +200 -0
  222. data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/command_helpers.rb +157 -0
  223. data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/documentation_helpers.rb +76 -0
  224. data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/options_helpers.rb +27 -0
  225. data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/platform.rb +58 -0
  226. data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/table.rb +114 -0
  227. data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/text.rb +115 -0
  228. data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers.rb +6 -0
  229. data/vendor/bundle/gems/pry-0.12.2/lib/pry/history.rb +161 -0
  230. data/vendor/bundle/gems/pry-0.12.2/lib/pry/hooks.rb +171 -0
  231. data/vendor/bundle/gems/pry-0.12.2/lib/pry/indent.rb +408 -0
  232. data/vendor/bundle/gems/pry-0.12.2/lib/pry/input_completer.rb +265 -0
  233. data/vendor/bundle/gems/pry-0.12.2/lib/pry/input_lock.rb +130 -0
  234. data/vendor/bundle/gems/pry-0.12.2/lib/pry/inspector.rb +27 -0
  235. data/vendor/bundle/gems/pry-0.12.2/lib/pry/last_exception.rb +61 -0
  236. data/vendor/bundle/gems/pry-0.12.2/lib/pry/method/disowned.rb +55 -0
  237. data/vendor/bundle/gems/pry-0.12.2/lib/pry/method/patcher.rb +122 -0
  238. data/vendor/bundle/gems/pry-0.12.2/lib/pry/method/weird_method_locator.rb +198 -0
  239. data/vendor/bundle/gems/pry-0.12.2/lib/pry/method.rb +552 -0
  240. data/vendor/bundle/gems/pry-0.12.2/lib/pry/object_path.rb +83 -0
  241. data/vendor/bundle/gems/pry-0.12.2/lib/pry/output.rb +50 -0
  242. data/vendor/bundle/gems/pry-0.12.2/lib/pry/pager.rb +250 -0
  243. data/vendor/bundle/gems/pry-0.12.2/lib/pry/platform.rb +91 -0
  244. data/vendor/bundle/gems/pry-0.12.2/lib/pry/plugins.rb +122 -0
  245. data/vendor/bundle/gems/pry-0.12.2/lib/pry/prompt.rb +145 -0
  246. data/vendor/bundle/gems/pry-0.12.2/lib/pry/pry_class.rb +425 -0
  247. data/vendor/bundle/gems/pry-0.12.2/lib/pry/pry_instance.rb +699 -0
  248. data/vendor/bundle/gems/pry-0.12.2/lib/pry/repl.rb +261 -0
  249. data/vendor/bundle/gems/pry-0.12.2/lib/pry/repl_file_loader.rb +73 -0
  250. data/vendor/bundle/gems/pry-0.12.2/lib/pry/ring.rb +84 -0
  251. data/vendor/bundle/gems/pry-0.12.2/lib/pry/rubygem.rb +84 -0
  252. data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop/LICENSE +20 -0
  253. data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop/commands.rb +195 -0
  254. data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop/option.rb +206 -0
  255. data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop.rb +661 -0
  256. data/vendor/bundle/gems/pry-0.12.2/lib/pry/terminal.rb +91 -0
  257. data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/evalable.rb +15 -0
  258. data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/mockable.rb +14 -0
  259. data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/pry_tester.rb +73 -0
  260. data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/utility.rb +26 -0
  261. data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/variables.rb +46 -0
  262. data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable.rb +70 -0
  263. data/vendor/bundle/gems/pry-0.12.2/lib/pry/version.rb +3 -0
  264. data/vendor/bundle/gems/pry-0.12.2/lib/pry/wrapped_module/candidate.rb +131 -0
  265. data/vendor/bundle/gems/pry-0.12.2/lib/pry/wrapped_module.rb +378 -0
  266. data/vendor/bundle/gems/pry-0.12.2/lib/pry.rb +132 -0
  267. data/vendor/bundle/gems/rb-readline-0.5.5/CHANGES +94 -0
  268. data/vendor/bundle/gems/rb-readline-0.5.5/LICENSE +25 -0
  269. data/vendor/bundle/gems/rb-readline-0.5.5/README.md +81 -0
  270. data/vendor/bundle/gems/rb-readline-0.5.5/Rakefile +25 -0
  271. data/vendor/bundle/gems/rb-readline-0.5.5/bench/_rl_adjust_point.rb +26 -0
  272. data/vendor/bundle/gems/rb-readline-0.5.5/examples/example_readline.rb +8 -0
  273. data/vendor/bundle/gems/rb-readline-0.5.5/examples/example_readline_with_completion.rb +18 -0
  274. data/vendor/bundle/gems/rb-readline-0.5.5/examples/tinyirb.rb +11 -0
  275. data/vendor/bundle/gems/rb-readline-0.5.5/lib/rb-readline.rb +18 -0
  276. data/vendor/bundle/gems/rb-readline-0.5.5/lib/rbreadline/version.rb +3 -0
  277. data/vendor/bundle/gems/rb-readline-0.5.5/lib/rbreadline.rb +8920 -0
  278. data/vendor/bundle/gems/rb-readline-0.5.5/lib/readline.rb +539 -0
  279. data/vendor/bundle/gems/rb-readline-0.5.5/rb-readline.gemspec +51 -0
  280. data/vendor/bundle/gems/rb-readline-0.5.5/setup.rb +1585 -0
  281. data/vendor/bundle/gems/rb-readline-0.5.5/test/support/filesystem_completion_helper.rb +53 -0
  282. data/vendor/bundle/gems/rb-readline-0.5.5/test/test_completion.rb +100 -0
  283. data/vendor/bundle/gems/rb-readline-0.5.5/test/test_filename_completion_proc.rb +88 -0
  284. data/vendor/bundle/gems/rb-readline-0.5.5/test/test_history.rb +29 -0
  285. data/vendor/bundle/gems/rb-readline-0.5.5/test/test_rbreadline.rb +23 -0
  286. data/vendor/bundle/gems/rb-readline-0.5.5/test/test_readline.rb +221 -0
  287. data/vendor/bundle/specifications/coderay-1.1.2.gemspec +26 -0
  288. data/vendor/bundle/specifications/colorize-0.8.1.gemspec +38 -0
  289. data/vendor/bundle/specifications/method_source-0.9.2.gemspec +35 -0
  290. data/vendor/bundle/specifications/pry-0.12.2.gemspec +38 -0
  291. data/vendor/bundle/specifications/rb-readline-0.5.5.gemspec +39 -0
  292. metadata +363 -0
@@ -0,0 +1,18 @@
1
+ module CodeRay
2
+
3
+ module Styles
4
+
5
+ # Base class for styles.
6
+ #
7
+ # Styles are used by Encoders::HTML to colorize tokens.
8
+ class Style
9
+ extend Plugin
10
+ plugin_host Styles
11
+
12
+ DEFAULT_OPTIONS = { } # :nodoc:
13
+
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,15 @@
1
+ module CodeRay
2
+
3
+ # This module holds the Style class and its subclasses.
4
+ #
5
+ # See Plugin.
6
+ module Styles
7
+
8
+ extend PluginHost
9
+ plugin_path File.dirname(__FILE__), 'styles'
10
+
11
+ autoload :Style, CodeRay.coderay_path('styles', 'style')
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,85 @@
1
+ module CodeRay
2
+
3
+ # A Hash of all known token kinds and their associated CSS classes.
4
+ TokenKinds = Hash.new(false)
5
+
6
+ # speedup
7
+ TokenKinds.compare_by_identity if TokenKinds.respond_to? :compare_by_identity
8
+
9
+ TokenKinds.update( # :nodoc:
10
+ :debug => 'debug', # highlight for debugging (white on blue background)
11
+
12
+ :annotation => 'annotation', # Groovy, Java
13
+ :attribute_name => 'attribute-name', # HTML, CSS
14
+ :attribute_value => 'attribute-value', # HTML
15
+ :binary => 'binary', # Python, Ruby
16
+ :char => 'char', # most scanners, also inside of strings
17
+ :class => 'class', # lots of scanners, for different purposes also in CSS
18
+ :class_variable => 'class-variable', # Ruby, YAML
19
+ :color => 'color', # CSS
20
+ :comment => 'comment', # most scanners
21
+ :constant => 'constant', # PHP, Ruby
22
+ :content => 'content', # inside of strings, most scanners
23
+ :decorator => 'decorator', # Python
24
+ :definition => 'definition', # CSS
25
+ :delimiter => 'delimiter', # inside strings, comments and other types
26
+ :directive => 'directive', # lots of scanners
27
+ :doctype => 'doctype', # Goorvy, HTML, Ruby, YAML
28
+ :docstring => 'docstring', # Python
29
+ :done => 'done', # Taskpaper
30
+ :entity => 'entity', # HTML
31
+ :error => 'error', # invalid token, most scanners
32
+ :escape => 'escape', # Ruby (string inline variables like #$foo, #@bar)
33
+ :exception => 'exception', # Java, PHP, Python
34
+ :filename => 'filename', # Diff
35
+ :float => 'float', # most scanners
36
+ :function => 'function', # CSS, JavaScript, PHP
37
+ :global_variable => 'global-variable', # Ruby, YAML
38
+ :hex => 'hex', # hexadecimal number; lots of scanners
39
+ :id => 'id', # CSS
40
+ :imaginary => 'imaginary', # Python
41
+ :important => 'important', # CSS, Taskpaper
42
+ :include => 'include', # C, Groovy, Java, Python, Sass
43
+ :inline => 'inline', # nested code, eg. inline string evaluation; lots of scanners
44
+ :inline_delimiter => 'inline-delimiter', # used instead of :inline > :delimiter FIXME: Why use inline_delimiter?
45
+ :instance_variable => 'instance-variable', # Ruby
46
+ :integer => 'integer', # most scanners
47
+ :key => 'key', # lots of scanners, used together with :value
48
+ :keyword => 'keyword', # reserved word that's actually implemented; most scanners
49
+ :label => 'label', # C, PHP
50
+ :local_variable => 'local-variable', # local and magic variables; some scanners
51
+ :map => 'map', # Lua tables
52
+ :modifier => 'modifier', # used inside on strings; lots of scanners
53
+ :namespace => 'namespace', # Clojure, Java, Taskpaper
54
+ :octal => 'octal', # lots of scanners
55
+ :predefined => 'predefined', # predefined function: lots of scanners
56
+ :predefined_constant => 'predefined-constant',# lots of scanners
57
+ :predefined_type => 'predefined-type', # C, Java, PHP
58
+ :preprocessor => 'preprocessor', # C, Delphi, HTML
59
+ :pseudo_class => 'pseudo-class', # CSS
60
+ :regexp => 'regexp', # Groovy, JavaScript, Ruby
61
+ :reserved => 'reserved', # most scanners
62
+ :shell => 'shell', # Ruby
63
+ :string => 'string', # most scanners
64
+ :symbol => 'symbol', # Clojure, Ruby, YAML
65
+ :tag => 'tag', # CSS, HTML
66
+ :type => 'type', # CSS, Java, SQL, YAML
67
+ :value => 'value', # used together with :key; CSS, JSON, YAML
68
+ :variable => 'variable', # Sass, SQL, YAML
69
+
70
+ :change => 'change', # Diff
71
+ :delete => 'delete', # Diff
72
+ :head => 'head', # Diff, YAML
73
+ :insert => 'insert', # Diff
74
+ :eyecatcher => 'eyecatcher', # Diff
75
+
76
+ :ident => false, # almost all scanners
77
+ :operator => false, # almost all scanners
78
+
79
+ :space => false, # almost all scanners
80
+ :plain => false # almost all scanners
81
+ )
82
+
83
+ TokenKinds[:method] = TokenKinds[:function]
84
+ TokenKinds[:unknown] = TokenKinds[:plain]
85
+ end
@@ -0,0 +1,161 @@
1
+ module CodeRay
2
+
3
+ # The Tokens class represents a list of tokens returned from
4
+ # a Scanner. It's actually just an Array with a few helper methods.
5
+ #
6
+ # A token itself is not a special object, just two elements in an Array:
7
+ # * the _token_ _text_ (the original source of the token in a String) or
8
+ # a _token_ _action_ (begin_group, end_group, begin_line, end_line)
9
+ # * the _token_ _kind_ (a Symbol representing the type of the token)
10
+ #
11
+ # It looks like this:
12
+ #
13
+ # ..., '# It looks like this', :comment, ...
14
+ # ..., '3.1415926', :float, ...
15
+ # ..., '$^', :error, ...
16
+ #
17
+ # Some scanners also yield sub-tokens, represented by special
18
+ # token actions, for example :begin_group and :end_group.
19
+ #
20
+ # The Ruby scanner, for example, splits "a string" into:
21
+ #
22
+ # [
23
+ # :begin_group, :string,
24
+ # '"', :delimiter,
25
+ # 'a string', :content,
26
+ # '"', :delimiter,
27
+ # :end_group, :string
28
+ # ]
29
+ #
30
+ # Tokens can be used to save the output of a Scanners in a simple
31
+ # Ruby object that can be send to an Encoder later:
32
+ #
33
+ # tokens = CodeRay.scan('price = 2.59', :ruby).tokens
34
+ # tokens.encode(:html)
35
+ # tokens.html
36
+ # CodeRay.encoder(:html).encode_tokens(tokens)
37
+ #
38
+ # Tokens gives you the power to handle pre-scanned code very easily:
39
+ # You can serialize it to a JSON string and store it in a database, pass it
40
+ # around to encode it more than once, send it to other algorithms...
41
+ class Tokens < Array
42
+
43
+ # The Scanner instance that created the tokens.
44
+ attr_accessor :scanner
45
+
46
+ # Encode the tokens using encoder.
47
+ #
48
+ # encoder can be
49
+ # * a plugin name like :html oder 'statistic'
50
+ # * an Encoder object
51
+ #
52
+ # options are passed to the encoder.
53
+ def encode encoder, options = {}
54
+ encoder = Encoders[encoder].new options if encoder.respond_to? :to_sym
55
+ encoder.encode_tokens self, options
56
+ end
57
+
58
+ # Turn tokens into a string by concatenating them.
59
+ def to_s
60
+ encode CodeRay::Encoders::Encoder.new
61
+ end
62
+
63
+ # Redirects unknown methods to encoder calls.
64
+ #
65
+ # For example, if you call +tokens.html+, the HTML encoder
66
+ # is used to highlight the tokens.
67
+ def method_missing meth, options = {}
68
+ encode meth, options
69
+ rescue PluginHost::PluginNotFound
70
+ super
71
+ end
72
+
73
+ # Split the tokens into parts of the given +sizes+.
74
+ #
75
+ # The result will be an Array of Tokens objects. The parts have
76
+ # the text size specified by the parameter. In addition, each
77
+ # part closes all opened tokens. This is useful to insert tokens
78
+ # betweem them.
79
+ #
80
+ # This method is used by @Scanner#tokenize@ when called with an Array
81
+ # of source strings. The Diff encoder uses it for inline highlighting.
82
+ def split_into_parts *sizes
83
+ return Array.new(sizes.size) { Tokens.new } if size == 2 && first == ''
84
+ parts = []
85
+ opened = []
86
+ content = nil
87
+ part = Tokens.new
88
+ part_size = 0
89
+ size = sizes.first
90
+ i = 0
91
+ for item in self
92
+ case content
93
+ when nil
94
+ content = item
95
+ when String
96
+ if size && part_size + content.size > size # token must be cut
97
+ if part_size < size # some part of the token goes into this part
98
+ content = content.dup # content may no be safe to change
99
+ part << content.slice!(0, size - part_size) << item
100
+ end
101
+ # close all open groups and lines...
102
+ closing = opened.reverse.flatten.map do |content_or_kind|
103
+ case content_or_kind
104
+ when :begin_group
105
+ :end_group
106
+ when :begin_line
107
+ :end_line
108
+ else
109
+ content_or_kind
110
+ end
111
+ end
112
+ part.concat closing
113
+ begin
114
+ parts << part
115
+ part = Tokens.new
116
+ size = sizes[i += 1]
117
+ end until size.nil? || size > 0
118
+ # ...and open them again.
119
+ part.concat opened.flatten
120
+ part_size = 0
121
+ redo unless content.empty?
122
+ else
123
+ part << content << item
124
+ part_size += content.size
125
+ end
126
+ content = nil
127
+ when Symbol
128
+ case content
129
+ when :begin_group, :begin_line
130
+ opened << [content, item]
131
+ when :end_group, :end_line
132
+ opened.pop
133
+ else
134
+ raise ArgumentError, 'Unknown token action: %p, kind = %p' % [content, item]
135
+ end
136
+ part << content << item
137
+ content = nil
138
+ else
139
+ raise ArgumentError, 'Token input junk: %p, kind = %p' % [content, item]
140
+ end
141
+ end
142
+ parts << part
143
+ parts << Tokens.new while parts.size < sizes.size
144
+ parts
145
+ end
146
+
147
+ # Return the actual number of tokens.
148
+ def count
149
+ size / 2
150
+ end
151
+
152
+ alias text_token push
153
+ def begin_group kind; push :begin_group, kind end
154
+ def end_group kind; push :end_group, kind end
155
+ def begin_line kind; push :begin_line, kind end
156
+ def end_line kind; push :end_line, kind end
157
+ alias tokens concat
158
+
159
+ end
160
+
161
+ end
@@ -0,0 +1,55 @@
1
+ module CodeRay
2
+
3
+ # The result of a scan operation is a TokensProxy, but should act like Tokens.
4
+ #
5
+ # This proxy makes it possible to use the classic CodeRay.scan.encode API
6
+ # while still providing the benefits of direct streaming.
7
+ class TokensProxy
8
+
9
+ attr_accessor :input, :lang, :options, :block
10
+
11
+ # Create a new TokensProxy with the arguments of CodeRay.scan.
12
+ def initialize input, lang, options = {}, block = nil
13
+ @input = input
14
+ @lang = lang
15
+ @options = options
16
+ @block = block
17
+ end
18
+
19
+ # Call CodeRay.encode if +encoder+ is a Symbol;
20
+ # otherwise, convert the receiver to tokens and call encoder.encode_tokens.
21
+ def encode encoder, options = {}
22
+ if encoder.respond_to? :to_sym
23
+ CodeRay.encode(input, lang, encoder, options)
24
+ else
25
+ encoder.encode_tokens tokens, options
26
+ end
27
+ end
28
+
29
+ # Tries to call encode;
30
+ # delegates to tokens otherwise.
31
+ def method_missing method, *args, &blk
32
+ encode method.to_sym, *args
33
+ rescue PluginHost::PluginNotFound
34
+ tokens.send(method, *args, &blk)
35
+ end
36
+
37
+ # The (cached) result of the tokenized input; a Tokens instance.
38
+ def tokens
39
+ @tokens ||= scanner.tokenize(input)
40
+ end
41
+
42
+ # A (cached) scanner instance to use for the scan task.
43
+ def scanner
44
+ @scanner ||= CodeRay.scanner(lang, options, &block)
45
+ end
46
+
47
+ # Overwrite Struct#each.
48
+ def each *args, &blk
49
+ tokens.each(*args, &blk)
50
+ self
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,3 @@
1
+ module CodeRay
2
+ VERSION = '1.1.2'
3
+ end
@@ -0,0 +1,284 @@
1
+ # encoding: utf-8
2
+ # Encoding.default_internal = 'UTF-8'
3
+
4
+ # = CodeRay Library
5
+ #
6
+ # CodeRay is a Ruby library for syntax highlighting.
7
+ #
8
+ # I try to make CodeRay easy to use and intuitive, but at the same time fully
9
+ # featured, complete, fast and efficient.
10
+ #
11
+ # See README.
12
+ #
13
+ # It consists mainly of
14
+ # * the main engine: CodeRay (Scanners::Scanner, Tokens, Encoders::Encoder)
15
+ # * the plugin system: PluginHost, Plugin
16
+ # * the scanners in CodeRay::Scanners
17
+ # * the encoders in CodeRay::Encoders
18
+ # * the styles in CodeRay::Styles
19
+ #
20
+ # Here's a fancy graphic to light up this gray docu:
21
+ #
22
+ # http://cycnus.de/raindark/coderay/scheme.png
23
+ #
24
+ # == Documentation
25
+ #
26
+ # See CodeRay, Encoders, Scanners, Tokens.
27
+ #
28
+ # == Usage
29
+ #
30
+ # Remember you need RubyGems to use CodeRay, unless you have it in your load
31
+ # path. Run Ruby with -rubygems option if required.
32
+ #
33
+ # === Highlight Ruby code in a string as html
34
+ #
35
+ # require 'coderay'
36
+ # print CodeRay.scan('puts "Hello, world!"', :ruby).html
37
+ #
38
+ # # prints something like this:
39
+ # puts <span class="s">&quot;Hello, world!&quot;</span>
40
+ #
41
+ #
42
+ # === Highlight C code from a file in a html div
43
+ #
44
+ # require 'coderay'
45
+ # print CodeRay.scan(File.read('ruby.h'), :c).div
46
+ # print CodeRay.scan_file('ruby.h').html.div
47
+ #
48
+ # You can include this div in your page. The used CSS styles can be printed with
49
+ #
50
+ # % coderay_stylesheet
51
+ #
52
+ # === Highlight without typing too much
53
+ #
54
+ # If you are one of the hasty (or lazy, or extremely curious) people, just run this file:
55
+ #
56
+ # % ruby -rubygems /path/to/coderay/coderay.rb > example.html
57
+ #
58
+ # and look at the file it created in your browser.
59
+ #
60
+ # = CodeRay Module
61
+ #
62
+ # The CodeRay module provides convenience methods for the engine.
63
+ #
64
+ # * The +lang+ and +format+ arguments select Scanner and Encoder to use. These are
65
+ # simply lower-case symbols, like <tt>:python</tt> or <tt>:html</tt>.
66
+ # * All methods take an optional hash as last parameter, +options+, that is send to
67
+ # the Encoder / Scanner.
68
+ # * Input and language are always sorted in this order: +code+, +lang+.
69
+ # (This is in alphabetical order, if you need a mnemonic ;)
70
+ #
71
+ # You should be able to highlight everything you want just using these methods;
72
+ # so there is no need to dive into CodeRay's deep class hierarchy.
73
+ #
74
+ # The examples in the demo directory demonstrate common cases using this interface.
75
+ #
76
+ # = Basic Access Ways
77
+ #
78
+ # Read this to get a general view what CodeRay provides.
79
+ #
80
+ # == Scanning
81
+ #
82
+ # Scanning means analysing an input string, splitting it up into Tokens.
83
+ # Each Token knows about what type it is: string, comment, class name, etc.
84
+ #
85
+ # Each +lang+ (language) has its own Scanner; for example, <tt>:ruby</tt> code is
86
+ # handled by CodeRay::Scanners::Ruby.
87
+ #
88
+ # CodeRay.scan:: Scan a string in a given language into Tokens.
89
+ # This is the most common method to use.
90
+ # CodeRay.scan_file:: Scan a file and guess the language using FileType.
91
+ #
92
+ # The Tokens object you get from these methods can encode itself; see Tokens.
93
+ #
94
+ # == Encoding
95
+ #
96
+ # Encoding means compiling Tokens into an output. This can be colored HTML or
97
+ # LaTeX, a textual statistic or just the number of non-whitespace tokens.
98
+ #
99
+ # Each Encoder provides output in a specific +format+, so you select Encoders via
100
+ # formats like <tt>:html</tt> or <tt>:statistic</tt>.
101
+ #
102
+ # CodeRay.encode:: Scan and encode a string in a given language.
103
+ # CodeRay.encode_tokens:: Encode the given tokens.
104
+ # CodeRay.encode_file:: Scan a file, guess the language using FileType and encode it.
105
+ #
106
+ # == All-in-One Encoding
107
+ #
108
+ # CodeRay.encode:: Highlight a string with a given input and output format.
109
+ #
110
+ # == Instanciating
111
+ #
112
+ # You can use an Encoder instance to highlight multiple inputs. This way, the setup
113
+ # for this Encoder must only be done once.
114
+ #
115
+ # CodeRay.encoder:: Create an Encoder instance with format and options.
116
+ # CodeRay.scanner:: Create an Scanner instance for lang, with '' as default code.
117
+ #
118
+ # To make use of CodeRay.scanner, use CodeRay::Scanner::code=.
119
+ #
120
+ # The scanning methods provide more flexibility; we recommend to use these.
121
+ #
122
+ # == Reusing Scanners and Encoders
123
+ #
124
+ # If you want to re-use scanners and encoders (because that is faster), see
125
+ # CodeRay::Duo for the most convenient (and recommended) interface.
126
+ module CodeRay
127
+
128
+ $CODERAY_DEBUG ||= false
129
+
130
+ CODERAY_PATH = File.expand_path('../coderay', __FILE__)
131
+
132
+ # Assuming the path is a subpath of lib/coderay/
133
+ def self.coderay_path *path
134
+ File.join CODERAY_PATH, *path
135
+ end
136
+
137
+ autoload :VERSION, 'coderay/version'
138
+
139
+ # helpers
140
+ autoload :FileType, coderay_path('helpers', 'file_type')
141
+
142
+ # Tokens
143
+ autoload :Tokens, coderay_path('tokens')
144
+ autoload :TokensProxy, coderay_path('tokens_proxy')
145
+ autoload :TokenKinds, coderay_path('token_kinds')
146
+
147
+ # Plugin system
148
+ autoload :PluginHost, coderay_path('helpers', 'plugin_host')
149
+ autoload :Plugin, coderay_path('helpers', 'plugin')
150
+
151
+ # Plugins
152
+ autoload :Scanners, coderay_path('scanners')
153
+ autoload :Encoders, coderay_path('encoders')
154
+ autoload :Styles, coderay_path('styles')
155
+
156
+ # convenience access and reusable Encoder/Scanner pair
157
+ autoload :Duo, coderay_path('duo')
158
+
159
+ class << self
160
+
161
+ # Scans the given +code+ (a String) with the Scanner for +lang+.
162
+ #
163
+ # This is a simple way to use CodeRay. Example:
164
+ # require 'coderay'
165
+ # page = CodeRay.scan("puts 'Hello, world!'", :ruby).html
166
+ #
167
+ # See also demo/demo_simple.
168
+ def scan code, lang, options = {}, &block
169
+ CodeRay::TokensProxy.new code, lang, options, block
170
+ end
171
+
172
+ # Scans +filename+ (a path to a code file) with the Scanner for +lang+.
173
+ #
174
+ # If +lang+ is :auto or omitted, the CodeRay::FileType module is used to
175
+ # determine it. If it cannot find out what type it is, it uses
176
+ # CodeRay::Scanners::Text.
177
+ #
178
+ # Calls CodeRay.scan.
179
+ #
180
+ # Example:
181
+ # require 'coderay'
182
+ # page = CodeRay.scan_file('some_c_code.c').html
183
+ def scan_file filename, lang = :auto, options = {}, &block
184
+ lang = CodeRay::FileType.fetch filename, :text, true if lang == :auto
185
+ code = File.read filename
186
+ scan code, lang, options, &block
187
+ end
188
+
189
+ # Encode a string.
190
+ #
191
+ # This scans +code+ with the the Scanner for +lang+ and then
192
+ # encodes it with the Encoder for +format+.
193
+ # +options+ will be passed to the Encoder.
194
+ #
195
+ # See CodeRay::Encoder.encode.
196
+ def encode code, lang, format, options = {}
197
+ encoder(format, options).encode code, lang, options
198
+ end
199
+
200
+ # Encode pre-scanned Tokens.
201
+ # Use this together with CodeRay.scan:
202
+ #
203
+ # require 'coderay'
204
+ #
205
+ # # Highlight a short Ruby code example in a HTML span
206
+ # tokens = CodeRay.scan '1 + 2', :ruby
207
+ # puts CodeRay.encode_tokens(tokens, :span)
208
+ #
209
+ def encode_tokens tokens, format, options = {}
210
+ encoder(format, options).encode_tokens tokens, options
211
+ end
212
+
213
+ # Encodes +filename+ (a path to a code file) with the Scanner for +lang+.
214
+ #
215
+ # See CodeRay.scan_file.
216
+ # Notice that the second argument is the output +format+, not the input language.
217
+ #
218
+ # Example:
219
+ # require 'coderay'
220
+ # page = CodeRay.encode_file 'some_c_code.c', :html
221
+ def encode_file filename, format, options = {}
222
+ tokens = scan_file filename, :auto, get_scanner_options(options)
223
+ encode_tokens tokens, format, options
224
+ end
225
+
226
+ # Highlight a string into a HTML <div>.
227
+ #
228
+ # CSS styles use classes, so you have to include a stylesheet
229
+ # in your output.
230
+ #
231
+ # See encode.
232
+ def highlight code, lang, options = { :css => :class }, format = :div
233
+ encode code, lang, format, options
234
+ end
235
+
236
+ # Highlight a file into a HTML <div>.
237
+ #
238
+ # CSS styles use classes, so you have to include a stylesheet
239
+ # in your output.
240
+ #
241
+ # See encode.
242
+ def highlight_file filename, options = { :css => :class }, format = :div
243
+ encode_file filename, format, options
244
+ end
245
+
246
+ # Finds the Encoder class for +format+ and creates an instance, passing
247
+ # +options+ to it.
248
+ #
249
+ # Example:
250
+ # require 'coderay'
251
+ #
252
+ # stats = CodeRay.encoder(:statistic)
253
+ # stats.encode("puts 17 + 4\n", :ruby)
254
+ #
255
+ # puts '%d out of %d tokens have the kind :integer.' % [
256
+ # stats.type_stats[:integer].count,
257
+ # stats.real_token_count
258
+ # ]
259
+ # #-> 2 out of 4 tokens have the kind :integer.
260
+ def encoder format, options = {}
261
+ CodeRay::Encoders[format].new options
262
+ end
263
+
264
+ # Finds the Scanner class for +lang+ and creates an instance, passing
265
+ # +options+ to it.
266
+ #
267
+ # See Scanner.new.
268
+ def scanner lang, options = {}, &block
269
+ CodeRay::Scanners[lang].new '', options, &block
270
+ end
271
+
272
+ # Extract the options for the scanner from the +options+ hash.
273
+ #
274
+ # Returns an empty Hash if <tt>:scanner_options</tt> is not set.
275
+ #
276
+ # This is used if a method like CodeRay.encode has to provide options
277
+ # for Encoder _and_ scanner.
278
+ def get_scanner_options options
279
+ options.fetch :scanner_options, {}
280
+ end
281
+
282
+ end
283
+
284
+ end