0

I'm storing Ruby code in a database so that if an administrator needs to tweak the code logic, they use ActiveAdmin to make edits. My app is written in such a way to load & call this code from the database.

My problem now is that the text rendered in the ActiveAdmin UI show page is not very readable code because it is not monospaced or syntax highlighted. How can I apply syntax highlighting to this particular row?

Would you use the Rouge gem? If so, can you wrap your code or do you need to monkey-patch ActiveAdmin? What other solutions exist?

ActiveAdmin.register Model do
  show do |model|
    attributes_table do
      row :name
      row :logic # render this logic text as Ruby code
      row :created_at
      row :updated_at
    end
  end
end

enter image description here

chemturion
  • 283
  • 2
  • 16

1 Answers1

1

You should be able to use the Arbe syntax to wrap it in a pre or code tag:

ActiveAdmin.register Model do
  show do |model|
    attributes_table do
      row :name
      row :logic, do |logic|
        pre( code(model.logic, class: 'lang-ruby') )
      end
      row :created_at
      row :updated_at
    end
  end
end

You could also use the code tag instead of pre, they're just slightly different. Either way any more serious customization should be done with CSS.

Original Poster's Note: wrap the code block with pre if using highlight.js.

chemturion
  • 283
  • 2
  • 16
sevensidedmarble
  • 643
  • 1
  • 4
  • 14
  • Thank you for this answer. It got me started in the right direction. I will edit it for further clarity. I wish the docs for Arbre and ActiveAdmin had more examples. I ended up source diving and inferred how to wrap the `code` and `pre` tags from this spec: https://github.com/activeadmin/activeadmin/blob/9d91d156d17a905e50b82f2b85ec483598489307/spec/unit/views/components/attributes_table_spec.rb#L127 – chemturion Mar 31 '20 at 19:32
  • Nice, glad I could help. – sevensidedmarble Mar 31 '20 at 20:05