class Hermeneutics::Html

Example

require “hermeneutics/color” require “hermeneutics/html”

class MyHtml < Hermeneutics::Html

def build
  html {
    head {
      title { "Example" }
      comment "created as an example, #{Time.now}"
    }
    body bgcolor: Hermeneutics::Color.from_s( "ffffef") do
      h1 {
        pcdata "Ruby "
        a href: "www.w3.org" do "Html" end
        _ { " example" }
      }
      p { "Some text.\nBye." }
      p {
        self << "link"
        br
        a href: "www.w3.org" do "Html" end
      }
    end
  }
end

end

Hermeneutics::Html.document

Constants

CONTENT_TYPE

Attributes

main[RW]
cgi[RW]

Public Class Methods

document(*args, **kwargs, &block) click to toggle source
# File lib/hermeneutics/html.rb, line 55
def document *args, **kwargs, &block
  open do |i|
    i.document *args, **kwargs, &block
  end
end
inherited(cls) click to toggle source
# File lib/hermeneutics/html.rb, line 46
def inherited cls
  Html.main = cls
end
open(out = nil) { |i| ... } click to toggle source
# File lib/hermeneutics/html.rb, line 49
def open out = nil
  i = (@main||self).new
  i.generate out do
    yield i
  end
end
write_file(name = nil) { |i| ... } click to toggle source
# File lib/hermeneutics/html.rb, line 60
def write_file name = nil
  name ||= (File.basename $0, ".rb") + ".html"
  File.open name, "w" do |f|
    open f do |i|
      if block_given? then
        yield i
      else
        i.document
      end
    end
  end
end

Public Instance Methods

build() click to toggle source
# File lib/hermeneutics/html.rb, line 93
def build
  html { body { h1 { "It works." } } }
end
doctype_header() click to toggle source
# File lib/hermeneutics/html.rb, line 89
def doctype_header
  @generator.doctype "html"
end
document(*args, **kwargs, &block) click to toggle source
# File lib/hermeneutics/html.rb, line 84
def document *args, **kwargs, &block
  doctype_header
  build *args, **kwargs, &block
end
form!(**attrs, &block) click to toggle source
# File lib/hermeneutics/cgi.rb, line 19
def form! **attrs, &block
  attrs[ :action] = @cgi.fullname attrs[ :action]
  form **attrs, &block
end
generate(out = nil) { || ... } click to toggle source
# File lib/hermeneutics/html.rb, line 74
def generate out = nil
  g = @generator
  begin
    @generator = Generator.new out||$stdout
    yield
  ensure
    @generator = g
  end
end
href(dest, params = nil, anchor = nil) click to toggle source
# File lib/hermeneutics/cgi.rb, line 24
def href dest, params = nil, anchor = nil
  @utx ||= URLText.new
  dest = @cgi.fullname dest
  @utx.mkurl dest, params, anchor
end
href!(dest, params = nil, anchor = nil) click to toggle source
# File lib/hermeneutics/cgi.rb, line 30
def href! dest, params = nil, anchor = nil
  dest = @cgi.fullpath dest
  href dest, params, anchor
end
language() click to toggle source
# File lib/hermeneutics/html.rb, line 98
def language
  if ENV[ "LANG"] =~ /\A\w{2,}/ then
    r = $&
    r.gsub! /_/, "-"
    r
  end
end