zooppa / administrate-field-simple_markdown Goto Github PK
View Code? Open in Web Editor NEW✍️ A plugin to edit Markdown text in Administrate
Home Page: https://github.com/thoughtbot/administrate
License: MIT License
✍️ A plugin to edit Markdown text in Administrate
Home Page: https://github.com/thoughtbot/administrate
License: MIT License
Since using this gem, several instances of my NestedHasMany nested resources get created whenever clicking "Add Program/Translation".
See illustration before clicking (I removed the fields in the nested resource for conciseness):
And after clicking:
The number of duplicate boxes corresponds to the number of page navigations that have been performed by Turbolinks since the last full page load. E.g if I visit 2 other pages using my side navigation, then visit the Programs index, then click "New Program", then click "Add Program/Translation", then there will be 4 instances of the nested resource.
When commenting out turbolinks.start()
in Javascript, the issue disappears.
NB: the issue is completely unrelated to whether there are actual Field::SimpleMarkdown
used in dashboards. Just having the gem in the gemfile (and thus its Javascript loaded in the asset pipeline) is enough to get the issue.
It makes for a poor admin experience, but more importantly it also breaks the tests. Is there any way to make this gem work with Turbolinks?
Using administrate-field-simple_markdown 0.3.0, administrate-field-nested_has_many 1.2.0@bbc3cb777b.
Hey @michelegera
Wanted to share this issue:
Some of my description
data is nil
. SimpleMarkdown fails to render the data.
Workaround: Change to empty string.
wrong argument type nil (expected String)
# /gems/administrate-0.8.1/app/views/administrate/application/show.html.erb
def to_html
markdown(html_renderer).render(data).html_safe
end
# Framework trace
administrate-field-simple_markdown (0.0.4) lib/administrate/field/simple_markdown.rb:14:in `render'
administrate-field-simple_markdown (0.0.4) lib/administrate/field/simple_markdown.rb:14:in `to_html'
administrate-field-simple_markdown (0.0.4) app/views/fields/simple_markdown/_show.html.erb:12:in
Hi, I had to add require 'redcarpet'
to my config/application.rb
, or else I got an error on server boot: ~/.rvm/gems/ruby-2.4.0/gems/redcarpet-3.4.0/lib/redcarpet/render_strip.rb:5:in '<module:Render>': uninitialized constant Redcarpet::Render::Base (NameError)
Any ideas to what's going on? Thanks.
Thanks a lot for making this plugin. I've given it a quick try by adding the gem to my gemfile and putting about: Field::SimpleMarkdown
in my resource's ATTRIBUTE_TYPES
. However the Javascript/CSS doesn't seem to load: when loading the edit view, the textarea doesn't display any markdown buttons and the text is plain.
NB: Looking at the page source, the textarea's parent div has class="field-unit__field simple_markdown"
which I guess is a good sign. I am using Rails 6.0.2.1, administrate 0.12.0, administrate-field-simple_markdown 0.2.1.
What should I do to ensure the Javascript/CSS get loaded?
I guess that it should be possible to instead use Rails' ActionText feature but I haven't gotten to that yet and wanted to try this in the interim.
Hello, thank you for the useful plugin, it works pretty well.
I would like to custimize the toolbar hidding some buttons/icons, for example: 'image upload'. I've checked the documentation of SimpleMDE and it seems to be that it can be done via an attribute in the editor initialization.
new SimpleMDE(
{
element: el,
hideIcons: ["guide", "heading"]
}
);
Is there any way to achieve this with this plugin? I did try to change my manifest.js
to pass hideIcons
to the editor but Sprockets throws an exception
// link administrate-field-simple_markdown/application.js
document.addEventListener('DOMContentLoaded', setup);
document.addEventListener('turbolinks:load', setup);
function setup() {
initSimpleMDE(document);
initObserver(document.querySelector('.field-unit--nested'));
}
function initObserver(element) {
if (!element) return;
const observer = new MutationObserver(function (mutations) {
for (let mutation of mutations) {
if (mutation.addedNodes.length) {
mutation.addedNodes.forEach(function(node) {
initSimpleMDE(node);
});
}
}
});
function initSimpleMDE(element) {
if (!element) return;
element.querySelectorAll('[data-simplemde="false"]').forEach(function(el) {
new SimpleMDE({ element: el, hideIcons: ["guide", "heading"] }); // My change
el.setAttribute('data-simplemde', true);
});
}
observer.observe(element, { childList: true });
}
Thanks!
I think you'd preferably use https://github.com/sparksuite/simplemde-markdown-editor
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.