Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add richtext input type for form builder #2684

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading