lib/stasis.rb in stasis-0.1.23 vs lib/stasis.rb in stasis-0.2.0.pre

- old
+ new

@@ -16,20 +16,22 @@ rescue Exception => e end # Activate the [Tilt][ti] gem. -gem "tilt", "~> 1.3.3" +gem "tilt", "1.3.3" # Add the project directory to the load paths. $:.unshift File.dirname(__FILE__) # Require all Stasis library files, except for 'stasis/dev_mode' and # 'stasis/server'. Those are demand-loaded when the corresponding command-line # options are passed. +require 'ext/string' + require 'stasis/options' require 'stasis/plugin' require 'stasis/scope' require 'stasis/scope/action' @@ -113,11 +115,11 @@ def load_controllers # Create a controller instance. @controller = Controller.new(self) # Reload controllers - Dir["#{@root}/**/controller.rb"].each do |path| + Dir["#{@root}/**/controller.rb"].sort.each do |path| @controller._add(path) unless path[0..@destination.length-1] == @destination end end def render(*only) @@ -177,20 +179,20 @@ # Set the extension if the `@path` extension is supported by [Tilt][ti]. ext = Tilt.mappings.keys.detect do |ext| File.extname(@path)[1..-1] == ext end + + # Change current working directory. + Dir.chdir(File.dirname(@path)) # Trigger all plugin `before_render` events. trigger(:before_render) # Skip if `@path` set to `nil`. next unless @path - # Change current working directory. - Dir.chdir(File.dirname(@path)) - # Render the view. view = # If the path has an extension supported by [Tilt][ti]... if ext # If the controller calls `render` within the `before` block for this @@ -292,11 +294,13 @@ end # Add a plugin to all existing controller instances. This method should be called by # all external plugins. def self.register(plugin) - @instances.each do |stasis| - stasis.add_plugin(plugin) + if @instances + @instances.each do |stasis| + stasis.add_plugin(plugin) + end end end # Trigger an event on every plugin in the controller. def trigger(type)