module Slight::DSLEssential

Public Instance Methods

br() click to toggle source
# File lib/slight/dsl.rb, line 5
def br; echo "<br/>\n"; end
doctype(type) click to toggle source
# File lib/slight/dsl.rb, line 15
def doctype(type)
  case type
  when :html, :h5
    echo "<!DOCTYPE html>\n"
  when :h11
    echo %q[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">] + "\n"
  when :strict
    echo %q[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">] + "\n"
  when :frameset
    echo %q[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">] + "\n"
  when :mobile
    echo %q[<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">] + "\n"
  when :basic
    echo %q[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">] + "\n"
  when :transitional
    echo %q[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">] + "\n"
  when :xml
    echo %q[<?xml version="1.0" encoding="utf-8" ?>] + "\n"
  end

end
hr() click to toggle source
# File lib/slight/dsl.rb, line 7
def hr; echo "<hr/>\n"; end
inc(*preloads) click to toggle source
# File lib/slight/dsl.rb, line 66
def inc(*preloads)
  preloads << "defaults" if preloads.size == 0
  preloads.each{ |target|
    layout_yield(target.to_s + ".rb")
  }
end
js(str) click to toggle source
# File lib/slight/dsl.rb, line 11
def js(str)
  echo "<script language=\"javascript\">\n#{str}\n</script>\n"
end
layout(target) { || ... } click to toggle source
# File lib/slight/dsl.rb, line 61
def layout(target)
  yield if block_given?
  layout_yield(target.to_s + ".slight")
end
layout_yield(target_src) click to toggle source

load another page into current page

# File lib/slight/dsl.rb, line 47
def layout_yield(target_src)
  #eval(File.new(target_src).read, binding_scope, target_src, __LINE__ - 48)
  @load_history ||= [] # prevernt recursive page load
  #unless @load_history[target_src] then
  @load_history.push target_src
  unless @load_history.count(target_src) == 2
    self.instance_eval(File.new(target_src).read, target_src, __LINE__ - 48)
  else
    echo "<!--recursive page loading deteced, ignore.-->"
  end
  @load_history.pop
  nil
end
title(str) click to toggle source
# File lib/slight/dsl.rb, line 9
def title(str); echo "<title>#{str}</title>\n"; end
use(uri, type=nil) click to toggle source
# File lib/slight/dsl.rb, line 37
def use(uri, type=nil)
  case type ||= uri.split('.')[-1]
  when "js",:js
    echo "<script type=\"text/javascript\" src=\"#{uri}\"></script>\n"
  when "css",:css
    echo "<link rel=\"stylesheet\" href=\"#{uri}\"></link>\n"
  end
end