class Swee::View

Public Class Methods

new(controller) click to toggle source
# File lib/swee/view.rb, line 6
def initialize controller
  @controller = controller
  @config = Swee.config.app
  get_binding
end
render_404() click to toggle source

404页面

# File lib/swee/view.rb, line 28
def render_404
  cfg = Swee.config.app
  body = ::ERB.new(File.read(File.expand_path(cfg["page404"], ENV["app_path"]))).result
  headers = { "Content-Type" => "text/html; charset=utf8" }
  [200,headers,[body]]
end

Public Instance Methods

create_view() click to toggle source

读取视图文件 controller/action.erb

# File lib/swee/view.rb, line 21
def create_view
  erb = ::ERB.new(File.read(File.expand_path("views/#{@controller._name}/#{@controller.action_name}.erb", ENV["app_path"])))
  erb.result(binding)
end
get_binding() click to toggle source

把controller 实变量绑定到 view 层

# File lib/swee/view.rb, line 13
def get_binding
  @controller.instance_variables.each do |v|
    instance_variable_set v, @controller.instance_variable_get(v)
  end
end