Rails에서 bootstrap-ins를 간단히 사용

2616 단어 bootstrap-iconsRails

rails에서bootstrap-ins를 사용하는 방법


현재v1.0.0-alpha5는 최신이고 앞으로는 달라질 것이다.
npmnpm install bootstrap-iconsyarnyarn add bootstrap-icons다음은 app/helpers/application_helper.rb에 다음과 같은 내용을 보충한다.
module ApplicationHelper
  ...
  # 追加
  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

뷰는 슬림이니까.
=icon("hdd", class: "text-gray")
를 참고하십시오.

좋은 웹페이지 즐겨찾기