Skip to content

Commit

Permalink
Merge pull request #2684 from AlchemyCMS/richtext-input
Browse files Browse the repository at this point in the history
Add richtext input type for form builder
  • Loading branch information
tvdeyen authored Jan 11, 2024
2 parents dc7cc76 + e823fc9 commit 9764055
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
7 changes: 7 additions & 0 deletions lib/alchemy/forms/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ def datepicker(attribute_name, options = {})
template.content_tag("alchemy-datepicker", date_field, type: type)
end

# Renders a simple_form input that displays a richtext editor
#
def richtext(attribute_name, options = {})
text_area = input(attribute_name, options.merge(as: :text))
template.content_tag("alchemy-tinymce", text_area)
end

# Renders a button tag wrapped in a div with 'submit' class.
#
def submit(label, options = {})
Expand Down
48 changes: 38 additions & 10 deletions spec/libraries/forms/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@
end
end

let(:template) do
double(
"Template",
controller: controller,
label: "<label>",
text_field: "<input>",
content_tag: "<alchemy-datepicker>"
)
end

let(:builder) { described_class.new(object_name, form_object, template, {}) }

describe "#datepicker" do
let(:attribute) { :foo }

let(:template) do
double(
"Template",
controller: controller,
label: "<label>",
text_field: "<input>",
content_tag: "<alchemy-datepicker>"
)
end

subject { builder.datepicker(attribute, options) }

context "with date value" do
Expand Down Expand Up @@ -91,4 +91,32 @@
end
end
end

describe "#richtext" do
let(:attribute) { :foo }

let(:template) do
double(
"Template",
controller: controller,
label: "<label>",
text_area: "<textarea>",
content_tag: "<alchemy-tinymce>"
)
end

subject { builder.richtext(attribute) }

it "uses a alchemy-tinymce" do
expect(template).to receive(:text_area).with(
"Ding",
:foo,
hash_including(
class: [:text, :required]
)
)
expect(template).to receive(:content_tag).with("alchemy-tinymce", "<alchemy-tinymce>")
subject
end
end
end

0 comments on commit 9764055

Please sign in to comment.