summaryrefslogtreecommitdiff
path: root/lib/utils.rb
diff options
context:
space:
mode:
authorNathan Lasseter <Nathan Lasseter nathan@bytemark.co.uk>2015-01-23 17:17:30 +0000
committerNathan Lasseter <Nathan Lasseter nathan@bytemark.co.uk>2015-01-23 17:17:30 +0000
commit4e0218895efd84adeb613a9b068bc52989ad518e (patch)
tree41c0d785c78a09106665f94c213cbcbdde76074b /lib/utils.rb
parentd927f4a0e7c87c6ff50e69f9fbaa4ade827d2f06 (diff)
Really working in the tree structure for tags. aiming to remove all of the aliases in favour of the new style.HEADmaster
Diffstat (limited to 'lib/utils.rb')
-rw-r--r--lib/utils.rb30
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