Sha256: a443745dc1b40a995509bcf7dc7d36518c019cc8f275b8ec53024e0a846d5981
Contents?: true
Size: 1.8 KB
Versions: 18
Compression:
Stored size: 1.8 KB
Contents
# `Controller` provides a scope for `controller.rb` files. # # Stasis will still create a `Controller` instance for directories without a # `controller.rb` file, mostly for the purposes of resolving paths and triggering plugin # events. class Stasis class Controller < Scope def initialize(stasis) @_stasis = stasis # Some plugins define methods to be made available to controller scopes. This call # binds those methods. @_stasis.plugins.each do |plugin| _bind_plugin(plugin, :controller_method) end end def _add(path) return unless File.file?(path) && File.basename(path) == 'controller.rb' # Temporarily set path variables. @_stasis.path = path # Change current working directory. Dir.chdir(File.dirname(path)) # Evaluate `controller.rb`. instance_eval(File.read(path), path) # Unset temporary path variables. @_stasis.path = nil end # Accepts three kinds of paths as the `path` parameter: # # * Absolute: `/project/path/view.haml` # * Relative: `view.haml` # * Root: `/path/view.haml` # # Returns an absolute path. # # Set the `force` parameter to `true` to return the resolved path even if no file # exists at that location. def _resolve(path, force=false) if path.nil? nil elsif path.is_a?(Regexp) path # If the path is relative... elsif path[0..0] != '/' && @_stasis.path && (File.file?(p = File.expand_path("#{File.dirname(@_stasis.path)}/#{path}")) || force) p # If the path is root... elsif File.file?(p = File.expand_path("#{@_stasis.root}/#{path}")) || force p # If the path is absolute... elsif File.file?(path) path else false end end end end
Version data entries
18 entries across 18 versions & 1 rubygems