diff options
Diffstat (limited to 'lib/utils.rb')
-rw-r--r-- | lib/utils.rb | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/lib/utils.rb b/lib/utils.rb index e3b96a9..1df8305 100644 --- a/lib/utils.rb +++ b/lib/utils.rb @@ -1,11 +1,37 @@ module Virgil - class Utils + module Utils def self.unfold(attrs) ret = "" attrs.each do |key, value| - ret += " #{key.to_s}=\"#{value}\"" + if value.nil? then + ret += " #{key.to_s}" + else + ret += " #{key.to_s}=\"#{value}\"" + end end ret end + + class Generic + def initialize(attrs, tag = nil, &block) + tag = self.class.name.split('::').last.downcase if tag.nil? + @tag = "<#{tag}" + + Utils::unfold(attrs) + + ">" + + self.instance_eval(&block) + + "</#{tag}>" + end + def to_s + @tag + end + end + class GenericSingle < Generic + def initialize(attrs, tag = nil) + tag = self.class.name.split('::').last.downcase if tag.nil? + @tag = "<#{tag}" + + Utils::unfold(attrs) + + ">" + end + end end end |