class Octicons::Octicon
def a11y
def a11y accessible = {} if @options[:"aria-label"].nil? && @options["aria-label"].nil? accessible[:"aria-hidden"] = "true" else accessible[:role] = "img" end accessible end
def calculate_height(width)
def calculate_height(width) (width.to_i * @height) / @width end
def calculate_width(height)
def calculate_width(height) (height.to_i * @width) / @height end
def classes
def classes "octicon octicon-#{@symbol} #{@options[:class]} ".strip end
def html_attributes
def html_attributes attrs = "" @options.each { |attr, value| attrs += "#{attr}=\"#{value}\" " } attrs.strip end
def initialize(symbol, options = {})
def initialize(symbol, options = {}) @symbol = symbol.to_s if octicon = Octicons::OCTICON_SYMBOLS[@symbol] @path = octicon["path"] @width = octicon["width"].to_i @height = octicon["height"].to_i @keywords = octicon["keywords"] @options = options @options.merge!({ class: classes, viewBox: viewbox, version: "1.1" }) @options.merge!(size) @options.merge!(a11y) else raise "Couldn't find octicon symbol for #{@symbol.inspect}" end end
def size
def size size = { width: @width, height: @height } # Specific size unless @options[:width].nil? && @options[:height].nil? size[:width] = @options[:width].nil? ? calculate_width(@options[:height]) : @options[:width] size[:height] = @options[:height].nil? ? calculate_height(@options[:width]) : @options[:height] end size end
def to_svg
def to_svg "<svg #{html_attributes}>#{@path}</svg>" end
def viewbox
def viewbox "0 0 #{@width} #{@height}" end