Skip to content

Commit

Permalink
Basic pango markup helpers
Browse files Browse the repository at this point in the history
Included in widget modules and allows convinience shortcuts
in property formats such as:

	span @default, :font => "terminus 12"
	underline @time
	background :red, @artist
	foreground :blue, @title
	bold @count

* lib/amazing/helpers/pango_markup.rb: (span) simple span
tag generator.
(background) shortcut for background span.
(foreground) shortcut for foreground span.
(underline) shortcut for underline span.
(bold) shortcut for weighted span.

* lib/amazing/widget.rb: (Widget) include pango markup helper.
  • Loading branch information
dag committed Apr 25, 2008
1 parent e67249a commit 496f357
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/amazing/helpers/pango_markup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module Amazing
module Helpers
module PangoMarkup
def span(text, opts)
attrs = opts.map {|key, value| "#{key}=#{value.to_s.inspect}" }.join(" ")
"<span #{attrs}>#{text}</span>"
end

def background(color, text)
span(text, :background => color)
end

def foreground(color, text)
span(text, :foreground => color)
end

def underline(text, style=:single)
span(text, :underline => style)
end

def bold(text, level=:bold)
span(text, :weight => level)
end
end
end
end
2 changes: 2 additions & 0 deletions lib/amazing/widget.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (C) 2008 Dag Odenhall <dag.odenhall@gmail.com>
# Licensed under the Academic Free License version 3.0

require 'amazing/helpers/pango_markup'
require 'erb'

module Amazing
Expand All @@ -24,6 +25,7 @@ class WidgetError < Exception
# end
# end
class Widget
include Helpers::PangoMarkup
include ERB::Util

def initialize(opts={})
Expand Down

0 comments on commit 496f357

Please sign in to comment.