From ce8d414b7bca6e03d44740dd7112be5bc75d654e Mon Sep 17 00:00:00 2001 From: robmadole Date: Fri, 17 May 2013 08:35:23 -0500 Subject: [PATCH] Global icons object --- .ruby-version | 1 + Gemfile | 4 + Gemfile.lock | 46 +++++++++++ build/_includes/whats-new.html | 2 +- build/_layouts/icon.html | 30 +++---- build/_plugins/css_preproc_generator.rb | 56 +++++++++++++ build/_plugins/icon_page_generator.rb | 10 +-- build/_plugins/site.rb | 100 ++++++++++++++++++++++++ 8 files changed, 227 insertions(+), 22 deletions(-) create mode 100644 .ruby-version create mode 100755 Gemfile create mode 100644 Gemfile.lock create mode 100644 build/_plugins/css_preproc_generator.rb create mode 100644 build/_plugins/site.rb diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 000000000..ae6d5b9cb --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +1.9.3-p392 diff --git a/Gemfile b/Gemfile new file mode 100755 index 000000000..b95f33990 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +gem 'jekyll', '1.0' +gem 'debugger' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 000000000..a00e13f1e --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,46 @@ +GEM + remote: https://rubygems.org/ + specs: + classifier (1.3.3) + fast-stemmer (>= 1.0.0) + colorator (0.1) + columnize (0.3.6) + commander (4.1.3) + highline (~> 1.6.11) + debugger (1.6.0) + columnize (>= 0.3.1) + debugger-linecache (~> 1.2.0) + debugger-ruby_core_source (~> 1.2.1) + debugger-linecache (1.2.0) + debugger-ruby_core_source (1.2.2) + directory_watcher (1.4.1) + fast-stemmer (1.0.2) + highline (1.6.19) + jekyll (1.0.0) + classifier (~> 1.3) + colorator (~> 0.1) + commander (~> 4.1.3) + directory_watcher (~> 1.4.1) + kramdown (~> 0.14) + liquid (~> 2.3) + maruku (~> 0.5) + pygments.rb (~> 0.4.2) + safe_yaml (~> 0.7.0) + kramdown (0.14.2) + liquid (2.5.0) + maruku (0.6.1) + syntax (>= 1.0.0) + posix-spawn (0.3.6) + pygments.rb (0.4.2) + posix-spawn (~> 0.3.6) + yajl-ruby (~> 1.1.0) + safe_yaml (0.7.1) + syntax (1.0.0) + yajl-ruby (1.1.0) + +PLATFORMS + ruby + +DEPENDENCIES + debugger + jekyll (= 1.0) diff --git a/build/_includes/whats-new.html b/build/_includes/whats-new.html index f93584b36..ab0bd68a7 100644 --- a/build/_includes/whats-new.html +++ b/build/_includes/whats-new.html @@ -10,7 +10,7 @@
-

{{ site.font_awesome.new_icon_count }} New Icons in {{ site.font_awesome.version }}

+

{{ icons | version:site.font_awesome.version | size }} New Icons in {{ site.font_awesome.version }}

Requested by the active community on the Font Awesome GitHub project.
diff --git a/build/_layouts/icon.html b/build/_layouts/icon.html index ce420358b..3d1f8bc13 100755 --- a/build/_layouts/icon.html +++ b/build/_layouts/icon.html @@ -6,26 +6,26 @@ relative_path: ../../
-    -    -    -    -   - +    +    +    +    +   +

- icon-{{ page.icon['id'] }} + icon-{{ page.icon.id }} - · - Unicode: {{ page.icon['unicode'] }} · - Created: v{{ page.icon['created'] }} · + · + Unicode: {{ page.icon.unicode }} · + Created: v{{ page.icon.created }} · Categories: - {% for category in page.icon['categories'] %} + {% for category in page.icon.categories %} {{ category }}{% unless forloop.last %},{% endunless %} {% endfor %} - {% if page.icon['aliases'] %} + {% if page.icon.aliases %} · Aliases: - {% for alias in page.icon['aliases'] %} + {% for alias in page.icon.aliases %} icon-{{ alias }}{% unless forloop.last %},{% endunless %} {% endfor %} {% endif %} @@ -42,11 +42,11 @@ relative_path: ../../

After you get up and running, you can place Font Awesome icons just about anywhere with the <i> tag:

