如何将 Zurb Foundation 实施到 Rails 7?

发布于 2025-01-10 12:58:10 字数 429 浏览 3 评论 0原文

我目前正在将 Rails 应用程序升级到 7。我只是测试了一段时间,然后我在 上遇到了问题基础导轨。我安装了它并遵循了除

将 Foundation 添加到您的 JS

似乎 Rails 7 的指令尚未更新。

因此,CSS 似乎工作正常,但是当尝试实现需要 javascript 的功能时,例如 显示,它将无法正常工作。

知道如何正确实施 Foundation to Rails 7 吗?

I'm currently upgrading my rails app to 7. I was just testing it for a while then I have issues on Foundation Rails. I installed it and followed all the steps except the

Add Foundation to your JS

It seems the instruction is not updated yet for rails 7.

As a result, the CSS seems to work alright but when trying to implement features that require javascript like Reveal, it won't work properly.

Any idea how to implement Foundation to Rails 7 properly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

吃→可爱长大的 2025-01-17 12:58:10

它死了,吉姆。

与几乎所有“宝石化资产”一样,foundation-rails gem 是为旧的 Sprockets 资产管道制作的,这是 Rails 5 中的默认设置,并且在现代版本的 Rails 中没有维护或相关。

在 Sprockets 最初引入时,将第三方 JavaScript 或 CSS 包包装在 Ruby gems 中的整个想法被认为是可接受的解决方案,但由于它依赖于维护人员更新 gems 只是为了推送新版本的前端包,所以它并没有过时。

Sprockets 本身的开发也已停止,甚至可能无法编译 Foundation 的现代版本(如果它使用较新的功能,例如仅在 Dart-Sass 中可用的模块系统)。

Rails 6 用基于 Node.js 的短命 Webpacker 取代了 Spockets。 Rails 6 还默认使用 Yarn 从 NPM 安装前端包。

Rails 7 采用了一种非常不同的方法:

因此,在 Rails 7 中,我们同时提供了一种出色的默认方法,以避免处理整个节点/npm/捆绑设置,并提供完全支持的替代路线,涵盖所有这些内容。但我们将以与以前不同的方式来做这件事。

Webpacker 诞生于大约五年前,其使命是让那些不一定有兴趣成为 JavaScript 专家的 Rails 开发人员能够轻松使用 JavaScript 捆绑管道。当时 ES6 需要转译才能在浏览器中广泛使用,而 npm 需要访问 Node 的包生态系统,因此确实没有办法解决这个问题。我们要么接受这个现实,要么将 Rails 仅仅作为此类应用程序的 API。我们选择了拥抱。

但如今,为 Webpacker 所做的权衡开始变得不那么有意义了。它有点卡在两条更清晰的道路之间的泥泞中间。有一种完全放弃捆绑管道的新路径,它更容易设置,依赖性更少,并且 Ruby 和 JavaScript 之间的分工也更少。然后是 all-in 路径,我们根本不尝试隐藏或包装 JavaScript 复杂性。我们只是提供一个桥梁,通过该桥梁可以在 Rails 应用程序中使用生成的 JavaScript,但将其留给 JavaScript 生态系统来提供所有答案。

-

Rails 7 并未提供有关如何管理前端包的单一答案。

相反,它只是具有连接各种系统的管道,您需要找到适合您要求的系统,例如通过 import-maps 链接到 CDN,jsbundling-rails 或(不寒而栗)下载基础并通过 Scout 之类的东西编译它。

就开发人员的便利性而言,这与 Rails 5 天“刚刚工作”(某种程度上)相比是一个巨大的倒退,但这种方法不再站得住脚。

It's dead, Jim.

The foundation-rails gem like almost all "gemmified assets" is made for the old Sprockets assets pipleline that was the default in Rails 5 and its not maintained or relevant in modern versions of Rails.

The whole idea of wrapping third party JavaScript or CSS packages in Ruby gems was a considered an accepatble solution back when Sprockets was originally introduced but has not aged well as its dependent on maintainers updating gems just to push new versions of the front-end package.

Development on Sprockets itself has also stopped and it may not even be able to compile modern versions of Foundation if it uses newer features like the module system thats only available in Dart-Sass.

Rails 6 replaced Spockets with the short-lived Node.js based Webpacker. Rails 6 also defaulted to using Yarn to install front end packages from NPM.

