From 2d392e7b167fdf0a6c76e287a0f78c7ff4f88d94 Mon Sep 17 00:00:00 2001 From: Nathan Lasseter Date: Wed, 21 Jan 2015 17:47:21 +0000 Subject: Initial commit --- example.html.rb | 26 ++++++++++++++++++++++++++ lib/tag.rb | 27 +++++++++++++++++++++++++++ lib/utils.rb | 11 +++++++++++ lib/virgil.rb | 2 ++ 4 files changed, 66 insertions(+) create mode 100644 example.html.rb create mode 100644 lib/tag.rb create mode 100644 lib/utils.rb create mode 100644 lib/virgil.rb diff --git a/example.html.rb b/example.html.rb new file mode 100644 index 0000000..fb5d818 --- /dev/null +++ b/example.html.rb @@ -0,0 +1,26 @@ +require './lib/virgil' +include Virgil + +puts Tag.doctype { + "html" +} + +puts Tag.html { + Tag.head { + Tag.title { + "My Virgil site" + } + } + Tag.body { + Tag.h1 { + "My Virgil site" + } + Tag.p ({:class => "italic"}) { + "some content" + } + Tag.img ({:src => "img.jpg"}) + Tag.a ({"href" => "/"}) { + "A link home" + } + } +} diff --git a/lib/tag.rb b/lib/tag.rb new file mode 100644 index 0000000..bad0d01 --- /dev/null +++ b/lib/tag.rb @@ -0,0 +1,27 @@ +module Virgil + class Tag + class << self + def doctype + "" + end + def common(attrs = {}) + "<#{__callee__}" + Utils.unfold(attrs) + ">" + + yield + + "" + end + def common_single(attrs = {}) + "<#{__callee__}" + Utils.unfold(attrs) + " />" + end + + alias :html :common + alias :head :common + alias :title :common + alias :body :common + alias :h1 :common + alias :p :common + alias :img :common_single + alias :a :common + + end + end +end diff --git a/lib/utils.rb b/lib/utils.rb new file mode 100644 index 0000000..e3b96a9 --- /dev/null +++ b/lib/utils.rb @@ -0,0 +1,11 @@ +module Virgil + class Utils + def self.unfold(attrs) + ret = "" + attrs.each do |key, value| + ret += " #{key.to_s}=\"#{value}\"" + end + ret + end + end +end diff --git a/lib/virgil.rb b/lib/virgil.rb new file mode 100644 index 0000000..ef1c9fc --- /dev/null +++ b/lib/virgil.rb @@ -0,0 +1,2 @@ +require './lib/utils' +require './lib/tag' -- cgit v1.2.1