comfy / comfortable-mexican-sofa

ComfortableMexicanSofa is a powerful Ruby on Rails 5.2+ CMS (Content Management System) Engine
MIT License
2.73k stars 639 forks source link

Compatibility with Bootstrap 3 in main_app #777

Closed glebm closed 6 years ago

glebm commented 6 years ago

If the main app uses Bootstrap 3 via bootstrap-sass, Sprockets asset paths will conflict with Bootstrap 4 used by this gem.

One way to solve this would be to use absolute paths to the Bootstrap assets:

  1. Remove require 'bootstrap' from https://github.com/comfy/comfortable-mexican-sofa/blob/d80f9e5fb612348ebbcfa7897d6f807741ff17ad/lib/comfortable_mexican_sofa/engine.rb#L14

  2. Use the absolute path in application.sass.erb:

    // Import bootstrap via an absolute path, allowing main_app to use Bootstrap 3.
    // See https://github.com/comfy/comfortable-mexican-sofa/issues/777.
    @import "<%= File.join(Gem::Specification.find_by_name('bootstrap').gem_dir,
                          'assets', 'stylesheets', 'bootstrap') %>"
  3. Use the absolute path in application.js.coffee.erb:

    // Load bootstrap.js via an absolute path, allowing main_app to use Bootstrap 3.
    // See https://github.com/comfy/comfortable-mexican-sofa/issues/777.
    <%= File.read File.join(Gem::Specification.find_by_name('bootstrap').gem_dir,
                           'assets', 'javascripts', 'bootstrap.js') %>

Because Bootstrap 3 and Bootstrap 4 are different gems (bootstrap-sass and bootstrap respectively), there is no dependency conflict, and the main app will be able to use Bootstrap 3 while the CMS will use Bootstrap 4.

GBH commented 6 years ago

Instead of doing the hacky thing to have bootstrap3 and 4 in the same app, what about vendoring raw css/js into assets and removing bootstrap gem dependency? With glyphicons gone it's pretty easy. Thoughts?

glebm commented 6 years ago

That also solves the problem as long as we vendor it under a different path, e.g. comfy-bootstrap or bootstrap4, at the cost of making Bootstrap version updates here slightly more involved (e.g. with regards to Bootstrap popper.js dependency). Let me know if you prefer it and I'll send another PR.

Do you want popper.js vendored as well?

GBH commented 6 years ago

I vendored Redactor and FontAwesome5 (as there's no gem for it yet) so I think it's fine. https://github.com/comfy/comfortable-mexican-sofa/tree/master/app/assets/stylesheets/comfy/admin/cms/lib

I really hate relying on ruby gems that do nothing but package js/css assets. plupload-rails and codemirror-rails haven't been updated in ages. So I'm also thinking about just vendoring those too.

Rails still doesn't have good mechanism for dealing with asset dependencies like that.

glebm commented 6 years ago

Rails does support Yarn and Webpack now but I don't know whether it works for gems / engines.

GBH commented 6 years ago

There's some discussion there: https://github.com/rails/webpacker/issues/348 But I don't think we're going to see anything that makes sense until Rails 6 or something.