Integrate LESS version of Bootstrap-Material-Design to Rails Project

折月煮酒 提交于 2019-12-04 23:01:34

First install Rails, see: http://guides.rubyonrails.org/getting_started.html. Then you can create a new Rails app by running the following command in your console:

>> rails new material

The above command will create a new material directory, navigate to this directory (>> cd material). Now open the Gemfile and remove the Sass bundle and at the Less bundle(s):

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

Then run bundle install again. Now navigate to your public directory (>> cd public) and run the following command:

>> bower install bootstrap-material-design

Now you can create a controller called "welcome" with an action called "index", by running the following command:

>> bin/rails generate controller welcome index

The preceding command create among others the app/views/welcome/index.html.erb file. Open the app/views/welcome/index.html.erb file and write out the content like that shown beneath into it (according https://github.com/FezVrasta/bootstrap-material-design/blob/master/dist/test.html):

<!-- Your site -->
<h1>You can add your site here.</h1>
<h2>To ensure that material-design theme is working, check out the buttons below.</h2>
<h3 class="text-muted">If you can see the ripple effect on clicking them, then you are good to go!</h3>
<p class="bs-component">
<a href="javascript:void(0)" class="btn btn-default">Default</a>
<a href="javascript:void(0)" class="btn btn-primary">Primary</a>
<a href="javascript:void(0)" class="btn btn-success">Success</a>
<a href="javascript:void(0)" class="btn btn-info">Info</a>
<a href="javascript:void(0)" class="btn btn-warning">Warning</a>
<a href="javascript:void(0)" class="btn btn-danger">Danger</a>
<a href="javascript:void(0)" class="btn btn-link">Link</a>
</p>
<!-- Your site ends -->

And after that make sure that the content of the ./app/views/layouts/application.html.erb file look like that shown beneath:

<!DOCTYPE html>
<html>
<head>
  <title>Material</title>
  <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">

  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  <%= csrf_meta_tags %>
</head>
<body>

<%= yield %>


<!-- Your site ends -->
<script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<script src="/bower_components/bootstrap-material-design/dist/js/ripples.min.js"></script>
<script src="/bower_components/bootstrap-material-design/dist/js/material.min.js"></script>
<script>
$(document).ready(function() {
// This command is used to initialize some elements and make them work properly
$.material.init();
});
</script>


</body>
</html>

Finally rename app/assets/stylesheets/application.css to app/assets/stylesheets/application.css.less and write down the following content into it:

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

Now you can run >> bin/rails server and open http://localhost:3000/welcome/index in your browser. The result now should look like that shown in the figure beneath:

Sawo Cliff

If you intend to use this gem by Aufree, then it actually is quite simple following the documentation.

Add the gem to your gem file and also add less rails

gem 'less-rails' 

gem 'bootstrap-material-design'

Then bundle.

Now, go to your application.js file and add

//= require bootstrap-material-design

and then proceed to the application.css file and add

*= require bootstrap-material-design

after that restart your server. Should be good to go

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!