-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- adds VS Code's Monaco Editor to the page - allows for saving your code in Rails.env.development?
- Loading branch information
1 parent
0bcfd41
commit 3c3b203
Showing
11 changed files
with
162 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
module PhlexStorybook | ||
class ComponentsController < ApplicationController | ||
def update | ||
respond_to do |format| | ||
format.turbo_stream do | ||
case story_component.update_source(params[:ruby]) | ||
in {success: true} | ||
story_id = params[:story_id] | ||
redirect_to story_path(story_component, story_id: story_id) | ||
in {success: false, error:} | ||
render turbo_stream: [ | ||
turbo_stream.replace( | ||
"saving", | ||
"error: #{error.message}", | ||
), | ||
] | ||
else | ||
# huh?!?! | ||
end | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def story_component | ||
PhlexStorybook.configuration.components.detect { |_k, e| e.name == params[:id] }&.last | ||
end | ||
end | ||
end |
14 changes: 14 additions & 0 deletions
14
app/javascript/phlex_storybook/controllers/code_editor_controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
import * as monaco from "monaco-editor" | ||
|
||
export default class extends Controller { | ||
static targets = ["ruby"]; | ||
|
||
connect() { | ||
monaco.editor.create(this.element, {value: this.source(), language: "ruby", theme: "vs-dark"}); | ||
} | ||
|
||
source() { | ||
return this.rubyTarget.textContent; | ||
} | ||
} |
28 changes: 27 additions & 1 deletion
28
app/javascript/phlex_storybook/controllers/story_display_controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,6 @@ | |
pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true | ||
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true | ||
pin "turbo_power", to: "https://ga.jspm.io/npm:[email protected]/dist/index.js" | ||
pin 'monaco-editor', to: 'https://cdn.jsdelivr.net/npm/[email protected]/+esm' | ||
|
||
pin_all_from PhlexStorybook::Engine.root.join("app/javascript/phlex_storybook/controllers"), under: "controllers", to: "phlex_storybook/controllers" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
PhlexStorybook::Engine.routes.draw do | ||
root to: 'stories#index' | ||
|
||
resources :components, only: [:update] | ||
|
||
resources :stories, only: [:index, :show, :update] do | ||
collection do | ||
get :all | ||
|
||
get 'codicon.ttf', to: redirect( | ||
'https://cdn.jsdelivr.net/npm/[email protected]/esm/vs/base/browser/ui/codicons/codicon/codicon.ttf') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters