Skip to content

Commit b64f3ee

Browse files
authored
Action text rhino (#570)
* install action_text * install rhino-editor * add rhino editor to resource * add rhino view helper * add table extension * try rendering content withouth trix styles and rely on prose * update allowed attributes * add youtube embed to rhino * only display table buttons when active * add source editor * fix * add text alignment option * style links in editor * add editor helper * fix helper name * add show_test page * revert * clean up * change rhino text test route * add table tags to sanitizer * add src and brackets to image not found
1 parent a8de4f2 commit b64f3ee

File tree

22 files changed

+2050
-11
lines changed

22 files changed

+2050
-11
lines changed

app/controllers/resources_controller.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ def show
3535
render :show
3636
end
3737

38+
def rhino_text
39+
@resource = Resource.find(resource_id_param).decorate
40+
load_forms
41+
render :show_test
42+
end
43+
3844
def create
3945
@resource = current_user.resources.build(resource_params)
4046
if @resource.save
@@ -118,12 +124,12 @@ def resource_id_param
118124

119125
def resource_params
120126
params.require(:resource).permit(
121-
:text, :kind, :male, :female, :title, :featured, :inactive, :url,
127+
:text, :rhino_text, :kind, :male, :female, :title, :featured, :inactive, :url,
122128
:agency, :author, :filemaker_code, :windows_type_id, :ordering,
123129
main_image_attributes: [:id, :file, :_destroy],
124130
gallery_images_attributes: [:id, :file, :_destroy],
125131
categorizable_items_attributes: [:id, :category_id, :_destroy], category_ids: [],
126-
sectorable_items_attributes: [:id, :sector_id, :is_leader, :_destroy], sector_ids: [],
132+
sectorable_items_attributes: [:id, :sector_id, :is_leader, :_destroy], sector_ids: []
127133
)
128134
end
129135

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
import "@hotwired/turbo-rails";
2+
import "@rails/actiontext";
3+
import "rhino-editor";
4+
import "rhino-editor/exports/styles/trix.css";
25

36
import "./controllers";
7+
import "./rhino/extend-editor.js";

app/frontend/javascript/controllers/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ application.register("tabs", TabsController)
2929

3030
import TimeframeController from "./timeframe_controller"
3131
application.register("timeframe", TimeframeController)
32+
33+
import RhinoSourceController from "./rhino_source_controller"
34+
application.register("rhino-source", RhinoSourceController)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Controller } from "@hotwired/stimulus"
2+
3+
// Connects to data-controller="rhino-source"
4+
5+
export default class extends Controller {
6+
static targets = ["modal", "textarea"]
7+
8+
connect() {
9+
this.modalTarget.classList.add("hidden")
10+
this._editor = null
11+
}
12+
13+
registerEditor(editor) {
14+
this._editor = editor
15+
}
16+
17+
show(event) {
18+
event?.preventDefault()
19+
if (!this._editor) return
20+
this.textareaTarget.value = this._editor.getHTML()
21+
this.modalTarget.classList.remove("hidden")
22+
}
23+
24+
hide(event) {
25+
event?.preventDefault()
26+
this.modalTarget.classList.add("hidden")
27+
}
28+
29+
save(event) {
30+
event.preventDefault()
31+
if (!this._editor) return
32+
this._editor.chain().focus().setContent(this.textareaTarget.value).run()
33+
this.hide()
34+
}
35+
}

0 commit comments

Comments
 (0)