- icon-{{ page.icon['id'] }} + icon-{{ page.icon.id }}
{% highlight html linenos %} - icon-{{ page.icon['id'] }} + icon-{{ page.icon.id }} {% endhighlight %}
Looking for more? Check out the examples.
diff --git a/build/_plugins/css_preproc_generator.rb b/build/_plugins/css_preproc_generator.rb new file mode 100644 index 000000000..c83bbf200 --- /dev/null +++ b/build/_plugins/css_preproc_generator.rb @@ -0,0 +1,56 @@ +## +# Create Less and Sass files + +require 'yaml' +require 'forwardable' +require 'debugger' + +module Jekyll + + class CssPreProcPage < Page + + def initialize(site, base, dir, name, icons) + @site = site + @base = base + @dir = dir + @name = name + @icons = icons + + self.process(@name) + + self.read_yaml(File.join(base, site.config['layouts']), @name) + + self.data['icons'] = icons + end + + end + + class CssPreProcGenerator < Generator + + ## + # Iterate over every described icon in a YAML file and create a page for it + + safe true + + def generate(site) + # Need to figure use lessc to generate the files first + return + + less_destination = site.config['css_preproc']['less_destination'] + + # Less file + site.pages << CssPreProcPage.new( + site, site.source, less_destination, + site.config['css_preproc']['less_layout'], + site.icons) + + # Less IE7 file + site.pages << CssPreProcPage.new( + site, site.source, less_destination, + site.config['css_preproc']['less_ie7_layout'], + site.icons) + end + + end + +end diff --git a/build/_plugins/icon_page_generator.rb b/build/_plugins/icon_page_generator.rb index 2a05611af..51475e540 100755 --- a/build/_plugins/icon_page_generator.rb +++ b/build/_plugins/icon_page_generator.rb @@ -2,6 +2,7 @@ # Create individual pages for each icon in the FontAwesome set require 'yaml' +require 'debugger' module Jekyll @@ -14,7 +15,7 @@ module Jekyll @site = site @base = base @dir = dir - @name = "#{icon['id']}.html" + @name = "#{icon.id}.html" @icon = icon self.process(@name) @@ -22,7 +23,7 @@ module Jekyll self.read_yaml(File.join(base, site.config['layouts']), site.config['icon_layout']) self.data['icon'] = icon - self.data['title'] = "icon-#{icon['id']}: " + self.data['title_suffix'] + self.data['title'] = "icon-#{icon.id}: " + self.data['title_suffix'] end end @@ -35,10 +36,7 @@ module Jekyll safe true def generate(site) - icon_meta_filename = site.config['icon_meta'] - icon_meta = YAML.load_file(icon_meta_filename) - - icon_meta['icons'].each do |icon| + site.icons.each do |icon| site.pages << IconPage.new(site, site.source, site.config['icon_destination'], icon) end end diff --git a/build/_plugins/site.rb b/build/_plugins/site.rb new file mode 100644 index 000000000..744a5a848 --- /dev/null +++ b/build/_plugins/site.rb @@ -0,0 +1,100 @@ +## +# Provide an icons attribute on the site object + +require 'yaml' +require 'forwardable' + +module Jekyll + + class Icon + + attr_reader :name, :id, :unicode, :created, :categories + + def initialize(icon_object) + @icon_object = icon_object + + @name = icon_object['name'] + @id = icon_object['id'] + @aliases = icon_object['aliases'] + @unicode = icon_object['unicode'] + @created = icon_object['created'] + @categories = icon_object['categories'] + end + + def to_liquid + return @icon_object + end + + end + + class IconList + ## + # A list of icons + # + include Enumerable + extend Forwardable + + def_delegators :@icon_array, :each, :<< + + def initialize(icon_array) + @original_icon_array = icon_array + @icon_array = [] + + icon_array.each { |icon_object| + @icon_array << Icon.new(icon_object) + } + end + + def [](k) + @icon_array[k] + end + + def to_liquid + @original_icon_array + end + + end + + module IconFilters + def category(icons, cat) + icons.select { |icon| icon['categories'].include?(cat) } + end + + def version(icons, version) + icons.select { |icon| icon['created'] == version } + end + end + + Liquid::Template.register_filter(IconFilters) + + class Site + + attr_reader :icons + + def process + @icons = IconList.new(YAML.load_file(self.config['icon_meta'])['icons']) + + self.reset + self.read + self.generate + self.render + self.cleanup + self.write + end + + def site_payload + { + "site" => self.config.merge({ + "time" => self.time, + "posts" => self.posts.sort { |a, b| b <=> a }, + "pages" => self.pages, + "html_pages" => self.pages.reject { |page| !page.html? }, + "categories" => post_attr_hash('categories'), + "tags" => post_attr_hash('tags')}), + "icons" => @icons, + } + end + + end + +end