Giter VIP home page Giter VIP logo

Comments (5)

chriskrams avatar chriskrams commented on May 12, 2024 4

Thanks a lot. Your answer helped me getting back on the road.

For others getting in my position:
I put all the icons on a folder "app/assets/icons" and wrote a little helper:

def icon(icon, options = {})
file = File.read("app/assets/icons/#{icon}.svg")
doc = Nokogiri::HTML::DocumentFragment.parse file
svg = doc.at_css 'svg'
if options[:class].present?
svg['class'] += " " + options[:class]
end
doc.to_html.html_safe
end

In my view I call the icon with:
<%= icon("alert-circle", class: "text-success") %>

from icons.

mdo avatar mdo commented on May 12, 2024 2

Sorry, but we cannot help with how-to or general troubleshooting issues here; only bug reports and feature requests. You'll want to ask around in the official Slack team or Stack Overflow for this kind of thing.

I will say that there's no need to adjust CSS or JS to make these icons work. You'll want to drop them in an assets pipeline of some kind and include them via image tag or embedded HTML.

from icons.

MtnBiker avatar MtnBiker commented on May 12, 2024 2

I ran yarn add bootstrap-icons then following @chriskrams but changing the second line to file = File.read("node_modules/bootstrap-icons/icons/#{icon}.svg") which is where yarn installs the icons. For those with less experience that I, I put the code in app/helpers/<model name>.helper.rb in module <model name>Helper which had already been created.

In the interest of completeness

#app/helpers/people.helper.rb
module PeopleHelper
  def icon(icon, options = {})
    file = File.read("node_modules/bootstrap-icons/icons/#{icon}.svg")
    doc = Nokogiri::HTML::DocumentFragment.parse file
    svg = doc.at_css 'svg'
    if options[:class].present?
      svg['class'] += " " + options[:class]
    end
      doc.to_html.html_safe
  end
end

I had tried imports and includes in application.js and application.scss before finding this post.

Thanks @chriskrams your little helper was a big help. (Couldn't resist. Social distancing stress.)

PS I think this could go on the https://icons.getbootstrap.com.

from icons.

marcelolx avatar marcelolx commented on May 12, 2024 1

@chriskrams @MtnBiker I've created a helper for handling with this in rails https://github.com/marcelolx/bootstrap-icons.

Only what you need to do is add bootstrap-icons-helper to your Gemfile and call something like this <%= bootstrap_icon "check", width: 5, height: 5, fill: "blue" %> on your views.

from icons.

rgarifullin avatar rgarifullin commented on May 12, 2024

This worked for me

Add bootstrap-icons to package.json:
$ yarn add bootstrap-icons

// application.scss:
@import "bootstrap-icons/font/bootstrap-icons";
@font-face {
  font-family: "bootstrap-icons";
  src:  url("bootstrap-icons/font/fonts/bootstrap-icons.woff2") format("woff2"),
        url("bootstrap-icons/font/fonts/bootstrap-icons.woff") format("woff");
}
<!-- finally your views: -->
<i class="bi-bookmark-plus" />

from icons.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.