Class: Blacklight::Icon
- Inherits:
 - 
      Object
      
        
- Object
 - Blacklight::Icon
 
 
- Defined in:
 - app/models/blacklight/icon.rb
 
Instance Attribute Summary collapse
- 
  
    
      #additional_options  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute additional_options.
 - 
  
    
      #aria_hidden  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute aria_hidden.
 - 
  
    
      #icon_name  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute icon_name.
 - 
  
    
      #label  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute label.
 - 
  
    
      #role  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute role.
 
Instance Method Summary collapse
- #file_source ⇒ String
 - #icon_label ⇒ Object
 - 
  
    
      #initialize(icon_name, classes: '', aria_hidden: false, label: true, role: 'img', additional_options: {})  ⇒ Icon 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Icon.
 - #ng_xml ⇒ Object
 - #options ⇒ Hash
 - #path ⇒ String
 - 
  
    
      #svg  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    
Returns an updated version of the svg source.
 
Constructor Details
#initialize(icon_name, classes: '', aria_hidden: false, label: true, role: 'img', additional_options: {}) ⇒ Icon
Returns a new instance of Icon.
      16 17 18 19 20 21 22 23  | 
    
      # File 'app/models/blacklight/icon.rb', line 16 def initialize(icon_name, classes: '', aria_hidden: false, label: true, role: 'img', additional_options: {}) @icon_name = icon_name @classes = classes @aria_hidden = aria_hidden @label = label @role = role @additional_options = end  | 
  
Instance Attribute Details
#additional_options ⇒ Object (readonly)
Returns the value of attribute additional_options.
      5 6 7  | 
    
      # File 'app/models/blacklight/icon.rb', line 5 def @additional_options end  | 
  
#aria_hidden ⇒ Object (readonly)
Returns the value of attribute aria_hidden.
      5 6 7  | 
    
      # File 'app/models/blacklight/icon.rb', line 5 def aria_hidden @aria_hidden end  | 
  
#icon_name ⇒ Object (readonly)
Returns the value of attribute icon_name.
      5 6 7  | 
    
      # File 'app/models/blacklight/icon.rb', line 5 def icon_name @icon_name end  | 
  
#label ⇒ Object (readonly)
Returns the value of attribute label.
      5 6 7  | 
    
      # File 'app/models/blacklight/icon.rb', line 5 def label @label end  | 
  
#role ⇒ Object (readonly)
Returns the value of attribute role.
      5 6 7  | 
    
      # File 'app/models/blacklight/icon.rb', line 5 def role @role end  | 
  
Instance Method Details
#file_source ⇒ String
      57 58 59 60 61 62 63 64  | 
    
      # File 'app/models/blacklight/icon.rb', line 57 def file_source raise Blacklight::Exceptions::IconNotFound, "Could not find #{path}" if file.blank? # Handle both Sprockets::Asset and Propshaft::Asset data = file.respond_to?(:source) ? file.source : file.path.read data.force_encoding('UTF-8') end  | 
  
#icon_label ⇒ Object
      36 37 38  | 
    
      # File 'app/models/blacklight/icon.rb', line 36 def icon_label I18n.t("blacklight.icon.#{icon_name_context}", default: icon_name.to_s.titleize) end  | 
  
#ng_xml ⇒ Object
      66 67 68  | 
    
      # File 'app/models/blacklight/icon.rb', line 66 def ng_xml @ng_xml ||= Nokogiri::XML(file_source).remove_namespaces! end  | 
  
#options ⇒ Hash
      42 43 44 45 46 47  | 
    
      # File 'app/models/blacklight/icon.rb', line 42 def { class: classes, 'aria-hidden': (true if aria_hidden) } end  | 
  
#path ⇒ String
      51 52 53  | 
    
      # File 'app/models/blacklight/icon.rb', line 51 def path "blacklight/#{icon_name}.svg" end  | 
  
#svg ⇒ String
Returns an updated version of the svg source
      28 29 30 31 32 33 34  | 
    
      # File 'app/models/blacklight/icon.rb', line 28 def svg svg = ng_xml.at_xpath('svg') svg['aria-label'] = icon_label if label svg['role'] = role svg.prepend_child("<title>#{icon_label}</title>") if label ng_xml.to_xml end  |