Class: Swee::View

Inherits:
Object show all
Includes:
Helper
Defined in:
lib/swee/view.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helper

#form_for, #image_tag, #parse_tag_options, #raw, #tag

Constructor Details

#initialize(controller) ⇒ View

Returns a new instance of View.



7
8
9
10
11
# File 'lib/swee/view.rb', line 7

def initialize controller
  @controller = controller
  @config = Swee.config.app
  get_binding
end

Class Method Details

.render_404Object

404页面



29
30
31
32
33
34
# File 'lib/swee/view.rb', line 29

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

Instance Method Details

#create_viewObject

读取视图文件 controller/action.erb



22
23
24
25
# File 'lib/swee/view.rb', line 22

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_bindingObject

把controller 实变量绑定到 view 层



14
15
16
17
18
# File 'lib/swee/view.rb', line 14

def get_binding
  @controller.instance_variables.each do |v|
    instance_variable_set v, @controller.instance_variable_get(v)
  end
end