Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 68 lines (56 sloc) 1.756 kb
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
require 'rubygems'
require 'erector'
require './rounded'

Widget = Erector::Widget unless Object.const_defined?(:Widget)

class Iconistan < Erector::Widget
  extend Rounded
  external :style, <<-CSS
div.iconistan { position: relative; padding: 0px; margin: 0px 4px; }
div.iconistan a { text-decoration: none; font-size: 10pt; }

div.iconistan div.icon { margin: 2px; float: left; height: 36px; }
div.iconistan div.icon:nth-child(1) { margin-left: 0px; }

div.iconistan div.icon div.icon_border { float: left;
border: 2px solid #a3a3a3; #{rounded(2)}; margin: 0px; padding: 1px;
background-color: white;
}
div.iconistan div.icon:hover div.icon_border { border: 2px solid red; }

div.iconistan div.icon img { margin: 0px; }
div.iconistan div.icon div.url { position: absolute; top: 28px; left: 2px; /* must sync url's left and iconistan's padding */
background: #EFFEFF; border: 1px solid black; padding: 2px 8px; }
div.iconistan div.icon div.url { visibility: hidden; }
div.iconistan div.icon:hover div.url { visibility: visible; }
CSS

  needs :sites, :dir => "icons"

  # todo: test
  class Site < Widget
    needs :url, :dir

    def initialize options
      super
      @domain = @url.match(/https?:\/\/([^.]*)\./)[1]
      @img = "#{@dir}/#{@domain}.png"
    end

    def content
      div.icon do
        div.icon_border do
          a :href => @url do
            img :src => @img, :height => 16, :width => 16
          end
        end
        text nbsp(" ")
        div.url do
          url @url
        end
      end
    end
  end

  def sites
    @sites.map{|url| Site.new(url: url, dir: @dir)}
  end

  def content
    div.iconistan do
      sites.each do |site|
        widget site
      end
    end
  end
end
Something went wrong with that request. Please try again.