Navigation Menu

Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Sep 16, 2013
1 parent ea79eae commit b9d8710
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 8 deletions.
9 changes: 2 additions & 7 deletions lib/lotus/frameworks.rb
@@ -1,6 +1,7 @@
require 'lotus/router'
require 'lotus/controller'
require 'lotus/view'
require 'lotus/view/view_loader'

module Lotus
module View
Expand Down Expand Up @@ -42,13 +43,7 @@ def self.render(response)

protected
def self.view_for(action)
# TODO extract Lotus::Views::ViewLoader.new(action, config).load!
namespace, alternate_action_name, action_name = action.class.name.split('::')
action_name = action_name || alternate_action_name
namespace = namespace.gsub(config.controller_suffix, '')
Utils::Class.load!(
"#{ namespace }::(#{ config.view_namespace }#{ action_name }|#{ action_name }#{ config.view_suffix })"
)
Lotus::View::ViewLoader.new(action, config).load!
end
end
end
25 changes: 25 additions & 0 deletions lib/lotus/view/view_loader.rb
@@ -0,0 +1,25 @@
require 'lotus/utils/class'

module Lotus
module View
class ViewLoader
NAMESPACE_SEPARATOR = '::'.freeze
SUFFIX_REPLACEMENT = ''.freeze

def initialize(action, config)
namespace, action_name = _extract_namespace_and_action_name(action, config.dup)
@class_name = "#{ namespace }::(#{ config.view_namespace }#{ action_name }|#{ action_name }#{ config.view_suffix })"
end

def load!
Utils::Class.load!(@class_name)
end

private
def _extract_namespace_and_action_name(action, config)
namespace, alternate_action_name, action_name = action.class.name.split(NAMESPACE_SEPARATOR)
[ namespace.gsub(config.controller_suffix, SUFFIX_REPLACEMENT), action_name || alternate_action_name ]
end
end
end
end
3 changes: 2 additions & 1 deletion test/fixtures/blog/application.rb
Expand Up @@ -4,7 +4,8 @@ class Application < Lotus::Application
root __dir__

routes do
get '/', to: 'posts#index'
get '/', to: 'posts#index'
get '/raise', to: 'posts#raise'
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/blog/posts/controller.rb
Expand Up @@ -6,5 +6,11 @@ class Controller
def call(params)
end
end

action 'Raise' do
def call(params)
raise "I've got a problem"
end
end
end
end
16 changes: 16 additions & 0 deletions test/integration/application_test.rb
Expand Up @@ -17,6 +17,22 @@
response.body.must_match %(<title>Blog: Posts</title>)
response.body.must_match %(<h1>Posts</h1>)
end

# it 'returns a server side error when an exeception is raised' do
# response = @blog.get('/raise')

# response.status.must_equal 500
# response.body.must_match %(<title>Blog: Internal Server Error</title>)
# response.body.must_match %(<h1>Internal Server Error</h1>)
# end

# it 'returns a not found response for unknown path' do
# response = @blog.get('/unknown')

# response.status.must_equal 404
# response.body.must_match %(<title>Blog: Not Found</title>)
# response.body.must_match %(<h1>Not Found</h1>)
# end
end

describe 'with a Rails layout' do
Expand Down

0 comments on commit b9d8710

Please sign in to comment.