class Hermes::Html
Constants
- CONTENT_TYPE
- DOCTYPE
- Field
- NBSP
- TAGS
Attributes
main[RW]
cgi[R]
Public Class Methods
new(cgi, *args)
click to toggle source
# File lib/hermes/cgi.rb, line 27 def initialize cgi, *args @cgi = cgi end
Public Instance Methods
<<(str)
click to toggle source
# File lib/hermes/html.rb, line 339 def << str @generator.plain str if str self end
_(str = nil) { || ... }
click to toggle source
# File lib/hermes/html.rb, line 344 def _ str = nil @generator.plain str||yield nil end
build()
click to toggle source
# File lib/hermes/html.rb, line 65 def build html { body { p { "It works." } } } end
comment(str)
click to toggle source
# File lib/hermes/html.rb, line 349 def comment str @generator.comment str end
css(str)
click to toggle source
# File lib/hermes/html.rb, line 362 def css str mime = { type: "text/css" } script mime do quote_script str end end
document(out = nil)
click to toggle source
# File lib/hermes/html.rb, line 47 def document out = nil open_out out do |o| @main.new.document o end end
field(type, attrs)
click to toggle source
# File lib/hermes/html.rb, line 391 def field type, attrs attrs[ :id] ||= attrs[ :name] @tabindex += 1 attrs[ :tabindex] ||= @tabindex Field[ type, attrs] end
form(attrs, &block)
click to toggle source
# File lib/hermes/html.rb, line 377 def form attrs, &block attrs[ :method] ||= if attrs[ :enctype] == "multipart/form-data" then "post" else "get" end @tabindex = 0 method_missing :form, attrs, &block ensure @tabindex = nil end
form!(name, attrs = nil, &block)
click to toggle source
# File lib/hermes/cgi.rb, line 31 def form! name, attrs = nil, &block attrs ||= {} attrs[ :name] = name attrs[ :action] = scriptpath attrs[ :action] form attrs, &block end
head(attrs = nil) { || ... }
click to toggle source
# File lib/hermes/html.rb, line 367 def head attrs = nil method_missing :head, attrs do c = ContentType.new "text/html", charset: @generator.encoding meta http_equiv: "Content-Type", content: c l = language meta http_equiv: "Content-Language", content: l if l yield end end
href(dest, params = nil, anchor = nil)
click to toggle source
# File lib/hermes/cgi.rb, line 38 def href dest, params = nil, anchor = nil @utx ||= URLText.new dest = scriptpath dest @utx.mkurl dest, params, anchor end
href!(params = nil, anchor = nil)
click to toggle source
# File lib/hermes/cgi.rb, line 44 def href! params = nil, anchor = nil href nil, params, anchor end
inherited(cls)
click to toggle source
# File lib/hermes/html.rb, line 44 def inherited cls Html.main = cls end
input(arg, &block)
click to toggle source
# File lib/hermes/html.rb, line 413 def input arg, &block if Field === arg then case arg.type when /select/i then method_missing :select, arg.attrs, &block when /textarea/i then block and raise ArgumentError, "Field textarea: use the value attribute." v = arg.attrs.delete :value method_missing :textarea, arg.attrs do v end else arg.attrs[ :type] ||= arg.type method_missing :input, arg.attrs, &block end else method_missing :input, arg, &block end end
javascript(str)
click to toggle source
# File lib/hermes/html.rb, line 357 def javascript str mime = { type: "text/javascript" } script mime do quote_script str end end
label(field, attrs = nil, &block)
click to toggle source
# File lib/hermes/html.rb, line 398 def label field, attrs = nil, &block if String === attrs then label field do attrs end return end if Field === field or attrs then a = attrs attrs = { for: field.attrs[ :id] } attrs.merge! a if a else attrs = field end method_missing :label, attrs, &block end
language()
click to toggle source
# File lib/hermes/html.rb, line 62 def language end
method_missing(name, *args, &block)
click to toggle source
Calls superclass method
# File lib/hermes/html.rb, line 325 def method_missing name, *args, &block t = TAGS[ name] t or super @generator.tag t, name, *args, &block end
path()
click to toggle source
# File lib/hermes/html.rb, line 301 def path ; @generator.path ; end
pcdata(*strs)
click to toggle source
# File lib/hermes/html.rb, line 331 def pcdata *strs strs.each { |s| next unless s @generator.plain s } nil end
quote_script(str)
click to toggle source
# File lib/hermes/html.rb, line 353 def quote_script str comment str+$/+"// " end
Private Instance Methods
doctype_header()
click to toggle source
# File lib/hermes/html.rb, line 84 def doctype_header doctype_header_data do |type,dtd,dir,variant,file| file or raise ArgumentError, "No header data for #{self.class}" name = ["DTD", dtd, variant].compact.join " " path = ["-", "W3C", name, "EN"].join "//" link = "http://www.w3.org/TR/#{dir}/#{file}.dtd" @generator.doctype type, path, link end end
doctype_header_data() { |"HTML", "HTML 01", "html4", *vf| ... }
click to toggle source
# File lib/hermes/html.rb, line 94 def doctype_header_data vf = case DOCTYPE when "strict" then [ nil, "strict" ] when "transitional" then [ "Transitional", "loose" ] when "frameset" then [ "Frameset", "frameset"] end yield "HTML", "HTML 4.01", "html4", *vf end
open_out(out) { |out| ... }
click to toggle source
# File lib/hermes/html.rb, line 53 def open_out out if out or $*.empty? then yield out else File.open $*.shift, "w" do |f| yield f end end end
scriptpath(dest)
click to toggle source
# File lib/hermes/cgi.rb, line 50 def scriptpath dest unless dest =~ %r{\A/} then if dest then dest =~ /\.\w+\z/ or dest += ".rb" else dest = File.basename @cgi.script_name end end dest end