administrate icon indicating copy to clipboard operation
administrate copied to clipboard

Add Field::RichText

Open sedubois opened this issue 4 years ago • 1 comments

This is required for models with ActionText has_rich_text. I thought it would be good to have this in Administrate itself as it's a core Rails feature and it's so small it's maybe not something for a separate gem?

sedubois avatar May 29 '20 15:05 sedubois

I don't have a good rule on what should be in Administrate and what shouldn't be as it comes to field plugins. I've generally felt like it should cover the basic data types and push you to pull in others from other gems, but that perhaps is and has been a bit arbitrary based on what I consider a basic data type.

Anyway, I guess this is needed and like you say, it is small.

Can you add a some tests for using the field?

nickcharlton avatar May 29 '20 17:05 nickcharlton

Closed due to lack of activity.

pablobm avatar Apr 18 '23 09:04 pablobm

I think this was helpful to have @pablobm. Can we add it to https://github.com/thoughtbot/administrate/issues/2360 ?

kaka-ruto avatar Apr 26 '23 23:04 kaka-ruto

I think this is different from that epic, which is about the general visual design and layout of Administrate, so I wouldn't put it there.

However if you think this is something you think you can pick up, rebase, and add a spec, I would be happy to review it.

pablobm avatar Apr 27 '23 09:04 pablobm

I'm going to see if I can finish up this PR.

littleforest avatar Apr 28 '23 20:04 littleforest

I'm trying to write a spec for Administrate::Field::RichText, and within it trying to create a RichText object that I can pass: action_text = ::ActionText::RichText.new(body: "<trix><p>Foo</p></trix>"), but I get uninitialized constant ActionText::RichText. I have tried to add require "action_text/engine", require "action_text" (among many other library attempts), but nothing works. Anyone have any ideas?

littleforest avatar Apr 28 '23 21:04 littleforest

@littleforest thanks for taking this up! I don't think Administrate has defined any ActionText::RichText class anywhere, so unless you have the class somewhere, calling it will not work, you will want to create that class if it is needed. require "action_text" won't work as well as Adminstrate doesn't know what that is or where to get it from

kaka-ruto avatar Apr 30 '23 00:04 kaka-ruto

@littleforest - I just had a look. With no requires, it'll complain about lack of ActionText indeed. If you add require "action_text" then it will complain about ActionText::RichText which indeed I don't think exists. Perhaps you means ActionText::Content?

I got the following to run on that branch. Is this helpful?

require "rails_helper" # action_text requires activesupport. Easier to just load everything
require "administrate/field/rich_text"
require "action_text"

describe Administrate::Field::RichText do
  it "does stuff" do
    action_text = ::ActionText::Content.new("<trix><p>Foo</p></trix>")
  end
end

pablobm avatar May 12 '23 15:05 pablobm

@pablobm thanks for your thoughts on this! I got it to work by putting require "action_text/engine" in lib/administrate/engine.rb.

littleforest avatar May 12 '23 15:05 littleforest