HTML5 Boilerplate 对于 Rails 应用程序有什么价值?

发布于 2024-12-13 02:59:00 字数 835 浏览 1 评论 0原文

有多个应用程序模板(和 Rails gem)可以将 HTML5 Boilerplate 添加到 Rails 应用程序中。因此,我调查并整理了HTML5 Boilerplate for Rails<的分析/强>。看来 HTML5 Boilerplate 并没有添加太多新 Rails 应用程序中尚未存在的内容。有什么用:

示例 human.txt 文件

默认应用程序布局的示例index.html 文件

视口元标记

Google Analytics 代码片段

有一些 CSS 帮助,例如 CSS 规范化、占位符 CSS 媒体查询和 CSS 帮助器类,但似乎您可以通过以下方式获得所有这些内容以及更多内容CSS 工具包,例如 Skeleton、Twitter Bootstrap 或 Zurb Foundation。

最后,HTML5 Boilerplate 为需要支持 IE6、7 和 8 的网站提供了大量组件,例如 IE 条件注释、Modernizr 和 Chrome Frame。但如果我不支持 IE6 并且我使用 Twitter Bootstrap 或 Zurb Foundation,我认为我不需要这些。

HTML5 Boilerplate 是一个很好的项目,有很多社区的意见。其网站上有很多好的建议。但是对于 Rails 项目呢?

我错过了什么吗? HTML5 Boilerplate 对于 Rails 应用程序有什么价值?

There are several application templates (and a Rails gem) that add HTML5 Boilerplate to a Rails application. So I investigated and put together an analysis of HTML5 Boilerplate for Rails. It seems HTML5 Boilerplate doesn't add much that isn't already there in a new Rails app. What's useful:

sample humans.txt file

example index.html file for a default application layout

viewport metatag

Google Analytics snippet

There's some CSS help like CSS normalization, placeholder CSS Media Queries, and CSS helper classes but it seems you'd get all of them and more with a CSS toolkit such as Skeleton, Twitter Bootstrap or Zurb Foundation.

Finally, HTML5 Boilerplate has lots of components for websites that need to support IE6, 7, and 8 such as IE conditional comments, Modernizr, and Chrome Frame. But if I'm not supporting IE6 and I'm using Twitter Bootstrap or Zurb Foundation I don't think I need these.

HTML5 Boilerplate is a good project that has lots of community input. There's a lot of good advice on its website. But for a Rails project?

Am I missing something? What is the value of HTML5 Boilerplate for a Rails application?

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

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

发布评论

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

评论(1

盛夏尉蓝 2024-12-20 02:59:00

HTML5 Boilerplate 有一些不同的功能,通常是从其他项目借用的。

  • 用于设置超时、打开 sendfile、gzipping、服务器过期等的服务器配置文件。我相信他们的存储库针对一些不同的服务器(apache、nginx、node、lighttpd)有这些文件的几个不同版本。您可以在这里找到这些配置文件:https://github.com/h5bp/server-configs 。据我了解,Rails 没有任何类型的等效项。

  • 它还附带了 Modernizr 的自定义构建,可检查浏览器中的 HTML5 和 CSS3 功能,然后将类添加到您的 标记中,以便您可以在样式表或JavaScript。如果浏览器不支持您尝试使用的功能,这允许您以后备样式或交互为目标浏览器。 CSS 的一个例子可能是像 border-image 这样的东西,它没有得到广泛的支持。您可以将 border-image: 应用于可以使用它的浏览器,而对于其他浏览器,您可以使用 HTML5Boilerplate 提供的类 (html.no-borderimage) 来提供备份样式。您还可以从 JavaScript 中检查这些类,以确保您没有使用浏览器不需要(或无法响应)的代码来定位浏览器。 Rails 内部没有任何可以立即执行此操作的内容。

  • Respond.js 还与 Modernizr 打包在一起,它为您在尚不支持媒体查询的浏览器中提供媒体查询支持。您提到您的目标不是 IE6,而是 IE7 和 IE7。 IE8 不支持媒体查询(很多移动浏览器也不支持),而 Respond.js 将为您提供该支持。 Rails 也没有内置任何东西来处理这个问题。

  • Modernizr 依赖 yepnope.js 加载外部资源,以便您也可以使用。该库允许您测试功能并根据测试结果加载某些脚本/样式。如果您引入只有某些浏览器需要的文件,这会很有帮助。 Rails 不会这样做。

  • 修复了 PNG 问题。如果您不支持 IE6,您可能不需要这个,但它确实包含一些针对旧版浏览器的 png 修复(咳嗽 IE6)。 Rails 本身并不能真正在前端处理此类事情。

最终,您可以获取所需的部分并将它们引入您的应用程序,而无需引入整个 HTML5 样板(当然,这也是我通常所做的)。也就是说,您的问题是“HTML5 Boilerplate 为 Rails 应用程序带来什么价值?”答案是“很多”,具体取决于这些工具是否对您正在做的事情有用。 HTML5 Boilerplate 不一定以任何方式与 Rails 重叠。

可以在 HTML5 Boilerplate 文档 中获取完整的功能列表和编码风格建议。

您 也可能对 面向 Rails 开发人员的 HTML5 Boilerplate 感兴趣

HTML5 Boilerplate has a few different features, typically borrowed from other projects.

  • A server config file for setting timeouts, turning sendfile on, gzipping, server expiration, etc. I believe their repo has a few different versions of these files for a few different servers (apache, nginx, node, lighttpd). You can find those config files here: https://github.com/h5bp/server-configs. From my understanding Rails doesn't have any type of equivalent for this.

  • It also comes with a custom build of Modernizr that checks for HTML5 and CSS3 features within the browser and then adds classes to your <html> tag so that you can utilize them within your stylesheets or javascripts. This allows you to target browsers with a fallback style or interaction if it didn't support the feature you were trying to use. One example for CSS may be something like border-image which doesn't have widespread support. You could apply border-image: for the browsers that can use it and for the others you would use the class that HTML5Boilerplate provides (html.no-borderimage) to provide a backup style. You could also check for these classes from your JavaScript to be sure you weren't targeting browsers with code they didn't need (or couldn't respond to). Rails doesn't have anything internally that would do this out of the box.

  • Respond.js is also packaged with Modernizr which gives you media queries support in browsers that don't already have it. You mentioned you weren't targeting IE6 but IE7 & IE8 don't support Media Queries (nor do a good amount of mobile browsers) and Respond.js would give you that support. Rails also doesn't have anything built in to handle this.

  • Modernizr relies on yepnope.js to load externals so that would be available to you as well. This library allows you to test for features and load certain scripts/styles based on the result of that test. This is helpful if you are bringing in files that only some browsers need. Rails doesn't do this.

  • PNG fixes. You probably don't need this if you aren't supporting IE6 but it does come packaged with some png fixes for legacy browsers (cough IE6). Rails doesn't really handle this type of thing on the front end on it's own.

Ultimately you could grab the pieces that you need and bring them into your application without bringing in the entire HTML5 Boilerplate (and fwiw, that's what I typically do as well). That said, your question is "what value does HTML5 Boilerplate bring to a Rails application?" and the answer is "a lot", depending on if these tools are useful based on what you are doing. HTML5 Boilerplate doesn't necessarily overlap Rails in any way.

You can get a full list of features, coding style recommendations at the HTML5 Boilerplate Docs

You'll also probably be interested in HTML5 Boilerplate for Rails Developers

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