commit:     a100faf515c3cfe8c2d1d8fe4bc6c0fb48f7429d
Author:     Alex Legler <alex <AT> a3li <DOT> li>
AuthorDate: Mon Nov 30 19:48:22 2015 +0000
Commit:     Alex Legler <a3li <AT> gentoo <DOT> org>
CommitDate: Mon Nov 30 19:48:22 2015 +0000
URL:        https://gitweb.gentoo.org/sites/www.git/commit/?id=a100faf5

Ruby code cleanup

 _plugins/devaway.rb    |  4 ++--
 _plugins/filters.rb    |  6 +++---
 _plugins/herds.rb      |  6 +++---
 _plugins/mirrors.rb    |  4 +---
 _plugins/navigation.rb | 31 +++++++++++++++++--------------
 _plugins/news.rb       | 38 +++++++++++++++-----------------------
 _plugins/planet.rb     |  3 +--
 _plugins/tags.rb       |  9 +++++----
 _plugins/wiki.rb       |  2 +-
 9 files changed, 48 insertions(+), 55 deletions(-)

diff --git a/_plugins/devaway.rb b/_plugins/devaway.rb
index 5d411a0..9ba5018 100644
--- a/_plugins/devaway.rb
+++ b/_plugins/devaway.rb
@@ -5,11 +5,11 @@ module Gentoo
     def generate(site)
       data = Nokogiri::XML(File.open(DEVAWAY_XML))
 
-      site.data['devaway'] ||= { }
+      site.data['devaway'] ||= {}
 
       data.xpath('/devaway/dev').each do |dev|
         site.data['devaway'][dev['nick']] = 
dev.xpath('./reason/text()').first.content
       end
     end
   end
-end
\ No newline at end of file
+end

diff --git a/_plugins/filters.rb b/_plugins/filters.rb
index 34ad123..df5b4f7 100644
--- a/_plugins/filters.rb
+++ b/_plugins/filters.rb
@@ -1,6 +1,6 @@
 module Gentoo
   module Filters
-    UNITS = %W(B KiB MiB GiB TiB).freeze
+    UNITS = %w(B KiB MiB GiB TiB).freeze
 
     def nice_filesize(input)
       number = input.to_i
@@ -12,7 +12,7 @@ module Gentoo
         exponent = (Math.log(number) / Math.log(1024)).to_i
         exponent = max_exp if exponent > max_exp
 
-        number  /= 1024 ** exponent
+        number /= 1024**exponent
       end
 
       "#{number} #{UNITS[exponent]}"
@@ -25,4 +25,4 @@ module Gentoo
   end
 end
 
-Liquid::Template.register_filter(Gentoo::Filters)
\ No newline at end of file
+Liquid::Template.register_filter(Gentoo::Filters)

diff --git a/_plugins/herds.rb b/_plugins/herds.rb
index 2f357c7..971f1e2 100644
--- a/_plugins/herds.rb
+++ b/_plugins/herds.rb
@@ -4,7 +4,7 @@ module Gentoo
 
     def generate(site)
       xml = Nokogiri::XML(File.open(XML))
-      
+
       site.data['herds'] ||= {}
 
       xml.xpath('/herds/herd').each do |item|
@@ -21,7 +21,7 @@ module Gentoo
           maint_data = {
             'email' => maint.xpath('./email/text()').first.text,
             'name' => nil,
-            'role' => nil,
+            'role' => nil
           }
 
           ns_name = maint.xpath('./name/text()')
@@ -40,4 +40,4 @@ module Gentoo
       end
     end
   end
-end
\ No newline at end of file
+end

diff --git a/_plugins/mirrors.rb b/_plugins/mirrors.rb
index 1d30238..c1bf17b 100644
--- a/_plugins/mirrors.rb
+++ b/_plugins/mirrors.rb
@@ -26,7 +26,6 @@ module Gentoo
           next unless mirror.name == 'mirror'
 
           mirror.children.each do |tag|
-
             case tag.name
             when 'name'
               mirror_data['name'] = tag.text
@@ -46,7 +45,6 @@ module Gentoo
           site.data['mirrors'][key][region][country_code]['mirrors'] << 
mirror_data
         end
       end
-
     end
   end
-end
\ No newline at end of file
+end