Rails 7 takes a very different approach:

So in Rails 7, we're simultaneously offering a great, default way to avoid dealing with the entire node/npm/bundling setup and offering a fully-supported alternate route that embraces all of those things. But we're going to do it in a different way than before.

Webpacker was born almost five years ago with a mission to make the JavaScript bundling pipeline easy to use for Rails developers who weren't necessarily interested in becoming JavaScript experts. With ES6 requiring transpilation for widespread use in browsers at the time, and npm needed to access the ecosystem of packages for node, there really wasn't a way around it. We could either embrace that reality or relegate Rails to only being an API for such applications. We chose the embrace.

But today the trade-offs made for Webpacker are starting to make a lot less sense. It's sorta stuck in the muddy middle between two clearer paths. There's the new path of forgoing the bundling pipeline altogether, which is much easier to setup, has fewer dependencies, and less awkward divisions of labor between Ruby and JavaScript. And then there's the all-in path where we don't try to hide or wrap the JavaScript complexities at all. We simply provide a bridge by which the generated JavaScript can be used in the Rails application, but leave it to the JavaScript ecosystem to provide all the answers.

- David Heinemeier Hansson

Rails 7 isn't shipping with a single answer to how to manage front-end packages.

Instead it just has the plumbing to hook up a variety of systems and you need to find the system that works for your requirements such as linking to CDN's via import-maps, jsbundling-rails or (shudder) downloading foundation and compliling it via something like Scout.

In terms of developer convience is it a huge step back from the Rails 5 days when it "just worked" (kind of) but that approach was no longer tenable.

痴梦一场 2025-01-17 12:58:10

我找到了一种让它工作的方法

我没有找到的是在 scss 中通过 importmap 添加基础样式表的正确方法。我只是将它们全部粘贴到资产中并炸毁了我的存储库。但目前还有效。

jQuery

执行 ./bin/importmap pin jquery --download 查看其他选项

添加到 application.js

import jquery from 'jquery'
window.$ = jquery

样式表

  1. 下载在这里手动
  2. 创建文件夹app/assets/stylesheets/foundation
  3. 将文件夹_vendorscss拖到新文件夹中
  4. 添加@import "./foundation/scss/foundation";@include Foundation-everything();application.scss
  5. 我删除了 * = require_tree .*= require_self

Javascript

  1. 执行 ./bin/importmap pin Foundation-sites --download

然后添加到 application.js

import 'foundation-sites'

// initialize the page
$(document).on('turbo:render', function() {
    onPageLoad();
});
$(document).ready(function () {
    onPageLoad();
});
function onPageLoad() {
    // init foundation
    $(document).foundation();
}

i found a way to get it working

what i not found is the correct way for adding the foundation stylesheets, in scss, by importmap. i just pasted them all into the assets and blowed up my repository. But it works for now.

jQuery

execute ./bin/importmap pin jquery --download see other options

add to application.js

import jquery from 'jquery'
window.$ = jquery

Stylesheets

  1. Download it manually here
  2. create folder app/assets/stylesheets/foundation
  3. drag the folders _vendor and scss into the new folder
  4. add @import "./foundation/scss/foundation"; and @include foundation-everything(); to application.scss
  5. i removed *= require_tree . and *= require_self

Javascript

  1. execute ./bin/importmap pin foundation-sites --download

then add to application.js

import 'foundation-sites'

// initialize the page
$(document).on('turbo:render', function() {
    onPageLoad();
});
$(document).ready(function () {
    onPageLoad();
});
function onPageLoad() {
    // init foundation
    $(document).foundation();
}
谈下烟灰 2025-01-17 12:58:10

我走了另一条路

我喜欢粉底,我找到了Vite。
太棒了,它可以与新的 Turbo 配合使用。
最棒的是Vite HMR。

关于如何建立基金会和所有员工,我写了一篇教程
设置 Vite、Svelte ,惯性,刺激,Bootstrap /基础

I've gone another way

I like foundation and i found Vite.
So great and it works together with the new Turbo.
Greatest thing is the Vite HMR.

For how to setup foundation and all that staff together i wrote a tuorial
Setup Vite, Svelte, Inertia, Stimulus, Bootstrap / Foundation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文