Class: RailsBridge::LayoutBridgeController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/rails_bridge/layout_bridge_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/rails_bridge/layout_bridge_controller.rb', line 3

def index
  paths = self.view_paths
  @layouts = {}
  paths.each do |path|
    layouts_path = File.join(path, 'layouts', '*.{erb,haml}')
    files = Dir.glob( File.join(path, 'layouts', '*.{erb,haml}') )
    files.each do |file|
      name = File.basename(file).split('.').first
      next if name =~ /^_.*/ # ignore partials
      @layouts[name] ||= file # only the first matching layout in the views path is accessible
    end
  end
  
end

#showObject



18
19
20
21
22
23
24
25
26
# File 'app/controllers/rails_bridge/layout_bridge_controller.rb', line 18

def show
  @layout_name = params[:id]
  custom_content_path = File.join( Rails.root, RailsBridge::LAYOUTS_PATH, @layout_name )
  bridge_views_path = File.join( Rails.root, RailsBridge::VIEWS_PATH )
  self.prepend_view_path(custom_content_path)
  self.prepend_view_path(bridge_views_path)
  string = replace_relative_urls( render_to_string :layout=>@layout_name, :template=>'content' )
  render :text=>string, :content_type=>'text/plain'
end