-
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.
feat: starting work on experiments (sandbox)
- new ExperimentsController - look for experiments in `Rails.root.join("tmp", "experiments")` - more work to come
- Loading branch information
1 parent
3c3b203
commit 973caae
Showing
11 changed files
with
178 additions
and
35 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,46 @@ | ||
# frozen_string_literal: true | ||
|
||
module PhlexStorybook | ||
class ExperimentsController < ApplicationController | ||
before_action :reject_unless_editable! | ||
|
||
layout -> { Layouts::ApplicationLayout } | ||
|
||
def preview | ||
respond_to do |format| | ||
format.html { eval File.read(experiment) } | ||
end | ||
end | ||
|
||
def show | ||
respond_to do |format| | ||
format.html do | ||
render Components::Experiments::Index.new(selected: experiment_name) | ||
end | ||
|
||
format.turbo_stream do | ||
render turbo_stream: [ | ||
turbo_stream.replace( | ||
"experiment_display", | ||
Components::Experiments::ExperimentDisplay.new(name: experiment_name), | ||
), | ||
] | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def experiment | ||
PhlexStorybook.configuration.experiment experiment_name | ||
end | ||
|
||
def experiment_name | ||
params[:id] | ||
end | ||
|
||
def reject_unless_editable! | ||
redirect_to root_path unless PhlexStorybook.configuration.editable? | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails | ||
import { Turbo } from '@hotwired/turbo' | ||
import "@hotwired/turbo-rails" | ||
import "controllers" | ||
import TurboPower from 'turbo_power' | ||
TurboPower.initialize(Turbo.StreamActions) | ||
// import TurboPower from 'turbo_power' | ||
// TurboPower.initialize(Turbo.StreamActions) |
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,8 +1,7 @@ | ||
pin "phlex_storybook", to: "phlex_storybook/application.js", preload: true | ||
pin "@hotwired/turbo", to: "turbo.min.js", preload: true | ||
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true | ||
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
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
44 changes: 44 additions & 0 deletions
44
lib/phlex_storybook/components/experiments/experiment_display.rb
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,44 @@ | ||
# frozen_string_literal: true | ||
|
||
module PhlexStorybook | ||
module Components | ||
module Experiments | ||
class ExperimentDisplay < ApplicationView | ||
# include Phlex::Rails::Helpers::IframeTag | ||
|
||
def initialize(name:) | ||
@name = name | ||
end | ||
|
||
def view_template | ||
unless PhlexStorybook.configuration.experiment(@name) | ||
turbo_frame_tag("experiment_display") do | ||
blank_template | ||
end | ||
return | ||
end | ||
|
||
turbo_frame_tag("experiment_display") do | ||
div(class: "flex flex-col h-screen max-h-screen", data: { controller: "story-display copy" }) do | ||
render_header @name | ||
div(class: "px-2 flex-1 overflow-y-scroll overflow-x-hidden") do | ||
iframe(src: helpers.preview_experiment_path(@name), class: "w-full h-full") | ||
end | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def blank_template | ||
render_header("Select a component") | ||
div(class: "px-2") { "Select an experiment from the left to see its preview" } | ||
end | ||
|
||
def render_header(text) | ||
h2(class: "bg-slate-900 text-white border-x border-slate-700 p-2 flex-none") { text } | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
module PhlexStorybook | ||
module Components | ||
module Experiments | ||
class Index < ApplicationView | ||
def initialize(selected: nil) | ||
@story_components = PhlexStorybook.configuration.components | ||
@selected = selected | ||
end | ||
|
||
def view_template | ||
turbo_frame_tag("story_components") do | ||
div class: "flex h-screen w-screen" do | ||
div class: "flex-none w-1/4 min-w-40 max-w-80 bg-slate-700 text-white story-selector" do | ||
render Stories::ComponentSelector.new(story_components: @story_components) | ||
end | ||
|
||
div class: "flex-auto h-full w-3/4 bg-white" do | ||
render ExperimentDisplay.new(name: @selected) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
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