Skip to content

Commit

Permalink
Nested layouts working
Browse files Browse the repository at this point in the history
  • Loading branch information
Roger Campos committed Nov 8, 2011
1 parent f3f0d22 commit cd20c04
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 31 deletions.
2 changes: 1 addition & 1 deletion app/controllers/interpret/base_controller.rb
Expand Up @@ -2,7 +2,7 @@ class Interpret::BaseController < eval(Interpret.parent_controller.classify)
before_filter :set_locale
before_filter { authorize! :use, :interpret }
before_filter :check_authorized_language
layout 'interpret/application'
layout 'interpret/interpret'

protected
def current_interpret_user
Expand Down
@@ -1,14 +1,3 @@
<!DOCTYPE html>
<html>
<head>
<title><%= yield :title %></title>
<%= stylesheet_link_tag "interpret_style" %>
<%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" %>
<%= javascript_include_tag "best_in_place", "interpret" %>
<%= csrf_meta_tag %>
</head>
<body>

<div id="interpret_container">
<% if flash.any? %>
<div class="interpret_flash grid_16 <%= flash.keys.first %>">
Expand Down Expand Up @@ -63,8 +52,4 @@
</div>
</div>


</body>
</html>


<%= interpret_parent_layout Interpret.layout%>
13 changes: 1 addition & 12 deletions lib/interpret/helpers.rb
@@ -1,6 +1,5 @@
module Interpret
module InterpretHelpers

# Generates the html tree from the given keys
def interpret_show_tree(tree, origin_keys)
tree = tree.first[1]
Expand All @@ -12,19 +11,14 @@ def interpret_show_tree(tree, origin_keys)
build_tree(tree, origin_keys)
end

def interpret_section_link_to(name, options = {}, html_options = {})
html_options.merge!({ :class => 'current' }) if current_controller?(options)
link_to name, options, html_options
end

def interpret_title(title)
content_for :title do
title
end
end

def interpret_parent_layout(layout)
@_content_for[:layout] = self.output_buffer
@view_flow.set(:layout, self.output_buffer)
self.output_buffer = render(:file => "layouts/#{layout}")
end

Expand Down Expand Up @@ -88,10 +82,5 @@ def build_tree(hash, origin_keys = "", prev_key = "")
out << "</ul>"
out.html_safe
end

def current_controller?(opts)
hash = Rails.application.routes.recognize_path(url_for(opts))
params[:controller] == hash[:controller]
end
end
end
6 changes: 6 additions & 0 deletions test_app/app/controllers/admin/dashboard_controller.rb
@@ -0,0 +1,6 @@
class Admin::DashboardController < ApplicationController
layout 'backoffice'

def index
end
end
1 change: 1 addition & 0 deletions test_app/app/views/admin/dashboard/index.html.erb
@@ -0,0 +1 @@
Another Backoffice section
4 changes: 2 additions & 2 deletions test_app/app/views/layouts/backoffice.html.erb
Expand Up @@ -14,8 +14,8 @@
<div id="backoffice_menu">
<ul>
<li><%= link_to "Public page", "/" %></li>
<li><%= link_to "Other backoffice section", "#" %></li>
<li><%= link_to "Translations", interpret_path %></li>
<li><%= link_to "Other backoffice section", main_app.admin_dashboard_path %></li>
<li><%= link_to "Translations", main_app.interpret_path %></li>
</ul>
</div>
<div id="page">
Expand Down
3 changes: 3 additions & 0 deletions test_app/config/routes.rb
Expand Up @@ -11,6 +11,9 @@

post "toggle_edition_mode", :to => "application#toggle_edition_mode"

namespace :admin do
get 'dashboard', :to => "dashboard#index"
end

root :to => "pages#index"
end
Expand Down

0 comments on commit cd20c04

Please sign in to comment.