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.
- checksums.yaml +7 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +21 -0
- data/README.md +26 -0
- data/chess_engine.gemspec +14 -0
- data/lib/chess_engine/board.rb +95 -0
- data/lib/chess_engine/cli.rb +105 -0
- data/lib/chess_engine/game.rb +148 -0
- data/lib/chess_engine/input.rb +19 -0
- data/lib/chess_engine/move.rb +35 -0
- data/lib/chess_engine/piece.rb +97 -0
- data/lib/chess_engine/validator.rb +87 -0
- data/lib/chess_engine.rb +1 -0
- data/spec/board_spec.rb +70 -0
- data/spec/game_helper.rb +5 -0
- data/spec/game_spec.rb +79 -0
- data/spec/spec_helper.rb +100 -0
- data/spec/validator_spec.rb +26 -0
- data/vendor/bundle/bin/coderay +27 -0
- data/vendor/bundle/bin/pry +27 -0
- data/vendor/bundle/cache/coderay-1.1.2.gem +0 -0
- data/vendor/bundle/cache/colorize-0.8.1.gem +0 -0
- data/vendor/bundle/cache/method_source-0.9.2.gem +0 -0
- data/vendor/bundle/cache/pry-0.12.2.gem +0 -0
- data/vendor/bundle/cache/rb-readline-0.5.5.gem +0 -0
- data/vendor/bundle/gems/coderay-1.1.2/MIT-LICENSE +22 -0
- data/vendor/bundle/gems/coderay-1.1.2/README_INDEX.rdoc +123 -0
- data/vendor/bundle/gems/coderay-1.1.2/bin/coderay +215 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/duo.rb +81 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/_map.rb +17 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/comment_filter.rb +25 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/count.rb +39 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/debug.rb +49 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/debug_lint.rb +63 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/div.rb +23 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/encoder.rb +190 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/filter.rb +58 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html/css.rb +65 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html/numbering.rb +108 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html/output.rb +166 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html.rb +333 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/json.rb +83 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/lines_of_code.rb +45 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/lint.rb +59 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/null.rb +18 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/page.rb +24 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/span.rb +23 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/statistic.rb +95 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/terminal.rb +195 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/text.rb +46 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/token_kind_filter.rb +111 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/xml.rb +72 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/yaml.rb +50 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders.rb +18 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/for_redcloth.rb +95 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/file_type.rb +151 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/plugin.rb +55 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/plugin_host.rb +221 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/word_list.rb +72 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/_map.rb +24 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/c.rb +189 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/clojure.rb +217 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/cpp.rb +217 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/css.rb +196 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/debug.rb +75 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/delphi.rb +144 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/diff.rb +221 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/erb.rb +81 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/go.rb +208 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/groovy.rb +268 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/haml.rb +168 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/html.rb +275 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/java/builtin_types.rb +421 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/java.rb +174 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/java_script.rb +237 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/json.rb +98 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/lua.rb +280 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/php.rb +527 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/python.rb +287 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/raydebug.rb +75 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/ruby/patterns.rb +178 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/ruby/string_state.rb +79 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/ruby.rb +477 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/sass.rb +232 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/scanner.rb +337 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/sql.rb +169 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/taskpaper.rb +36 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/text.rb +26 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/xml.rb +17 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/yaml.rb +140 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners.rb +27 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles/_map.rb +7 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles/alpha.rb +153 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles/style.rb +18 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles.rb +15 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/token_kinds.rb +85 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/tokens.rb +161 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/tokens_proxy.rb +55 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/version.rb +3 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay.rb +284 -0
- data/vendor/bundle/gems/colorize-0.8.1/CHANGELOG +65 -0
- data/vendor/bundle/gems/colorize-0.8.1/LICENSE +339 -0
- data/vendor/bundle/gems/colorize-0.8.1/README.md +105 -0
- data/vendor/bundle/gems/colorize-0.8.1/Rakefile +13 -0
- data/vendor/bundle/gems/colorize-0.8.1/colorize.gemspec +36 -0
- data/vendor/bundle/gems/colorize-0.8.1/lib/colorize/class_methods.rb +120 -0
- data/vendor/bundle/gems/colorize-0.8.1/lib/colorize/instance_methods.rb +132 -0
- data/vendor/bundle/gems/colorize-0.8.1/lib/colorize.rb +12 -0
- data/vendor/bundle/gems/colorize-0.8.1/lib/colorized_string.rb +19 -0
- data/vendor/bundle/gems/colorize-0.8.1/test/test_colorize.rb +164 -0
- data/vendor/bundle/gems/method_source-0.9.2/Gemfile +2 -0
- data/vendor/bundle/gems/method_source-0.9.2/LICENSE +25 -0
- data/vendor/bundle/gems/method_source-0.9.2/README.markdown +91 -0
- data/vendor/bundle/gems/method_source-0.9.2/Rakefile +81 -0
- data/vendor/bundle/gems/method_source-0.9.2/lib/method_source/code_helpers.rb +154 -0
- data/vendor/bundle/gems/method_source-0.9.2/lib/method_source/source_location.rb +138 -0
- data/vendor/bundle/gems/method_source-0.9.2/lib/method_source/version.rb +3 -0
- data/vendor/bundle/gems/method_source-0.9.2/lib/method_source.rb +141 -0
- data/vendor/bundle/gems/method_source-0.9.2/method_source.gemspec +35 -0
- data/vendor/bundle/gems/method_source-0.9.2/spec/method_source/code_helpers_spec.rb +43 -0
- data/vendor/bundle/gems/method_source-0.9.2/spec/method_source_spec.rb +143 -0
- data/vendor/bundle/gems/method_source-0.9.2/spec/spec_helper.rb +101 -0
- data/vendor/bundle/gems/pry-0.12.2/CHANGELOG.md +953 -0
- data/vendor/bundle/gems/pry-0.12.2/LICENSE +25 -0
- data/vendor/bundle/gems/pry-0.12.2/README.md +390 -0
- data/vendor/bundle/gems/pry-0.12.2/bin/pry +8 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/basic_object.rb +6 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/cli.rb +218 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/code/code_file.rb +110 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/code/code_range.rb +71 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/code/loc.rb +98 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/code.rb +353 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/code_object.rb +195 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/color_printer.rb +65 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/command.rb +723 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/command_set.rb +415 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/amend_line.rb +98 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/bang.rb +20 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/bang_pry.rb +17 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/abstract_formatter.rb +27 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/exception_formatter.rb +79 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/file_formatter.rb +71 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat.rb +63 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cd.rb +41 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/change_inspector.rb +27 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/change_prompt.rb +46 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/clear_screen.rb +14 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/code_collector.rb +167 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/disable_pry.rb +27 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/disabled_commands.rb +2 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/easter_eggs.rb +112 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/edit/exception_patcher.rb +25 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/edit/file_and_line_locator.rb +36 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/edit.rb +200 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/exit.rb +43 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/exit_all.rb +29 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/exit_program.rb +23 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/find_method.rb +191 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/fix_indent.rb +19 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_cd.rb +26 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_install.rb +32 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_list.rb +33 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_open.rb +29 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_readme.rb +25 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_search.rb +40 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_stats.rb +83 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gist.rb +102 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/help.rb +164 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/hist.rb +181 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/import_set.rb +23 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/install_command.rb +54 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/jump_to.rb +29 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/list_inspectors.rb +35 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/constants.rb +58 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/formatter.rb +51 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/globals.rb +46 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/grep.rb +19 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/instance_vars.rb +38 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/interrogatable.rb +18 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/jruby_hacks.rb +49 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/local_names.rb +33 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/local_vars.rb +37 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/ls_entity.rb +69 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/methods.rb +54 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/methods_helper.rb +46 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/self_methods.rb +33 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls.rb +113 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/nesting.rb +25 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/play.rb +102 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/pry_backtrace.rb +25 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/pry_version.rb +17 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/raise_up.rb +33 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/reload_code.rb +62 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/reset.rb +18 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ri.rb +65 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/save_file.rb +61 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/shell_command.rb +75 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/shell_mode.rb +25 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_doc.rb +81 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_info.rb +216 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_input.rb +17 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_source.rb +53 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/stat.rb +40 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/switch_to.rb +23 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/toggle_color.rb +24 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/watch_expression/expression.rb +38 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/watch_expression.rb +107 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/whereami.rb +197 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/wtf.rb +70 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands.rb +6 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/behavior.rb +255 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/convenience.rb +28 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/default.rb +159 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/memoization.rb +48 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/config.rb +35 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/core_extensions.rb +142 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/editor.rb +128 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/exceptions.rb +76 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/forwardable.rb +23 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/base_helpers.rb +200 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/command_helpers.rb +157 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/documentation_helpers.rb +76 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/options_helpers.rb +27 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/platform.rb +58 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/table.rb +114 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/text.rb +115 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers.rb +6 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/history.rb +161 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/hooks.rb +171 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/indent.rb +408 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/input_completer.rb +265 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/input_lock.rb +130 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/inspector.rb +27 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/last_exception.rb +61 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/method/disowned.rb +55 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/method/patcher.rb +122 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/method/weird_method_locator.rb +198 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/method.rb +552 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/object_path.rb +83 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/output.rb +50 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/pager.rb +250 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/platform.rb +91 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/plugins.rb +122 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/prompt.rb +145 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/pry_class.rb +425 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/pry_instance.rb +699 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/repl.rb +261 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/repl_file_loader.rb +73 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/ring.rb +84 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/rubygem.rb +84 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop/LICENSE +20 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop/commands.rb +195 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop/option.rb +206 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop.rb +661 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/terminal.rb +91 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/evalable.rb +15 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/mockable.rb +14 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/pry_tester.rb +73 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/utility.rb +26 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/variables.rb +46 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable.rb +70 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/version.rb +3 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/wrapped_module/candidate.rb +131 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/wrapped_module.rb +378 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry.rb +132 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/CHANGES +94 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/LICENSE +25 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/README.md +81 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/Rakefile +25 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/bench/_rl_adjust_point.rb +26 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/examples/example_readline.rb +8 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/examples/example_readline_with_completion.rb +18 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/examples/tinyirb.rb +11 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/lib/rb-readline.rb +18 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/lib/rbreadline/version.rb +3 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/lib/rbreadline.rb +8920 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/lib/readline.rb +539 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/rb-readline.gemspec +51 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/setup.rb +1585 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/test/support/filesystem_completion_helper.rb +53 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/test/test_completion.rb +100 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/test/test_filename_completion_proc.rb +88 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/test/test_history.rb +29 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/test/test_rbreadline.rb +23 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/test/test_readline.rb +221 -0
- data/vendor/bundle/specifications/coderay-1.1.2.gemspec +26 -0
- data/vendor/bundle/specifications/colorize-0.8.1.gemspec +38 -0
- data/vendor/bundle/specifications/method_source-0.9.2.gemspec +35 -0
- data/vendor/bundle/specifications/pry-0.12.2.gemspec +38 -0
- data/vendor/bundle/specifications/rb-readline-0.5.5.gemspec +39 -0
- metadata +363 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
module CodeRay
|
2
|
+
module Encoders
|
3
|
+
|
4
|
+
# A Filter encoder has another Tokens instance as output.
|
5
|
+
# It can be subclass to select, remove, or modify tokens in the stream.
|
6
|
+
#
|
7
|
+
# Subclasses of Filter are called "Filters" and can be chained.
|
8
|
+
#
|
9
|
+
# == Options
|
10
|
+
#
|
11
|
+
# === :tokens
|
12
|
+
#
|
13
|
+
# The Tokens object which will receive the output.
|
14
|
+
#
|
15
|
+
# Default: Tokens.new
|
16
|
+
#
|
17
|
+
# See also: TokenKindFilter
|
18
|
+
class Filter < Encoder
|
19
|
+
|
20
|
+
register_for :filter
|
21
|
+
|
22
|
+
protected
|
23
|
+
def setup options
|
24
|
+
super
|
25
|
+
|
26
|
+
@tokens = options[:tokens] || Tokens.new
|
27
|
+
end
|
28
|
+
|
29
|
+
def finish options
|
30
|
+
output @tokens
|
31
|
+
end
|
32
|
+
|
33
|
+
public
|
34
|
+
|
35
|
+
def text_token text, kind # :nodoc:
|
36
|
+
@tokens.text_token text, kind
|
37
|
+
end
|
38
|
+
|
39
|
+
def begin_group kind # :nodoc:
|
40
|
+
@tokens.begin_group kind
|
41
|
+
end
|
42
|
+
|
43
|
+
def begin_line kind # :nodoc:
|
44
|
+
@tokens.begin_line kind
|
45
|
+
end
|
46
|
+
|
47
|
+
def end_group kind # :nodoc:
|
48
|
+
@tokens.end_group kind
|
49
|
+
end
|
50
|
+
|
51
|
+
def end_line kind # :nodoc:
|
52
|
+
@tokens.end_line kind
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module CodeRay
|
2
|
+
module Encoders
|
3
|
+
|
4
|
+
class HTML
|
5
|
+
class CSS # :nodoc:
|
6
|
+
|
7
|
+
attr :stylesheet
|
8
|
+
|
9
|
+
def CSS.load_stylesheet style = nil
|
10
|
+
CodeRay::Styles[style]
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize style = :default
|
14
|
+
@styles = Hash.new
|
15
|
+
style = CSS.load_stylesheet style
|
16
|
+
@stylesheet = [
|
17
|
+
style::CSS_MAIN_STYLES,
|
18
|
+
style::TOKEN_COLORS.gsub(/^(?!$)/, '.CodeRay ')
|
19
|
+
].join("\n")
|
20
|
+
parse style::TOKEN_COLORS
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_style_for_css_classes css_classes
|
24
|
+
cl = @styles[css_classes.first]
|
25
|
+
return '' unless cl
|
26
|
+
style = ''
|
27
|
+
1.upto css_classes.size do |offset|
|
28
|
+
break if style = cl[css_classes[offset .. -1]]
|
29
|
+
end
|
30
|
+
# warn 'Style not found: %p' % [styles] if style.empty?
|
31
|
+
return style
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
CSS_CLASS_PATTERN = /
|
37
|
+
( # $1 = selectors
|
38
|
+
(?:
|
39
|
+
(?: \s* \. [-\w]+ )+
|
40
|
+
\s* ,?
|
41
|
+
)+
|
42
|
+
)
|
43
|
+
\s* \{ \s*
|
44
|
+
( [^\}]+ )? # $2 = style
|
45
|
+
\s* \} \s*
|
46
|
+
|
|
47
|
+
( [^\n]+ ) # $3 = error
|
48
|
+
/mx
|
49
|
+
def parse stylesheet
|
50
|
+
stylesheet.scan CSS_CLASS_PATTERN do |selectors, style, error|
|
51
|
+
raise "CSS parse error: '#{error.inspect}' not recognized" if error
|
52
|
+
for selector in selectors.split(',')
|
53
|
+
classes = selector.scan(/[-\w]+/)
|
54
|
+
cl = classes.pop
|
55
|
+
@styles[cl] ||= Hash.new
|
56
|
+
@styles[cl][classes] = style.to_s.strip.delete(' ').chomp(';')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
module CodeRay
|
2
|
+
module Encoders
|
3
|
+
|
4
|
+
class HTML
|
5
|
+
|
6
|
+
module Numbering # :nodoc:
|
7
|
+
|
8
|
+
def self.number! output, mode = :table, options = {}
|
9
|
+
return self unless mode
|
10
|
+
|
11
|
+
options = DEFAULT_OPTIONS.merge options
|
12
|
+
|
13
|
+
start = options[:line_number_start]
|
14
|
+
unless start.is_a? Integer
|
15
|
+
raise ArgumentError, "Invalid value %p for :line_number_start; Integer expected." % start
|
16
|
+
end
|
17
|
+
|
18
|
+
anchor_prefix = options[:line_number_anchors]
|
19
|
+
anchor_prefix = 'line' if anchor_prefix == true
|
20
|
+
anchor_prefix = anchor_prefix.to_s[/[\w-]+/] if anchor_prefix
|
21
|
+
anchoring =
|
22
|
+
if anchor_prefix
|
23
|
+
proc do |line|
|
24
|
+
line = line.to_s
|
25
|
+
anchor = anchor_prefix + line
|
26
|
+
"<a href=\"##{anchor}\" name=\"#{anchor}\">#{line}</a>"
|
27
|
+
end
|
28
|
+
else
|
29
|
+
:to_s.to_proc
|
30
|
+
end
|
31
|
+
|
32
|
+
bold_every = options[:bold_every]
|
33
|
+
highlight_lines = options[:highlight_lines]
|
34
|
+
bolding =
|
35
|
+
if bold_every == false && highlight_lines == nil
|
36
|
+
anchoring
|
37
|
+
elsif highlight_lines.is_a? Enumerable
|
38
|
+
highlight_lines = highlight_lines.to_set
|
39
|
+
proc do |line|
|
40
|
+
if highlight_lines.include? line
|
41
|
+
"<strong class=\"highlighted\">#{anchoring[line]}</strong>" # highlighted line numbers in bold
|
42
|
+
else
|
43
|
+
anchoring[line]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
elsif bold_every.is_a? Integer
|
47
|
+
raise ArgumentError, ":bolding can't be 0." if bold_every == 0
|
48
|
+
proc do |line|
|
49
|
+
if line % bold_every == 0
|
50
|
+
"<strong>#{anchoring[line]}</strong>" # every bold_every-th number in bold
|
51
|
+
else
|
52
|
+
anchoring[line]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
else
|
56
|
+
raise ArgumentError, 'Invalid value %p for :bolding; false or Integer expected.' % bold_every
|
57
|
+
end
|
58
|
+
|
59
|
+
if position_of_last_newline = output.rindex(RUBY_VERSION >= '1.9' ? /\n/ : ?\n)
|
60
|
+
after_last_newline = output[position_of_last_newline + 1 .. -1]
|
61
|
+
ends_with_newline = after_last_newline[/\A(?:<\/span>)*\z/]
|
62
|
+
|
63
|
+
if ends_with_newline
|
64
|
+
line_count = output.count("\n")
|
65
|
+
else
|
66
|
+
line_count = output.count("\n") + 1
|
67
|
+
end
|
68
|
+
else
|
69
|
+
line_count = 1
|
70
|
+
end
|
71
|
+
|
72
|
+
case mode
|
73
|
+
when :inline
|
74
|
+
max_width = (start + line_count).to_s.size
|
75
|
+
line_number = start
|
76
|
+
output.gsub!(/^.*$\n?/) do |line|
|
77
|
+
line_number_text = bolding.call line_number
|
78
|
+
indent = ' ' * (max_width - line_number.to_s.size)
|
79
|
+
line_number += 1
|
80
|
+
"<span class=\"line-numbers\">#{indent}#{line_number_text}</span>#{line}"
|
81
|
+
end
|
82
|
+
|
83
|
+
when :table
|
84
|
+
line_numbers = (start ... start + line_count).map(&bolding).join("\n")
|
85
|
+
line_numbers << "\n"
|
86
|
+
line_numbers_table_template = Output::TABLE.apply('LINE_NUMBERS', line_numbers)
|
87
|
+
|
88
|
+
output.gsub!(/<\/div>\n/, '</div>')
|
89
|
+
output.wrap_in! line_numbers_table_template
|
90
|
+
output.wrapped_in = :div
|
91
|
+
|
92
|
+
when :list
|
93
|
+
raise NotImplementedError, 'The :list option is no longer available. Use :table.'
|
94
|
+
|
95
|
+
else
|
96
|
+
raise ArgumentError, 'Unknown value %p for mode: expected one of %p' %
|
97
|
+
[mode, [:table, :inline]]
|
98
|
+
end
|
99
|
+
|
100
|
+
output
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
module CodeRay
|
2
|
+
module Encoders
|
3
|
+
|
4
|
+
class HTML
|
5
|
+
|
6
|
+
# This module is included in the output String of the HTML Encoder.
|
7
|
+
#
|
8
|
+
# It provides methods like wrap, div, page etc.
|
9
|
+
#
|
10
|
+
# Remember to use #clone instead of #dup to keep the modules the object was
|
11
|
+
# extended with.
|
12
|
+
#
|
13
|
+
# TODO: Rewrite this without monkey patching.
|
14
|
+
module Output
|
15
|
+
|
16
|
+
attr_accessor :css
|
17
|
+
|
18
|
+
class << self
|
19
|
+
|
20
|
+
# Raises an exception if an object that doesn't respond to to_str is extended by Output,
|
21
|
+
# to prevent users from misuse. Use Module#remove_method to disable.
|
22
|
+
def extended o # :nodoc:
|
23
|
+
warn "The Output module is intended to extend instances of String, not #{o.class}." unless o.respond_to? :to_str
|
24
|
+
end
|
25
|
+
|
26
|
+
def make_stylesheet css, in_tag = false # :nodoc:
|
27
|
+
sheet = css.stylesheet
|
28
|
+
sheet = <<-'CSS' if in_tag
|
29
|
+
<style type="text/css">
|
30
|
+
#{sheet}
|
31
|
+
</style>
|
32
|
+
CSS
|
33
|
+
sheet
|
34
|
+
end
|
35
|
+
|
36
|
+
def page_template_for_css css # :nodoc:
|
37
|
+
sheet = make_stylesheet css
|
38
|
+
PAGE.apply 'CSS', sheet
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
def wrapped_in? element
|
44
|
+
wrapped_in == element
|
45
|
+
end
|
46
|
+
|
47
|
+
def wrapped_in
|
48
|
+
@wrapped_in ||= nil
|
49
|
+
end
|
50
|
+
attr_writer :wrapped_in
|
51
|
+
|
52
|
+
def wrap_in! template
|
53
|
+
Template.wrap! self, template, 'CONTENT'
|
54
|
+
self
|
55
|
+
end
|
56
|
+
|
57
|
+
def apply_title! title
|
58
|
+
self.sub!(/(<title>)(<\/title>)/) { $1 + title + $2 }
|
59
|
+
self
|
60
|
+
end
|
61
|
+
|
62
|
+
def wrap! element, *args
|
63
|
+
return self if not element or element == wrapped_in
|
64
|
+
case element
|
65
|
+
when :div
|
66
|
+
raise "Can't wrap %p in %p" % [wrapped_in, element] unless wrapped_in? nil
|
67
|
+
wrap_in! DIV
|
68
|
+
when :span
|
69
|
+
raise "Can't wrap %p in %p" % [wrapped_in, element] unless wrapped_in? nil
|
70
|
+
wrap_in! SPAN
|
71
|
+
when :page
|
72
|
+
wrap! :div if wrapped_in? nil
|
73
|
+
raise "Can't wrap %p in %p" % [wrapped_in, element] unless wrapped_in? :div
|
74
|
+
wrap_in! Output.page_template_for_css(@css)
|
75
|
+
if args.first.is_a?(Hash) && title = args.first[:title]
|
76
|
+
apply_title! title
|
77
|
+
end
|
78
|
+
self
|
79
|
+
when nil
|
80
|
+
return self
|
81
|
+
else
|
82
|
+
raise "Unknown value %p for :wrap" % element
|
83
|
+
end
|
84
|
+
@wrapped_in = element
|
85
|
+
self
|
86
|
+
end
|
87
|
+
|
88
|
+
def stylesheet in_tag = false
|
89
|
+
Output.make_stylesheet @css, in_tag
|
90
|
+
end
|
91
|
+
|
92
|
+
#-- don't include the templates in docu
|
93
|
+
|
94
|
+
class Template < String # :nodoc:
|
95
|
+
|
96
|
+
def self.wrap! str, template, target
|
97
|
+
target = Regexp.new(Regexp.escape("<%#{target}%>"))
|
98
|
+
if template =~ target
|
99
|
+
str[0,0] = $`
|
100
|
+
str << $'
|
101
|
+
else
|
102
|
+
raise "Template target <%%%p%%> not found" % target
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def apply target, replacement
|
107
|
+
target = Regexp.new(Regexp.escape("<%#{target}%>"))
|
108
|
+
if self =~ target
|
109
|
+
Template.new($` + replacement + $')
|
110
|
+
else
|
111
|
+
raise "Template target <%%%p%%> not found" % target
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
SPAN = Template.new '<span class="CodeRay"><%CONTENT%></span>'
|
118
|
+
|
119
|
+
DIV = Template.new <<-DIV
|
120
|
+
<div class="CodeRay">
|
121
|
+
<div class="code"><pre><%CONTENT%></pre></div>
|
122
|
+
</div>
|
123
|
+
DIV
|
124
|
+
|
125
|
+
TABLE = Template.new <<-TABLE
|
126
|
+
<table class="CodeRay"><tr>
|
127
|
+
<td class="line-numbers"><pre><%LINE_NUMBERS%></pre></td>
|
128
|
+
<td class="code"><pre><%CONTENT%></pre></td>
|
129
|
+
</tr></table>
|
130
|
+
TABLE
|
131
|
+
|
132
|
+
PAGE = Template.new <<-PAGE
|
133
|
+
<!DOCTYPE html>
|
134
|
+
<html>
|
135
|
+
<head>
|
136
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
137
|
+
<title></title>
|
138
|
+
<style type="text/css">
|
139
|
+
.CodeRay .line-numbers a {
|
140
|
+
text-decoration: inherit;
|
141
|
+
color: inherit;
|
142
|
+
}
|
143
|
+
body {
|
144
|
+
background-color: white;
|
145
|
+
padding: 0;
|
146
|
+
margin: 0;
|
147
|
+
}
|
148
|
+
<%CSS%>
|
149
|
+
.CodeRay {
|
150
|
+
border: none;
|
151
|
+
}
|
152
|
+
</style>
|
153
|
+
</head>
|
154
|
+
<body>
|
155
|
+
|
156
|
+
<%CONTENT%>
|
157
|
+
</body>
|
158
|
+
</html>
|
159
|
+
PAGE
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
end
|
@@ -0,0 +1,333 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
module CodeRay
|
4
|
+
module Encoders
|
5
|
+
|
6
|
+
# = HTML Encoder
|
7
|
+
#
|
8
|
+
# This is CodeRay's most important highlighter:
|
9
|
+
# It provides save, fast XHTML generation and CSS support.
|
10
|
+
#
|
11
|
+
# == Usage
|
12
|
+
#
|
13
|
+
# require 'coderay'
|
14
|
+
# puts CodeRay.scan('Some /code/', :ruby).html #-> a HTML page
|
15
|
+
# puts CodeRay.scan('Some /code/', :ruby).html(:wrap => :span)
|
16
|
+
# #-> <span class="CodeRay"><span class="co">Some</span> /code/</span>
|
17
|
+
# puts CodeRay.scan('Some /code/', :ruby).span #-> the same
|
18
|
+
#
|
19
|
+
# puts CodeRay.scan('Some code', :ruby).html(
|
20
|
+
# :wrap => nil,
|
21
|
+
# :line_numbers => :inline,
|
22
|
+
# :css => :style
|
23
|
+
# )
|
24
|
+
#
|
25
|
+
# == Options
|
26
|
+
#
|
27
|
+
# === :tab_width
|
28
|
+
# Convert \t characters to +n+ spaces (a number or false.)
|
29
|
+
# false will keep tab characters untouched.
|
30
|
+
#
|
31
|
+
# Default: 8
|
32
|
+
#
|
33
|
+
# === :css
|
34
|
+
# How to include the styles; can be :class or :style.
|
35
|
+
#
|
36
|
+
# Default: :class
|
37
|
+
#
|
38
|
+
# === :wrap
|
39
|
+
# Wrap in :page, :div, :span or nil.
|
40
|
+
#
|
41
|
+
# You can also use Encoders::Div and Encoders::Span.
|
42
|
+
#
|
43
|
+
# Default: nil
|
44
|
+
#
|
45
|
+
# === :title
|
46
|
+
#
|
47
|
+
# The title of the HTML page (works only when :wrap is set to :page.)
|
48
|
+
#
|
49
|
+
# Default: 'CodeRay output'
|
50
|
+
#
|
51
|
+
# === :break_lines
|
52
|
+
#
|
53
|
+
# Split multiline blocks at line breaks.
|
54
|
+
# Forced to true if :line_numbers option is set to :inline.
|
55
|
+
#
|
56
|
+
# Default: false
|
57
|
+
#
|
58
|
+
# === :line_numbers
|
59
|
+
# Include line numbers in :table, :inline, or nil (no line numbers)
|
60
|
+
#
|
61
|
+
# Default: nil
|
62
|
+
#
|
63
|
+
# === :line_number_anchors
|
64
|
+
# Adds anchors and links to the line numbers. Can be false (off), true (on),
|
65
|
+
# or a prefix string that will be prepended to the anchor name.
|
66
|
+
#
|
67
|
+
# The prefix must consist only of letters, digits, and underscores.
|
68
|
+
#
|
69
|
+
# Default: true, default prefix name: "line"
|
70
|
+
#
|
71
|
+
# === :line_number_start
|
72
|
+
# Where to start with line number counting.
|
73
|
+
#
|
74
|
+
# Default: 1
|
75
|
+
#
|
76
|
+
# === :bold_every
|
77
|
+
# Make every +n+-th number appear bold.
|
78
|
+
#
|
79
|
+
# Default: 10
|
80
|
+
#
|
81
|
+
# === :highlight_lines
|
82
|
+
#
|
83
|
+
# Highlights certain line numbers.
|
84
|
+
# Can be any Enumerable, typically just an Array or Range, of numbers.
|
85
|
+
#
|
86
|
+
# Bolding is deactivated when :highlight_lines is set. It only makes sense
|
87
|
+
# in combination with :line_numbers.
|
88
|
+
#
|
89
|
+
# Default: nil
|
90
|
+
#
|
91
|
+
# === :hint
|
92
|
+
# Include some information into the output using the title attribute.
|
93
|
+
# Can be :info (show token kind on mouse-over), :info_long (with full path)
|
94
|
+
# or :debug (via inspect).
|
95
|
+
#
|
96
|
+
# Default: false
|
97
|
+
class HTML < Encoder
|
98
|
+
|
99
|
+
register_for :html
|
100
|
+
|
101
|
+
FILE_EXTENSION = 'snippet.html'
|
102
|
+
|
103
|
+
DEFAULT_OPTIONS = {
|
104
|
+
:tab_width => 8,
|
105
|
+
|
106
|
+
:css => :class,
|
107
|
+
:style => :alpha,
|
108
|
+
:wrap => nil,
|
109
|
+
:title => 'CodeRay output',
|
110
|
+
|
111
|
+
:break_lines => false,
|
112
|
+
|
113
|
+
:line_numbers => nil,
|
114
|
+
:line_number_anchors => 'n',
|
115
|
+
:line_number_start => 1,
|
116
|
+
:bold_every => 10,
|
117
|
+
:highlight_lines => nil,
|
118
|
+
|
119
|
+
:hint => false,
|
120
|
+
}
|
121
|
+
|
122
|
+
autoload :Output, CodeRay.coderay_path('encoders', 'html', 'output')
|
123
|
+
autoload :CSS, CodeRay.coderay_path('encoders', 'html', 'css')
|
124
|
+
autoload :Numbering, CodeRay.coderay_path('encoders', 'html', 'numbering')
|
125
|
+
|
126
|
+
attr_reader :css
|
127
|
+
|
128
|
+
protected
|
129
|
+
|
130
|
+
def self.make_html_escape_hash
|
131
|
+
{
|
132
|
+
'&' => '&',
|
133
|
+
'"' => '"',
|
134
|
+
'>' => '>',
|
135
|
+
'<' => '<',
|
136
|
+
# "\t" => will be set to ' ' * options[:tab_width] during setup
|
137
|
+
}.tap do |hash|
|
138
|
+
# Escape ASCII control codes except \x9 == \t and \xA == \n.
|
139
|
+
(Array(0x00..0x8) + Array(0xB..0x1F)).each { |invalid| hash[invalid.chr] = ' ' }
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
HTML_ESCAPE = make_html_escape_hash
|
144
|
+
HTML_ESCAPE_PATTERN = /[\t"&><\0-\x8\xB-\x1F]/
|
145
|
+
|
146
|
+
TOKEN_KIND_TO_INFO = Hash.new do |h, kind|
|
147
|
+
h[kind] = kind.to_s.gsub(/_/, ' ').gsub(/\b\w/) { $&.capitalize }
|
148
|
+
end
|
149
|
+
|
150
|
+
TRANSPARENT_TOKEN_KINDS = Set[
|
151
|
+
:delimiter, :modifier, :content, :escape, :inline_delimiter,
|
152
|
+
]
|
153
|
+
|
154
|
+
# Generate a hint about the given +kinds+ in a +hint+ style.
|
155
|
+
#
|
156
|
+
# +hint+ may be :info, :info_long or :debug.
|
157
|
+
def self.token_path_to_hint hint, kinds
|
158
|
+
kinds = Array kinds
|
159
|
+
title =
|
160
|
+
case hint
|
161
|
+
when :info
|
162
|
+
kinds = kinds[1..-1] if TRANSPARENT_TOKEN_KINDS.include? kinds.first
|
163
|
+
TOKEN_KIND_TO_INFO[kinds.first]
|
164
|
+
when :info_long
|
165
|
+
kinds.reverse.map { |kind| TOKEN_KIND_TO_INFO[kind] }.join('/')
|
166
|
+
when :debug
|
167
|
+
kinds.inspect
|
168
|
+
end
|
169
|
+
title ? " title=\"#{title}\"" : ''
|
170
|
+
end
|
171
|
+
|
172
|
+
def setup options
|
173
|
+
super
|
174
|
+
|
175
|
+
check_options! options
|
176
|
+
|
177
|
+
if options[:wrap] || options[:line_numbers]
|
178
|
+
@real_out = @out
|
179
|
+
@out = ''.dup
|
180
|
+
end
|
181
|
+
|
182
|
+
@break_lines = (options[:break_lines] == true)
|
183
|
+
|
184
|
+
@HTML_ESCAPE = HTML_ESCAPE.merge("\t" => options[:tab_width] ? ' ' * options[:tab_width] : "\t")
|
185
|
+
|
186
|
+
@opened = []
|
187
|
+
@last_opened = nil
|
188
|
+
@css = CSS.new options[:style]
|
189
|
+
|
190
|
+
@span_for_kinds = make_span_for_kinds(options[:css], options[:hint])
|
191
|
+
|
192
|
+
@set_last_opened = options[:hint] || options[:css] == :style
|
193
|
+
end
|
194
|
+
|
195
|
+
def finish options
|
196
|
+
unless @opened.empty?
|
197
|
+
@out << '</span>' while @opened.pop
|
198
|
+
@last_opened = nil
|
199
|
+
end
|
200
|
+
|
201
|
+
if @out.respond_to? :to_str
|
202
|
+
@out.extend Output
|
203
|
+
@out.css = @css
|
204
|
+
if options[:line_numbers]
|
205
|
+
Numbering.number! @out, options[:line_numbers], options
|
206
|
+
end
|
207
|
+
@out.wrap! options[:wrap]
|
208
|
+
@out.apply_title! options[:title]
|
209
|
+
end
|
210
|
+
|
211
|
+
if defined?(@real_out) && @real_out
|
212
|
+
@real_out << @out
|
213
|
+
@out = @real_out
|
214
|
+
end
|
215
|
+
|
216
|
+
super
|
217
|
+
end
|
218
|
+
|
219
|
+
public
|
220
|
+
|
221
|
+
def text_token text, kind
|
222
|
+
style = @span_for_kinds[@last_opened ? [kind, *@opened] : kind]
|
223
|
+
|
224
|
+
text = text.gsub(/#{HTML_ESCAPE_PATTERN}/o) { |m| @HTML_ESCAPE[m] } if text =~ /#{HTML_ESCAPE_PATTERN}/o
|
225
|
+
text = break_lines(text, style) if @break_lines && (style || @opened.size > 0) && text.index("\n")
|
226
|
+
|
227
|
+
if style
|
228
|
+
@out << style << text << '</span>'
|
229
|
+
else
|
230
|
+
@out << text
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
# token groups, eg. strings
|
235
|
+
def begin_group kind
|
236
|
+
@out << (@span_for_kinds[@last_opened ? [kind, *@opened] : kind] || '<span>')
|
237
|
+
@opened << kind
|
238
|
+
@last_opened = kind if @set_last_opened
|
239
|
+
end
|
240
|
+
|
241
|
+
def end_group kind
|
242
|
+
check_group_nesting 'token group', kind if $CODERAY_DEBUG
|
243
|
+
close_span
|
244
|
+
end
|
245
|
+
|
246
|
+
# whole lines to be highlighted, eg. a deleted line in a diff
|
247
|
+
def begin_line kind
|
248
|
+
if style = @span_for_kinds[@last_opened ? [kind, *@opened] : kind]
|
249
|
+
if style['class="']
|
250
|
+
@out << style.sub('class="', 'class="line ')
|
251
|
+
else
|
252
|
+
@out << style.sub('>', ' class="line">')
|
253
|
+
end
|
254
|
+
else
|
255
|
+
@out << '<span class="line">'
|
256
|
+
end
|
257
|
+
@opened << kind
|
258
|
+
@last_opened = kind if @options[:css] == :style
|
259
|
+
end
|
260
|
+
|
261
|
+
def end_line kind
|
262
|
+
check_group_nesting 'line', kind if $CODERAY_DEBUG
|
263
|
+
close_span
|
264
|
+
end
|
265
|
+
|
266
|
+
protected
|
267
|
+
|
268
|
+
def check_options! options
|
269
|
+
unless [false, nil, :debug, :info, :info_long].include? options[:hint]
|
270
|
+
raise ArgumentError, "Unknown value %p for :hint; expected :info, :info_long, :debug, false, or nil." % [options[:hint]]
|
271
|
+
end
|
272
|
+
|
273
|
+
unless [:class, :style].include? options[:css]
|
274
|
+
raise ArgumentError, 'Unknown value %p for :css.' % [options[:css]]
|
275
|
+
end
|
276
|
+
|
277
|
+
options[:break_lines] = true if options[:line_numbers] == :inline
|
278
|
+
end
|
279
|
+
|
280
|
+
def css_class_for_kinds kinds
|
281
|
+
TokenKinds[kinds.is_a?(Symbol) ? kinds : kinds.first]
|
282
|
+
end
|
283
|
+
|
284
|
+
def style_for_kinds kinds
|
285
|
+
css_classes = kinds.is_a?(Array) ? kinds.map { |c| TokenKinds[c] } : [TokenKinds[kinds]]
|
286
|
+
@css.get_style_for_css_classes css_classes
|
287
|
+
end
|
288
|
+
|
289
|
+
def make_span_for_kinds method, hint
|
290
|
+
Hash.new do |h, kinds|
|
291
|
+
begin
|
292
|
+
css_class = css_class_for_kinds(kinds)
|
293
|
+
title = HTML.token_path_to_hint hint, kinds if hint
|
294
|
+
|
295
|
+
if css_class || title
|
296
|
+
if method == :style
|
297
|
+
style = style_for_kinds(kinds)
|
298
|
+
"<span#{title}#{" style=\"#{style}\"" if style}>"
|
299
|
+
else
|
300
|
+
"<span#{title}#{" class=\"#{css_class}\"" if css_class}>"
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end.tap do |span|
|
304
|
+
h.clear if h.size >= 100
|
305
|
+
h[kinds] = span
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
def check_group_nesting name, kind
|
311
|
+
if @opened.empty? || @opened.last != kind
|
312
|
+
warn "Malformed token stream: Trying to close a #{name} (%p) that is not open. Open are: %p." % [kind, @opened[1..-1]]
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
def break_lines text, style
|
317
|
+
reopen = ''.dup
|
318
|
+
@opened.each_with_index do |kind, index|
|
319
|
+
reopen << (@span_for_kinds[index > 0 ? [kind, *@opened[0...index]] : kind] || '<span>')
|
320
|
+
end
|
321
|
+
text.gsub("\n", "#{'</span>' * @opened.size}#{'</span>' if style}\n#{reopen}#{style}")
|
322
|
+
end
|
323
|
+
|
324
|
+
def close_span
|
325
|
+
if @opened.pop
|
326
|
+
@out << '</span>'
|
327
|
+
@last_opened = @opened.last if @last_opened
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
end
|
333
|
+
end
|