diff --git a/_plugins/navigation.rb b/_plugins/navigation.rb
index 0df1404..66bf9a3 100644
--- a/_plugins/navigation.rb
+++ b/_plugins/navigation.rb
@@ -24,38 +24,43 @@ module Gentoo
       end
 
       private
+
       def primary(all_pages, current_page)
-        pages = all_pages.select {|page| page.data['nav1-show'] == true }
+        pages = all_pages.select { |page| page.data['nav1-show'] == true }
 
         generate(pages, current_page, '1')
       end
 
       def secondary(all_pages, current_page)
-        pages = all_pages.select {|page| page.data['nav1'] == 
current_page['nav1'] and page.data['nav2-show'] == true }
+        pages = all_pages.select { |page| page.data['nav1'] == 
current_page['nav1'] && page.data['nav2-show'] == true }
 
         generate(pages, current_page, '2')
       end
 
       def tertiary(all_pages, current_page)
-        pages = all_pages.select {|page| page.data['nav1'] == 
current_page['nav1'] and page.data['nav2'] == current_page['nav2'] and 
page.data['nav3-show'] == true }
+        pages = all_pages.select do |page|
+          page.data['nav1'] == current_page['nav1'] &&
+          page.data['nav2'] == current_page['nav2'] &&
+          page.data['nav3-show'] == true
+        end
 
         generate(pages, current_page, '3')
       end
 
       def sitemap(all_pages, nav1)
-        pages = all_pages.select {|page| page.data['nav1'] == nav1 and 
page.data['nav2-show'] == true }
+        pages = all_pages.select { |page| page.data['nav1'] == nav1 && 
page.data['nav2-show'] == true }
 
         generate(pages, {}, '2')
       end
 
       def generate(all_pages, current_page, level)
-        level_show = "nav%s-show" % level
-        level_weight = "nav%s-weight" % level
-        level_str = "nav%s" % level
+        level_show = 'nav%s-show' % level
+        level_weight = 'nav%s-weight' % level
+        level_str = 'nav%s' % level
 
-        pages = all_pages.select {|page| page.data[level_show] == true }
+        pages = all_pages.select { |page| page.data[level_show] == true }
         pages.sort! do |a, b|
-          if a.data.has_key? level_weight and b.data.has_key? level_weight
+          if a.data.key?(level_weight) && b.data.key?(level_weight)
             a.data[level_weight] <=> b.data[level_weight]
           else
             a_title = a.data['navtitle'] || a.data['title']
@@ -71,13 +76,13 @@ module Gentoo
 
           html += "<li class=\"%s\">" % css_class
 
-          if page.data.has_key? 'redirect'
+          if page.data.key? 'redirect'
             html += '<a href="' + page.data['redirect'] + '">'
           else
             html += '<a href="' + page.url.gsub('index.html', '') + '">'
           end
 
-          if page.data.has_key? 'navtitle'
+          if page.data.key? 'navtitle'
             html += page.data['navtitle']
           else
             html += page.data['title']
@@ -88,10 +93,8 @@ module Gentoo
 
         html
       end
-
-
     end
   end
 end
 
-Liquid::Template.register_tag('navigation', Gentoo::Tags::NavigationTag)
\ No newline at end of file
+Liquid::Template.register_tag('navigation', Gentoo::Tags::NavigationTag)

diff --git a/_plugins/news.rb b/_plugins/news.rb
index a93aa06..a90c435 100644
--- a/_plugins/news.rb
+++ b/_plugins/news.rb
@@ -1,12 +1,12 @@
 module Gentoo
   class NewsGenerator < Jekyll::Generator
-    NEWS_DIR =  '_data/news/'
+    NEWS_DIR = '_data/news/'
 
     def generate(site)
       site.data['newsitems'] ||= []
 
       Dir.chdir(NEWS_DIR) do
-        Dir.glob("[0-9][0-9][0-9][0-9]*").reverse.each do |path|
+        Dir.glob('[0-9][0-9][0-9][0-9]*').reverse_each do |path|
           begin
             name = path
 
@@ -17,7 +17,7 @@ module Gentoo
         end
       end
 
-      site.data['newsitems'] = site.data['newsitems'].sort {|a,b| b['date'] 
<=> a['date'] }
+      site.data['newsitems'] = site.data['newsitems'].sort { |a, b| b['date'] 
<=> a['date'] }
     end
   end
 
