Module: Kward::ScratchpadLanguages
- Defined in:
- lib/kward/prompt_interface/editor/scratchpad_languages.rb
Overview
Names, aliases, and display paths accepted by the scratchpad command.
Constant Summary collapse
- LANGUAGES =
{ text: { aliases: %w[text txt], display_path: "scratchpad.txt" }, ruby: { aliases: %w[ruby rb], display_path: "scratchpad.rb", runner: :ruby }, erb: { aliases: %w[erb], display_path: "scratchpad.erb" }, crystal: { aliases: %w[crystal cr], display_path: "scratchpad.cr", runner: :crystal }, elixir: { aliases: %w[elixir ex exs], display_path: "scratchpad.ex", runner: :elixir }, julia: { aliases: %w[julia jl], display_path: "scratchpad.jl", runner: :julia }, javascript: { aliases: %w[javascript js jsx mjs cjs], display_path: "scratchpad.js", runner: :node }, typescript: { aliases: %w[typescript ts tsx], display_path: "scratchpad.ts", runner: :node }, json: { aliases: %w[json], display_path: "scratchpad.json" }, markdown: { aliases: %w[markdown md], display_path: "scratchpad.md" }, yaml: { aliases: %w[yaml yml], display_path: "scratchpad.yml" }, shell: { aliases: %w[shell sh bash zsh fish], display_path: "scratchpad.sh", runner: :shell }, makefile: { aliases: %w[makefile make mk], display_path: "scratchpad.mk" }, html: { aliases: %w[html htm], display_path: "scratchpad.html" }, css: { aliases: %w[css], display_path: "scratchpad.css" }, scss: { aliases: %w[scss], display_path: "scratchpad.scss" }, python: { aliases: %w[python py pyw], display_path: "scratchpad.py", runner: :python }, go: { aliases: %w[go], display_path: "scratchpad.go", runner: :go }, rust: { aliases: %w[rust rs], display_path: "scratchpad.rs" }, java: { aliases: %w[java], display_path: "scratchpad.java" }, csharp: { aliases: %w[csharp cs c#], display_path: "scratchpad.cs" }, c: { aliases: %w[c], display_path: "scratchpad.c" }, cpp: { aliases: %w[cpp cc cxx hpp hh hxx c++], display_path: "scratchpad.cpp" }, swift: { aliases: %w[swift], display_path: "scratchpad.swift", runner: :swift }, kotlin: { aliases: %w[kotlin kt kts], display_path: "scratchpad.kt" }, lua: { aliases: %w[lua], display_path: "scratchpad.lua", runner: :lua }, sql: { aliases: %w[sql], display_path: "scratchpad.sql" } }.freeze
- ALIASES =
LANGUAGES.each_with_object({}) do |(language, definition), aliases| ([language.to_s] + definition.fetch(:aliases)).each do |name| aliases[name] = language end end.freeze
Class Method Summary collapse
- .display_path(language) ⇒ Object
- .help_text ⇒ Object
- .normalize(language) ⇒ Object
- .runnable?(language) ⇒ Boolean
- .runner(language) ⇒ Object
Class Method Details
.display_path(language) ⇒ Object
52 53 54 |
# File 'lib/kward/prompt_interface/editor/scratchpad_languages.rb', line 52 def display_path(language) LANGUAGES.fetch(normalize(language)).fetch(:display_path) end |
.help_text ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/kward/prompt_interface/editor/scratchpad_languages.rb', line 64 def help_text lines = ["Supported scratchpad languages:"] LANGUAGES.each do |language, definition| aliases = definition.fetch(:aliases).reject { |name| name == language.to_s } suffix = aliases.empty? ? "" : " (#{aliases.join(", ")})" lines << " #{language}#{suffix}" end lines.join("\n") end |
.normalize(language) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/kward/prompt_interface/editor/scratchpad_languages.rb', line 43 def normalize(language) value = language.to_s.strip.downcase return :text if value.empty? ALIASES.fetch(value) do raise ArgumentError, "Unknown scratchpad language #{language.inspect}. Use /scratchpad help for supported languages." end end |
.runnable?(language) ⇒ Boolean
60 61 62 |
# File 'lib/kward/prompt_interface/editor/scratchpad_languages.rb', line 60 def runnable?(language) !runner(language).nil? end |
.runner(language) ⇒ Object
56 57 58 |
# File 'lib/kward/prompt_interface/editor/scratchpad_languages.rb', line 56 def runner(language) LANGUAGES.fetch(normalize(language))[:runner] end |