GithubHelp home page GithubHelp logo

zooppa / administrate-field-simple_markdown Goto Github PK

View Code? Open in Web Editor NEW
8.0 1.0 12.0 940 KB

✍️ A plugin to edit Markdown text in Administrate

Home Page: https://github.com/thoughtbot/administrate

License: MIT License

Ruby 82.00% JavaScript 0.27% CSS 3.40% HTML 14.32%
simplemde administrate rails ruby unmaintained

administrate-field-simple_markdown's People

Contributors

casaper avatar dependabot-preview[bot] avatar dependabot[bot] avatar golmansax avatar michelegera avatar neumayr avatar parterburn avatar pedantic-git avatar sedubois avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

administrate-field-simple_markdown's Issues

Many duplicate NestedHasMany elements get created when using Turbolinks

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):

Screenshot 2020-04-24 at 11 57 51

And after clicking:

Screenshot 2020-04-24 at 12 08 55

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.

wrong argument type nil (expected String)

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 

Needed to require 'redcarpet'?

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.

Javascript/CSS doesn't load?

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.

Screenshot 2020-02-19 at 13 53 34

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.

Customize toolbar buttons

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 });
}

Screenshot 2020-03-18 at 19 44 31

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.