将LESS版本的Bootstrap-Material-Design集成到Rails项目中

我正在使用这个gem bootstrap-material-design ,它是https://github.com/FezVrasta/bootstrap-material-design库的sass版本,但最近我注意到sass版本不再维护了。

问题我面对的这个gem是它不会将按钮和flash消息转换为素材样式。

这里建议的一个解决方案 : https : //github.com/FezVrasta/bootstrap-material-design/issues/535是使用LESS版本,但我不知道如何集成此库的LESS版本。 有人已经这样做了吗?

更新

如果有人想要将Bootstrap-Material-Design添加到他们的网站而不使用任何框架或服务器端语言,如Ruby,PHP等……,只需使用HTML5,CSS3和JS。 他们可以按照以下说明操作:

安装和下载bootstrap-material文件夹

bower install bootstrap-material-design

在head标记下链接bootstrap css和material css minified file

   

链接Javascript文件

      

最后,您必须在身体底部使用此脚本初始化一些材质组件

  $(document).ready(function() { $.material.init(); });  

首先安装Rails,请参阅: http : //guides.rubyonrails.org/getting_started.html 。 然后,您可以通过在控制台中运行以下命令来创建新的Rails应用程序:

 >> rails new material 

上面的命令将创建一个新的material目录,导航到这个目录( >> cd material )。 现在打开Gemfile并删除Sass包并在Less bundle中:

 #gem 'sass-rails', '~> 5.0' gem 'less-rails' # Less gem 'therubyracer' # Ruby 

然后再次运行bundle install 。 现在导航到您的public目录( >> cd public )并运行以下命令:

 >> bower install bootstrap-material-design 

现在,您可以通过运行以下命令,使用名为“index”的操作创建名为“welcome”的控制器:

 >> bin/rails generate controller welcome index 

上面的命令创建了app/views/welcome/index.html.erb文件。 打开app/views/welcome/index.html.erb文件并写出下面显示的内容(根据https://github.com/FezVrasta/bootstrap-material-design/blob/master/dist/test .html ):

  

You can add your site here.

To ensure that material-design theme is working, check out the buttons below.

If you can see the ripple effect on clicking them, then you are good to go!

Default Primary Success Info Warning Danger Link

然后确保./app/views/layouts/application.html.erb文件的内容如下所示:

    Material  <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %>   <%= yield %>         

最后将app/assets/stylesheets/application.css重命名为app/assets/stylesheets/application.css.less并将以下内容写入其中:

 @import "../../../public/bower_components/bootstrap-material-design/less/material-fullpalette.less"; @color: red; h1 { color: @color; } 

现在您可以运行>> bin/rails server并在浏览器中打开http://localhost:3000/welcome/index 。 结果现在应该如下图所示:

在此处输入图像描述

如果您打算使用Aufree的这个gem ,那么在文档之后它实际上非常简单。

将gem添加到gem文件中,并添加更少的rails

 gem 'less-rails' gem 'bootstrap-material-design' 

捆绑。

现在,转到application.js文件并添加

 //= require bootstrap-material-design 

然后继续执行application.css文件并添加

 *= require bootstrap-material-design 

之后重新启动服务器。 应该好好去

Interesting Posts