myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [3475] trunk/app: Made skin code more durable


From: noreply
Subject: [myexperiment-hackers] [3475] trunk/app: Made skin code more durable
Date: Thu, 7 Mar 2013 14:15:35 +0000 (UTC)

Revision
3475
Author
fbacall
Date
2013-03-07 14:15:35 +0000 (Thu, 07 Mar 2013)

Log Message

Made skin code more durable

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/app/controllers/application_controller.rb (3474 => 3475)


--- trunk/app/controllers/application_controller.rb	2013-03-07 13:40:48 UTC (rev 3474)
+++ trunk/app/controllers/application_controller.rb	2013-03-07 14:15:35 UTC (rev 3475)
@@ -542,24 +542,43 @@
     end
   end
 
-  #Selects layout for contributables/groups or uses site's default
+  # Selects layout (aka skin) for contributables/groups or uses site's default.
+  # Sets a variable that is used for choosing the right stylesheets etc., then returns the layout name for rails
+  #  to render the view with.
   def configure_layout
     contributable = (@workflow || @pack || @blob)
     layout = nil
 
+    # For testing skins
     if params["layout_preview"]
       layout = Conf.layouts[params["layout_preview"]]
+    # Skins on resources
     elsif contributable && contributable.contribution && contributable.contribution.policy
-      layout = Conf.layouts[contributable.contribution.policy.layout]
-      if contributable.contribution.policy.layout && layout.nil?
-        logger.error("Missing layout for #{contributable.class.name} #{contributable.id}: "+
-                    "#{contributable.contribution.policy.layout}")
+      if contributable.contribution.policy.layout
+        layout = Conf.layouts[contributable.contribution.policy.layout]
+        if layout.nil?
+          logger.error("Missing layout for #{contributable.class.name} #{contributable.id}: "+
+                      "#{contributable.contribution.policy.layout}")
+        end
       end
+    # Skins on groups, or when in a group context
     elsif (network = @network) || (@context.is_a?(Network) && (network = @context))
       layout = network.layout
     end
 
-    @layout = layout || {"layout" => 'application', "stylesheets" => [Conf.stylesheet]}
+    # Check skin exists
+    if layout && layout["layout"] && !File.exists?("#{RAILS_ROOT}/app/views/layouts/#{layout["layout"]}.html.erb")
+      logger.error("Missing layout #{RAILS_ROOT}/app/views/layouts/#{layout["layout"]}.html.erb")
+      layout = nil
+    end
+
+    # Use default skin if all else fails
+    if layout.nil?
+      @layout = {"layout" => 'application', "stylesheets" => [Conf.stylesheet]}
+    else
+      @layout = layout
+    end
+
     @layout["layout"]
   end
 

Copied: trunk/app/views/layouts/application.html.erb (from rev 3472, trunk/app/views/layouts/application.rhtml) (0 => 3475)


--- trunk/app/views/layouts/application.html.erb	                        (rev 0)
+++ trunk/app/views/layouts/application.html.erb	2013-03-07 14:15:35 UTC (rev 3475)
@@ -0,0 +1 @@
+<%= render :partial => Conf.page_template %>

Deleted: trunk/app/views/layouts/application.rhtml (3474 => 3475)


--- trunk/app/views/layouts/application.rhtml	2013-03-07 13:40:48 UTC (rev 3474)
+++ trunk/app/views/layouts/application.rhtml	2013-03-07 14:15:35 UTC (rev 3475)
@@ -1 +0,0 @@
-<%= render :partial => Conf.page_template %>

reply via email to

[Prev in Thread] Current Thread [Next in Thread]