File: charmap.rb

package info (click to toggle)
ruby-entypo-rails 2.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 844 kB
  • ctags: 38
  • sloc: ruby: 93; makefile: 2
file content (46 lines) | stat: -rw-r--r-- 1,092 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
module Entypo

  # The Charmap simply "parses" a CSS file which must conform to the following format:
  #
  # .icon$NAME$:before { content: ...} /* $codepoint$ */
  #
  class Charmap

    Icon = Struct.new(:klass, :codepoint) do
      def <=>(other)
        klass <=> other.klass
      end
    end

    # Public: Access the shared instance based on our default entypo.css.scss file.
    #
    # Returns Charmap instance.
    def self.instance
      @@instance ||= self.new File.expand_path('/usr/share/ruby-entypo-rails/app/assets/stylesheets/entypo.css.scss.erb', __FILE__)
    end

    # Public: Returns Array of icons.
    #
    # Returns Array of Icon instances.
    def self.icons
      instance.icons
    end

    # Access the icons array.
    attr_reader :icons

    def initialize(path)
      @icons = load(path)
    end

    private

    def load(path)
      ERB.new(File.read(path)).result.split("\n").map do |line|
        if line =~ %r{\A\.(#{Entypo.css_prefix}-[a-z0-9\-]+):before.*/\* ([0-9a-f]+)}
          Icon.new($1, $2)
        end
      end.compact.sort
    end
  end
end