From 923f65cefad6c7967001ceeaae8610164880dd27 Mon Sep 17 00:00:00 2001 From: Sean Santry Date: Wed, 21 Dec 2022 14:34:18 -0500 Subject: [PATCH] Add Ruby language support --- CHANGELOG.md | 4 ++++ README.md | 12 +++++++++- src/main.ts | 8 ++++++- src/settings/Settings.ts | 10 ++++++++- src/settings/SettingsTab.ts | 6 ++++- src/settings/languageDisplayName.ts | 5 +++-- src/settings/per-lang/makeRubySettings.ts | 27 +++++++++++++++++++++++ 7 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 src/settings/per-lang/makeRubySettings.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index b1338cbb..ce1d59c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +## [Unreleased] + +### Added +- Support for Ruby (Thanks to @santry) ## [1.5.0] ### Added diff --git a/README.md b/README.md index d273fc53..a5e3f5ec 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ The result is shown only after the execution is finished. It is not possible to ![Video that shows how the plugin works.](https://github.com/twibiral/obsidian-execute-code/blob/master/images/execute_code_example.gif?raw=true) -The following [languages are supported](#supported-programming-languages): C, CPP, Golang, Groovy, Kotlin, Java, JavaScript, TypeScript, Lua, CSharp, Prolog, Rust, Python, R, Wolfram Mathematica, Haskell, Scala, Shell & Powershell. +The following [languages are supported](#supported-programming-languages): C, CPP, Golang, Groovy, Kotlin, Java, JavaScript, TypeScript, Lua, CSharp, Prolog, Rust, Python, R, Ruby, Wolfram Mathematica, Haskell, Scala, Shell & Powershell. Python and Rust support embedded plots. All languages support ["magic" commands](#magic-commands) that help you to access paths in obsidian or show images in your notes. @@ -328,6 +328,16 @@ println("Hello, World!") ``` +
+Ruby + +- Requirements: Ruby is installed and the correct path is set in the settings. + +```ruby +puts "Hello, World!" +``` +
+ Squiggle: For Squiggle support take a look at the [Obsidian Squiggle plugin](https://github.com/jqhoogland/obsidian-squiggle) by @jqhoogland. Support for the following is planned: diff --git a/src/main.ts b/src/main.ts index 12903c0b..c95afeab 100644 --- a/src/main.ts +++ b/src/main.ts @@ -18,7 +18,7 @@ import runAllCodeBlocks from './runAllCodeBlocks'; export const languageAliases = ["javascript", "typescript", "bash", "csharp", "wolfram", "nb", "wl", "hs", "py"] as const; export const canonicalLanguages = ["js", "ts", "cs", "lua", "python", "cpp", - "prolog", "shell", "groovy", "r", "go", "rust", "java", "powershell", "kotlin", "mathematica", "haskell", "scala", "c"] as const; + "prolog", "shell", "groovy", "r", "go", "rust", "java", "powershell", "kotlin", "mathematica", "haskell", "scala", "c", "ruby"] as const; export const supportedLanguages = [...languageAliases, ...canonicalLanguages] as const; @@ -336,6 +336,12 @@ export default class ExecuteCodePlugin extends Plugin { const transformedCode = await new CodeInjector(this.app, this.settings, language).injectCode(srcCode); this.runCodeInShell(transformedCode, out, button, this.settings.clingPath, this.settings.clingArgs, "c", language, file); }) + } else if(language ==="ruby") { + button.addEventListener("click", async () => { + button.className = runButtonDisabledClass; + const transformedCode = await new CodeInjector(this.app, this.settings, language).injectCode(srcCode); + this.runCodeInShell(transformedCode, out, button, this.settings.rubyPath, this.settings.rubyArgs, "rb", language, file); + }) } } diff --git a/src/settings/Settings.ts b/src/settings/Settings.ts index f4cbfe7e..1be89814 100644 --- a/src/settings/Settings.ts +++ b/src/settings/Settings.ts @@ -82,6 +82,9 @@ export interface ExecutorSettings { cArgs: string; cUseMain: boolean; cInject: string; + rubyPath: string; + rubyArgs: string; + rubyInject: string; jsInteractive: boolean; tsInteractive: boolean; @@ -103,6 +106,7 @@ export interface ExecutorSettings { haskellInteractive: boolean; scalaInteractive: boolean; cInteractive: boolean; + rubyInteractive: boolean; } @@ -188,6 +192,9 @@ export const DEFAULT_SETTINGS: ExecutorSettings = { cArgs: "", cUseMain: true, cInject: "", + rubyPath: "ruby", + rubyArgs: "", + rubyInject: "", jsInteractive: true, tsInteractive: false, @@ -208,5 +215,6 @@ export const DEFAULT_SETTINGS: ExecutorSettings = { mathematicaInteractive: false, haskellInteractive: false, scalaInteractive: false, - cInteractive: false + cInteractive: false, + rubyInteractive: false } diff --git a/src/settings/SettingsTab.ts b/src/settings/SettingsTab.ts index 7f252c75..183e735e 100644 --- a/src/settings/SettingsTab.ts +++ b/src/settings/SettingsTab.ts @@ -16,6 +16,7 @@ import makePowershellSettings from "./per-lang/makePowershellSettings"; import makePrologSettings from "./per-lang/makePrologSettings"; import makePythonSettings from "./per-lang/makePythonSettings"; import makeRSettings from "./per-lang/makeRSettings"; +import makeRubySettings from "./per-lang/makeRubySettings"; import makeRustSettings from "./per-lang/makeRustSettings"; import makeScalaSettings from "./per-lang/makeScalaSettings.js"; import makeShellSettings from "./per-lang/makeShellSettings"; @@ -178,7 +179,10 @@ export class SettingsTab extends PluginSettingTab { // ========== Scala =========== makeScalaSettings(this, this.makeContainerFor("scala")); - + + // ========== Ruby ============ + makeRubySettings(this, this.makeContainerFor("ruby")); + this.focusContainer(this.plugin.settings.lastOpenLanguageTab || canonicalLanguages[0]); } diff --git a/src/settings/languageDisplayName.ts b/src/settings/languageDisplayName.ts index f90dfbd5..31926fd7 100644 --- a/src/settings/languageDisplayName.ts +++ b/src/settings/languageDisplayName.ts @@ -19,5 +19,6 @@ export const DISPLAY_NAMES: Record = { shell: "Shell", ts: "Typescript", scala: "Scala", - c: "C" -} as const; \ No newline at end of file + c: "C", + ruby: "Ruby" +} as const; diff --git a/src/settings/per-lang/makeRubySettings.ts b/src/settings/per-lang/makeRubySettings.ts new file mode 100644 index 00000000..094ae343 --- /dev/null +++ b/src/settings/per-lang/makeRubySettings.ts @@ -0,0 +1,27 @@ +import { Setting } from "obsidian"; +import { SettingsTab } from "../SettingsTab"; + +export default (tab: SettingsTab, containerEl: HTMLElement) => { + containerEl.createEl('h3', { text: 'Ruby Settings' }); + new Setting(containerEl) + .setName('ruby path') + .setDesc("Path to your ruby installation") + .addText(text => text + .setValue(tab.plugin.settings.rubyPath) + .onChange(async (value) => { + const sanitized = tab.sanitizePath(value); + tab.plugin.settings.rubyPath = sanitized; + console.log('ruby path set to: ' + sanitized); + await tab.plugin.saveSettings(); + })); + new Setting(containerEl) + .setName('ruby arguments') + .addText(text => text + .setValue(tab.plugin.settings.rubyArgs) + .onChange(async (value) => { + tab.plugin.settings.rubyArgs = value; + console.log('ruby args set to: ' + value); + await tab.plugin.saveSettings(); + })); + tab.makeInjectSetting(containerEl, "ruby"); +}