@@ -28,31 +28,23 @@ module Gentoo
       @dir = NewsGenerator::NEWS_DIR
       @name = "#{name}.html"
 
-      self.process(@name)
-      self.read_yaml(File.join(@base, NewsGenerator::NEWS_DIR, path), 
"#{name}.en.txt")
+      process(@name)
+      read_yaml(File.join(@base, NewsGenerator::NEWS_DIR, path), 
"#{name}.en.txt")
 
-      self.data['permalink'] = "/support/news-items/#{name}.html"
-      self.data['layout'] = 'page-pre'
-      self.data['nav1'] = 'support'
-      self.data['nav2'] = 'news-items'
+      data['permalink'] = "/support/news-items/#{name}.html"
+      data['layout'] = 'page-pre'
+      data['nav1'] = 'support'
+      data['nav2'] = 'news-items'
 
       File.readlines(File.join(@base, NewsGenerator::NEWS_DIR, path, 
"#{name}.en.txt")).each do |line|
-        if line =~ /Title: (.*)$/
-          @title = $1
-        end
-
-        if line =~ /Author: (.*)$/
-          @author = $1
-        end
-
-        if line =~ /Posted: (.*)$/
-          @date = $1
-        end
+        @title = $1 if line =~ /Title: (.*)$/
+        @author = $1 if line =~ /Author: (.*)$/
+        @date = $1 if line =~ /Posted: (.*)$/
       end
 
-      site.data['newsitems'] << { 'title' => @title, 'author' => @author, 
'date' => @date, 'url' => self.data['permalink'] }
+      site.data['newsitems'] << { 'title' => @title, 'author' => @author, 
'date' => @date, 'url' => data['permalink'] }
 
-      self.data['title'] = @title
+      data['title'] = @title
     end
   end
-end
\ No newline at end of file
+end

diff --git a/_plugins/planet.rb b/_plugins/planet.rb
index 265e703..cca9122 100644
--- a/_plugins/planet.rb
+++ b/_plugins/planet.rb
@@ -32,7 +32,6 @@ module Gentoo
 
         site.data['planet']['posts'] << item_data unless ignore
       end
-
     end
   end
-end
\ No newline at end of file
+end

diff --git a/_plugins/tags.rb b/_plugins/tags.rb
index 5175cde..7ad24bb 100644
--- a/_plugins/tags.rb
+++ b/_plugins/tags.rb
@@ -1,4 +1,5 @@
 require_relative 'lib/weightedrandomizer'
+
 module Gentoo
   module Tags
     class AdsTag < Liquid::Tag
@@ -8,18 +9,19 @@ module Gentoo
       def render(context)
         ads = context.registers[:site].data['ads']['active']
 
-        ad_html = ""
+        ad_html = ''
         first_ad = true
         raw_weighted_ads = Hash[ads.map { |ad| [ad, ad['weight'] || 0] }]
         ads_wr = WeightedRandomizer.new(raw_weighted_ads)
-        ads_wr.sample(AD_COUNT*10).uniq.slice(0, AD_COUNT).each do |ad|
+        ads_wr.sample(AD_COUNT * 10).uniq.slice(0, AD_COUNT).each do |ad|
           if first_ad
             ad_html += '<div class="col-xs-12 col-md-2 col-md-offset-2 
sponsorlogo">'
             first_ad = false
           else
             ad_html += '<div class="col-xs-12 col-md-2 sponsorlogo">'
           end
-                 ad_html += '<!-- sponsor{name:%s,weight:%d} -->' % 
[ad['name'], ad['weight']]
+
+          ad_html += '<!-- sponsor{name:%s,weight:%d} -->' % [ad['name'], 
ad['weight']]
 
           if ad.has_key? 'img'
             ad_html += "<a href=\"%s\" title=\"%s\"><img 
src=\"/assets/img/sponsors/ads/%s\" alt=\"%s\"></a>" %
@@ -34,7 +36,6 @@ module Gentoo
         ad_html
       end
     end
-
   end
 end
 

diff --git a/_plugins/wiki.rb b/_plugins/wiki.rb
index ee2c27c..5d25716 100644
--- a/_plugins/wiki.rb
+++ b/_plugins/wiki.rb
@@ -27,4 +27,4 @@ module Gentoo
       end
     end
   end
-end
\ No newline at end of file
+end

Reply via email to