# Copyright (C) 2003-2005 Kouichirou Eto, All rights reserved.

$LOAD_PATH << "../../lib" unless $LOAD_PATH.include?("../../lib")
require "qwik/parser"
require "qwik/resolve"
require "qwik/generator-view"
require "qwik/act-url"

module Qwik
  class Action
    #------------------------------------------------------------ format
    def c_parse(str)
      return TextParser.new.parse(str)
    end

    def c_res(str)
      w = c_parse(str)
      return Resolver.new(@config, @site, self).resolve(w)
    end

    def c_get(pagename)
      page = @site[pagename]
      if page.nil?
	return nil
      end
      str = page.load
      return c_res(str)
    end

    def c_add_br(str)
      ignore_chars = [?\s, ?-, ?*, ?>, ?|, ?,, ?{, ?}]
      str.map {|line|
	line.chomp!
	line = line+"~" unless ignore_chars.include?(line[0])
	line
      }.join("\n")+"\n"
    end

    def c_pre_text(str="")
      str = "" if str.nil?
      if block_given?
	str2 = yield
	str += str2 if str2
      end
      str = c_add_br(str)
      c_res(str)
    end

    #------------------------------------------------------------ generate
    def c_set_html
      @res["Content-Type"] = "text/html; charset=Shift_JIS"
    end

    def c_set_no_cache
      @res["Pragma"] = "no-cache"
      @res["Cache-Control"] = "no-cache"
    end
  end
end

if $0 == __FILE__
  require "t/test"
  $debug = true
end

if $debug
  class TC_ActGenerate < Test::Unit::TestCase
    include TestSession

    def test_dummy
    end
  end
end
