unignore bower_components
[bootswatch] / bower_components / font-awesome / src / _plugins / site.rb
1 ##
2 # Provide an icons attribute on the site object
3
4 require 'yaml'
5 require 'forwardable'
6
7 module Jekyll
8
9   class Icon
10
11     attr_reader :name, :id, :unicode, :created, :categories
12
13     def initialize(icon_object)
14       @icon_object = icon_object
15
16       # Class name used in CSS and HTML
17       @icon_object['class'] = icon_object['id']
18       # Normalize the aliases
19       @icon_object['aliases'] ||= []
20
21       @name = icon_object['name']
22       @id = icon_object['id']
23       @class = icon_object['class']
24       @aliases = icon_object['aliases']
25       @unicode = icon_object['unicode']
26       @created = icon_object['created']
27       @categories = icon_object['categories']
28     end
29
30     def to_liquid
31       return @icon_object
32     end
33
34   end
35
36   class IconList
37     ##
38     # A list of icons
39     #
40     include Enumerable
41     extend Forwardable
42
43     def_delegators :@icon_array, :each, :<<
44
45     def initialize(icon_array)
46       @original_icon_array = icon_array
47       @icon_array = []
48
49       icon_array.each { |icon_object|
50         @icon_array << Icon.new(icon_object)
51       }
52     end
53
54     def [](k)
55       @icon_array[k]
56     end
57
58     def to_liquid
59       @original_icon_array
60     end
61
62   end
63
64   module IconFilters
65     def expand_aliases(icons)
66       expanded = []
67
68       icons.each { |icon|
69         # Remove the aliases since we are expanding them
70         expanded << icon.reject{ |k| k == 'aliases'}
71
72         icon['aliases'].each { |alias_id|
73           alias_icon = expanded[-1].dup
74           alias_icon['class'] = alias_id
75           alias_icon['alias_of'] = icon
76
77           expanded << alias_icon
78         }
79       }
80
81       return expanded
82     end
83
84     def category(icons, cat)
85       icons.select { |icon| icon['categories'].include?(cat) }
86     end
87
88     def version(icons, version)
89       icons.select { |icon| icon['created'] == version }
90     end
91
92     def sort_by(icons, sort_key)
93       icons.sort_by! { |icon| icon[sort_key] }
94     end
95   end
96
97   Liquid::Template.register_filter(IconFilters)
98
99   class Site
100
101     attr_reader :icons
102
103     def process
104       self.reset_icons
105       self.reset
106       self.read
107       self.generate
108       self.render
109       self.cleanup
110       self.write
111
112       self.build
113     end
114
115     ##
116     # Reads the YAML file that stores all data about icons
117     def reset_icons
118       @icons = IconList.new(YAML.load_file(self.config['icon_meta'])['icons'])
119     end
120
121     ##
122     # After generation, runs a build of Font-Awesome
123     def build
124       system("make build", :chdir => self.config['destination'], :out => :err)
125     end
126
127     def site_payload
128       {
129         "site"       => self.config.merge({
130           "time"       => self.time,
131           "posts"      => self.posts.sort { |a, b| b <=> a },
132           "pages"      => self.pages,
133           "html_pages" => self.pages.reject { |page| !page.html? },
134           "categories" => post_attr_hash('categories'),
135           "tags"       => post_attr_hash('tags')}),
136         "icons"      => @icons,
137       }
138     end
139
140   end
141
142 end