Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moving towards single controller model (untested)

  • Loading branch information...
commit af64d12c9d7ac15d0a61263c978bcae0186d841f 1 parent 8c526f4
@winton authored
View
200 lib/stasis.rb
@@ -54,20 +54,29 @@
class Stasis
- # `Hash` -- keys are directory paths, and values are instances of `Controller`.
- attr_reader :controllers
+ # `Action` -- changes with each iteration of the main loop within `Stasis#generate`.
+ attr_accessor :action
+
+ # `Controller` -- set to the same instance for the lifetime of the `Stasis` instance.
+ attr_accessor :controller
# `String` -- the destination path passed to `Stasis.new`.
- attr_reader :destination
+ attr_accessor :destination
# `Hash` -- options passed to `Stasis.new`.
- attr_reader :options
+ attr_accessor :options
+
+ # `String` -- changes with each iteration of the main loop within `Stasis#generate`.
+ attr_accessor :path
# `Array` -- all paths in the project that Stasis will act upon.
- attr_reader :paths
+ attr_accessor :paths
+
+ # `Array` -- `Plugin` instances.
+ attr_accessor :plugins
# `String` -- the root path passed to `Stasis.new`.
- attr_reader :root
+ attr_accessor :root
def initialize(root, destination=root+'/public', options={})
@destination = destination
@@ -82,14 +91,11 @@ def initialize(root, destination=root+'/public', options={})
!File.file?(path) || path[0..destination.length-1] == destination
end
- # Create a controller instance for each directory in the project.
- @controllers = @paths.inject({}) do |hash, path|
- unless hash[dir = File.dirname(path)]
- scope = Controller.new(dir, root)
- hash[dir] = scope
- end
- hash
- end
+ # Create plugin instances.
+ @plugins = find_plugins.collect { |klass| klass.new(self) }
+
+ # Create a controller instance.
+ @controller = Controller.new(self)
end
def generate(options={})
@@ -118,88 +124,74 @@ def generate(options={})
end
# Reject paths that are controllers.
- @paths.reject! { |p| File.basename(p) == 'controller.rb' }
+ @paths.reject! do |path|
+ if File.basename(path) == 'controller.rb'
+ # Add controller to `Controller` instance.
+ @controller._add(path) if match
+ true
+ else
+ false
+ end
+ end
- # Trigger all plugin `before_all` events, passing all `Controller` instances and
- # paths.
- @controllers, @paths = trigger(:before_all, '*', @controllers, @paths)
+ # Trigger all plugin `before_all` events.
+ trigger(:before_all, '*')
@paths.uniq.each do |path|
- dir = File.dirname(path)
- path_controller = @controllers[dir]
+ @path = path
+
+ dir = File.dirname(@path)
# If `:only` option specified...
unless options[:only].empty?
# Skip iteration unless there is a match.
next unless options[:only].any? do |only|
- (only.is_a?(::Regexp) && path =~ only) ||
- (only.is_a?(::String) && path == only)
+ (only.is_a?(::Regexp) && @path =~ only) ||
+ (only.is_a?(::String) && @path == only)
end
end
-
- # Sometimes the path doesn't actually exist, which means a `Controller` instance
- # does not exist yet.
- path_controller ||= Controller.new(dir, root)
# Create an `Action` instance, the scope for rendering the view.
- @action = Action.new(
- :path => path,
- :params => options[:params],
- :plugins => path_controller._[:plugins],
- :stasis => self
- )
-
- # Set the extension if the `path` extension is supported by [Tilt][ti].
+ @action = Action.new(self)
+
+ # 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
+ File.extname(@path)[1..-1] == ext
end
- # Trigger all plugin `before_render` events, passing the `Action` instance
- # and the current path.
- @action, path = trigger(:before_render, path, @action, path)
+ # Trigger all plugin `before_render` events.
+ trigger(:before_render)
# 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
+ # path, receive output from `@action._render`.
+ #
+ # Otherwise, render the file located at `@path`.
+ output = @action._render || @action.render(@path, :callback => false)
+
# If a layout was specified via the `layout` method...
- if @action._[:layout]
- # Grab the controller at the same directory level as the layout.
- layout_controller = @controllers[File.dirname(@action._[:layout])]
-
- controller(layout_controller) do
- # Render the layout with a block for the layout to `yield` to.
- @action.render(@action._[:layout]) do
- controller(path_controller) do
- # If the controller calls `render` within the `before` block for this
- # path, `_[:render]` is set to the output.
- #
- # Use `_[:render]` if present, otherwise render the file located at
- # `path`.
- @action._[:render] || @action.render(path, :callback => false)
- end
- end
- end
+ if @action._layout
+ # Render the layout with a block for the layout to `yield` to.
+ @action.render(@action._layout) { output }
# If a layout was not specified...
else
- controller(path_controller) do
- # Use `_[:render]` if present, otherwise render the file located at `path`.
- @action._[:render] || @action.render(path, :callback => false)
- end
+ output
end
# If the path does not have an extension supported by [Tilt][ti] and `render` was
# called within the `before` block for this path...
- elsif @action._[:render]
- @action._[:render]
+ elsif @action._render
+ @action._render
end
- # Trigger all plugin `after_render` events, passing the `Action` instance and the
- # current path.
- @action, path = trigger(:after_render, path, @action, path)
+ # Trigger all plugin `after_render` events.
+ trigger(:after_render)
# Cut the `root` out of the `path` to get the relative destination.
- dest = path[root.length..-1]
+ dest = @path[root.length..-1]
# Add `destination` (as specified from `Stasis.new`) to front of relative
# destination.
@@ -223,80 +215,54 @@ def generate(options={})
f.write(view)
end
# If markup was not rendered and the path exists...
- elsif File.exists?(path)
+ elsif File.exists?(@path)
# Copy the file located at the path to the destination path.
- FileUtils.cp(path, dest)
+ FileUtils.cp(@path, dest)
end
end
- # Trigger all plugin `after_all` events, passing all `Controller` instances and
- # paths.
- @controllers, @paths = trigger(:after_all, '*', @controllers, @paths)
+ # Trigger all plugin `after_all` events, passing the `Stasis` instance.
+ trigger(:after_all, '*')
end
# Add a plugin to all existing controller instances. This method should be called by
# all external plugins.
def self.register(plugin)
- ObjectSpace.each_object(::Stasis::Controller) do |controller|
- plugin = plugin.new
- controller._[:plugins] << plugin
- controller._bind_plugin(plugin, :controller_method)
+ plugin = plugin.new
+ ObjectSpace.each_object(::Stasis) do |stasis|
+ stasis.plugins << plugin
+ stasis.controllers.each do |controller|
+ controller._bind_plugin(plugin, :controller_method)
+ end
end
end
- # Trigger an event on every plugin in certain controllers (depending on the `path`
- # parameter).
- def trigger(type, path, *args, &block)
+ # Trigger an event on every plugin in the controller.
+ def trigger(type)
each_priority do |priority|
- # Trigger event on all plugins in every controller.
- if path == '*'
- @controllers.values.each do |controller|
- args = controller._send_to_plugin(priority, type, *args, &block)
- end
- # Trigger event on all plugins in certain controllers (see `each_directory`).
- else
- each_directory(path) do |dir|
- if cont = @controllers[dir]
- controller(cont) do
- args = cont._send_to_plugin(priority, type, *args, &block)
- end
- end
- end
- end
+ args = @controller._send_to_plugin(priority, type)
end
args
end
private
- # Sets `_[:controller]` on the current `Action` instance for the duration of
- # the block and returns the output of the block.
- def controller(controller, &block)
- old_controller = @action._[:controller]
- @action._[:controller] = controller
- output = yield
- @action._[:controller] = old_controller
- output
- end
-
- # Iterate through every directory between `root` and `path` (inclusive) and yield each
- # directory to a block.
- def each_directory(path, &block)
- yield(root)
- dirs = File.dirname(path)[root.length+1..-1]
- if dirs
- dirs = dirs.split('/')
- dirs.each do |dir|
- yield("#{root}/#{dir}")
- end
- end
- end
-
# Iterate through plugin priority integers (sorted) and yield each to a block.
def each_priority(&block)
- priorities = Controller.find_plugins.collect do |klass|
- klass._[:priority]
+ priorities = @plugins.collect do |klass|
+ klass._priority || 0
end
priorities.uniq.sort.each(&block)
end
+
+ # Returns an `Array` of `Stasis::Plugin` classes.
+ def find_plugins
+ plugins = []
+ ObjectSpace.each_object(Class) do |klass|
+ if klass < ::Stasis::Plugin
+ plugins << klass
+ end
+ end
+ plugins
+ end
end
View
28 lib/stasis/plugin.rb
@@ -2,15 +2,16 @@ class Stasis
class Plugin
class <<self
- # The class variable is named `@_` so that there is little likelihood that a
- # user-defined variable will conflict.
- attr_accessor :_
+ # `Hash` -- Keys are the "bind as" method names and values are the actual method
+ # names on the `Plugin` instance.
+ attr_accessor :_methods
- # Here we define class methods that only exist to store method names. Each method
- # can accept either an `Array` or a `Hash` of method names. `Hash` parameters only
- # make sense when used with bind methods (`action_method` and `controller_method`),
- # i.e. `{ :bind_as_method => :real_method }`. `Array` parameters are stored as a
- # `Hash` for continuity.
+ # `Fixnum` -- The execution priority for this plugin (defaults to 0).
+ attr_accessor :_priority
+
+ # The methods in this `Array` essentially all take the same kind of parameters.
+ # Either a `Hash` or an `Array` of method names. No matter what, the input is
+ # converted to a `Hash` (see `_methods`).
%w(
action_method
after_all
@@ -23,11 +24,11 @@ class <<self
# Define method on the `Plugin` class.
define_method(method) do |*methods|
# Set defaults on the `_` class variable.
- self._ ||= { :methods => {}, :priority => 0 }
- self._[:methods][method] ||= {}
+ self._methods ||= {}
+ self._methods[method] ||= {}
# If passing a `Hash`...
if methods[0].is_a?(::Hash)
- self._[:methods][method].merge!(methods[0])
+ self._methods[method].merge!(methods[0])
# If passing an `Array`...
else
# Generate `Hash` from `Array`.
@@ -35,15 +36,14 @@ class <<self
hash[m] = m
hash
end
- self._[:methods][method].merge!(methods)
+ self._methods[method].merge!(methods)
end
end
end
# Class method to set priority on the `Plugin`.
def priority(number)
- self._ ||= { :methods => {}, :priority => 0 }
- self._[:priority] = number
+ self._priority = number
end
end
View
23 lib/stasis/plugins/before.rb
@@ -6,17 +6,18 @@ class Before < Plugin
controller_method :before
priority 1
- def initialize
+ def initialize(stasis)
+ @stasis = stasis
@blocks = {}
end
# This method is bound to all controllers. Stores a block in the `@blocks` `Hash`,
# where the key is a path and the value is an `Array` of blocks.
- def before(controller, *paths, &block)
- paths = [ nil ] if paths.empty?
+ def before(&block)
+ paths = [ nil ] if stasis.paths.empty?
if block
- paths.each do |path|
- path = controller._resolve(path, true)
+ @stasis.paths.each do |path|
+ path = @stasis.controller._resolve(path, true)
@blocks[path] ||= []
@blocks[path] << block
end
@@ -28,24 +29,20 @@ def before(controller, *paths, &block)
# This event triggers before all files render. When a `before` call receives a path
# that does not exist, we want to create that file dynamically. This method adds
# those dynamic paths to the `paths` `Array`.
- def before_all(controller, controllers, paths)
+ def before_all
new_paths = (@blocks || {}).keys.select do |path|
path.is_a?(::String)
end
- [ controller, controllers, (paths + new_paths).uniq ]
end
# This event triggers before each file renders through Stasis. It finds matching
# blocks for the `path` and evaluates those blocks using the `action` as a scope.
- def before_render(controller, action, path)
- if @blocks && matches = _match_key?(@blocks, path)
- action._[:path] = path
+ def before_render
+ if @blocks && matches = _match_key?(@blocks, @stasis.path)
matches.flatten.each do |block|
- action.instance_eval(&block)
+ @stasis.action.instance_eval(&block)
end
- action._[:path] = nil
end
- [ controller, action, path ]
end
end
end
View
10 lib/stasis/plugins/helpers.rb
@@ -4,21 +4,21 @@ class Helpers < Plugin
controller_method :helpers
before_render :before_render
- def initialize
+ def initialize(stasis)
+ @stasis = stasis
@blocks = []
end
# This event triggers before each file renders through Stasis. For each helper
# `block`, evaluate the `block` in the scope of the `action` class.
- def before_render(controller, action, path)
+ def before_render
@blocks.each do |block|
- action.class.class_eval(&block)
+ @stasis.action.class.class_eval(&block)
end
- [ controller, action, path ]
end
# This method is bound to all controllers. Stores a block in the `@blocks` `Array`.
- def helpers(controller, &block)
+ def helpers(&block)
if block
@blocks << block
end
View
12 lib/stasis/plugins/ignore.rb
@@ -4,15 +4,16 @@ class Ignore < Plugin
before_all :before_all
controller_method :ignore
- def initialize
+ def initialize(stasis)
+ @stasis = stasis
@ignore = []
end
# This event triggers before all files render. Rejects any `paths` that are included
# in the `@ignore` `Array`.
- def before_all(controller, controllers, paths)
+ def before_all
@ignore.each do |ignore|
- paths.reject! do |path|
+ @stasis.paths.reject! do |path|
if ignore.is_a?(::String)
ignore == path
elsif ignore.is_a?(::Regexp)
@@ -22,14 +23,13 @@ def before_all(controller, controllers, paths)
end
end
end
- [ controller, controllers, paths ]
end
# This method is bound to all controllers. Adds an `Array` of paths to the `@ignore`
# `Array`.
- def ignore(controller, *array)
+ def ignore(*array)
@ignore += array.collect do |path|
- path = controller._resolve(path)
+ path = @stasis.controller._resolve(path)
path ? path : nil
end
@ignore.compact!
View
4 lib/stasis/plugins/instead.rb
@@ -4,8 +4,8 @@ class Instead < Plugin
action_method :instead
# This method is bound to all actions.
- def instead(action, string)
- action._[:render] = string
+ def instead(string)
+ action._render = string
end
end
end
View
30 lib/stasis/plugins/layout.rb
@@ -5,34 +5,32 @@ class Layout < Plugin
before_render :before_render
controller_method :layout => :layout_controller
- def initialize
+ def initialize(stasis)
+ @stasis = stasis
@layouts = {}
end
# This event triggers before each file renders through Stasis. It sets the `action`
# layout from the matching layout for `path`.
- def before_render(controller, action, path)
- if @layouts && match = _match_key?(@layouts, path)[0]
- action._[:layout] = match
+ def before_render
+ if @layouts && match = _match_key?(@layouts, @stasis.path)[0]
+ @stasis.action._layout = match
else
- action._[:layout] = nil
+ @stasis.action._layout = nil
end
- [ controller, action, path ]
end
- # This method is bound to all actions. Add the resolved path to `@layouts` and set
- # the `action` layout.
- def layout_action(action, path)
- if p = action._[:controller]._resolve(path)
- @layouts[action._[:path]] = p
- before_render(nil, action, action._[:path])
+ # This method is bound to all actions. Set the `action` layout.
+ def layout_action(path)
+ if p = @stasis.controller._resolve(path)
+ @stasis.action._layout = p
end
end
# This method is bound to all controllers. If it receives a `String` as a parameter,
# use that layout for all paths. Otherwise, it receives a `Hash` with the key being
# the `path` and the value being the layout to use for that `path`.
- def layout_controller(controller, hash_or_string)
+ def layout_controller(hash_or_string)
if hash_or_string.is_a?(::String)
hash = {}
hash[/.*/] = hash_or_string
@@ -40,9 +38,9 @@ def layout_controller(controller, hash_or_string)
hash = hash_or_string
end
@layouts.merge! hash.inject({}) { |hash, (key, value)|
- key = controller._resolve(key)
- hash[key] = controller._resolve(value)
- controller.ignore(hash[key])
+ key = @stasis.controller._resolve(key)
+ hash[key] = @stasis.controller._resolve(value)
+ @stasis.controller.ignore(hash[key])
hash
}
end
View
29 lib/stasis/plugins/priority.rb
@@ -6,43 +6,36 @@ class Priority < Plugin
controller_method :priority
priority 2
- def initialize
- @@priorities ||= {}
- end
-
- # This event triggers after all files render through Stasis. Reset `@@priorities`.
- def after_all(controller, controllers, paths)
- @@priorities = {}
- [ controller, controllers, paths ]
+ def initialize(stasis)
+ @stasis = stasis
+ @priorities = {}
end
# This event triggers before all files render through Stasis. Collect matching
# `paths` and sort those `paths` by priority.
- def before_all(controller, controllers, paths)
- paths.collect! do |path|
+ def before_all
+ @stasis.paths.collect! do |path|
priority = 0
- @@priorities.each do |key, value|
+ @priorities.each do |key, value|
if (key.is_a?(::Regexp) && path =~ key) || key == path
priority = value
end
end
[ path, priority ]
end
- paths.sort! { |a, b| b[1] <=> a[1] }
- paths.collect! { |(path, priority)| path }
- @@priorities = {}
- [ controller, controllers, paths ]
+ @stasis.paths.sort! { |a, b| b[1] <=> a[1] }
+ @stasis.paths.collect! { |(path, priority)| path }
end
# This method is bound to all controllers. Stores a priority integer in the
# `@@priorities` `Hash`, where the key is a path and the value is the priority.
- def priority(controller, hash)
+ def priority(hash)
hash = hash.inject({}) do |hash, (key, value)|
- key = controller._resolve(key)
+ key = @stasis.controller._resolve(key)
hash[key] = value if key
hash
end
- @@priorities.merge!(hash)
+ @priorities.merge!(hash)
end
end
end
View
33 lib/stasis/plugins/render.rb
@@ -5,8 +5,12 @@ class Render < Plugin
action_method :render
+ def initialize(stasis)
+ @stasis = stasis
+ end
+
# This method is bound to all actions.
- def render(action, path_or_options={}, options={}, &block)
+ def render(path_or_options={}, options={}, &block)
if path_or_options.is_a?(::String)
options[:path] = path_or_options
else
@@ -19,8 +23,8 @@ def render(action, path_or_options={}, options={}, &block)
scope = options[:scope]
text = options[:text]
- if action._[:controller]
- path = action._[:controller]._resolve(path)
+ if @stasis.controller
+ path = @stasis.controller._resolve(path)
end
output =
@@ -28,9 +32,10 @@ def render(action, path_or_options={}, options={}, &block)
text
elsif File.file?(path)
unless callback == false
- # Trigger all plugin `before_render` events, passing the `Action` instance
- # and the current path.
- action, path = action._[:stasis].trigger(:before_render, path, action, path)
+ # Trigger all plugin `before_render` events.
+ temporary_path(path) do
+ @stasis.trigger(:before_render)
+ end
end
output =
@@ -42,9 +47,10 @@ def render(action, path_or_options={}, options={}, &block)
end
unless callback == false
- # Trigger all plugin `after_render` events, passing the `Action` instance and the
- # current path.
- action, path = action._[:stasis].trigger(:after_render, path, action, path)
+ # Trigger all plugin `after_render` events.
+ temporary_path(path) do
+ action, path = @stasis.trigger(:after_render)
+ end
end
output
@@ -52,5 +58,14 @@ def render(action, path_or_options={}, options={}, &block)
output
end
+
+ private
+
+ # Temporarily set `Stasis#path`.
+ def temporary_path(path, &block)
+ @stasis.path, old_path = path, @stasis.path
+ yield
+ @stasis.path = old_path
+ end
end
end
View
29 lib/stasis/scope.rb
@@ -1,20 +1,18 @@
class Stasis
class Scope
- # The class variable is named `@_` so that there is little likelihood that a
- # user-defined variable will conflict.
- attr_reader :_
+ # `Stasis`.
+ attr_accessor :_stasis
# Plugins use the `controller_method` and `action_method` class methods to bind
# plugin methods to a scope instance. This method does the binding.
def _bind_plugin(plugin, type)
_each_plugin_method(plugin, type) do |plugin, method, real_method|
self.instance_eval <<-EVAL
+ # Define a method on `self` (the `Scope` instance).
def #{method}(*args, &block)
- # Define a method on `self` (the `Scope` instance).
- args = [ self ] + args
# Find the plugin.
- plugin = self._[:plugins].detect do |plugin|
+ plugin = self._stasis.plugins.detect do |plugin|
plugin.to_s == "#{plugin.to_s}"
end
# Pass parameters to the method on the plugin.
@@ -28,7 +26,7 @@ def _each_plugin_method(plugin, type, &block)
# Retrieve plugin `methods`: a `Hash` whose keys are the method name to bind to
# `self`, and whose values are the method name on the `Plugin` class we are
# binding from.
- methods = plugin.class._[:methods][type] || {}
+ methods = plugin.class._methods[type] || {}
methods.each do |method, real_method|
yield(plugin, method, real_method)
end
@@ -36,23 +34,18 @@ def _each_plugin_method(plugin, type, &block)
def _each_plugins_method(type, &block)
# For each plugin...
- _[:plugins].each do |plugin|
+ _stasis.plugins.each do |plugin|
_each_plugin_method(plugin, type, &block)
end
end
- # Using all `Plugin` instances of a certain priority, grab methods of a certain
- # `type` and send the arguments to those methods.
- def _send_to_plugin(priority, type, *args, &block)
+ # Using all `Plugin` instances of a certain priority, call methods of a certain type.
+ def _send_to_plugin(priority, type)
_each_plugins_method(type) do |plugin, method, real_method|
# If priority matches and plugin responds to method...
- if plugin.class._[:priority] == priority && plugin.respond_to?(real_method)
- # Add `Scope` instance as first parameter.
- args = [ self ] + args
- # Send arguments to plugin method.
- args = plugin.send(real_method, *args, &block)
- # Remove `Scope` instance as first parameter.
- args = args[1..-1]
+ if plugin.class._priority == priority && plugin.respond_to?(real_method)
+ # Call plugin method.
+ plugin.send(real_method)
end
end
args
View
18 lib/stasis/scope/action.rb
@@ -6,22 +6,18 @@
class Stasis
class Action < Scope
- attr_reader :params
+ # `String` -- Path to the layout for this action.
+ attr_accessor :_layout
- def initialize(options)
- # `Hash` -- Contains two key/value pairs:
- #
- # * `path` -- Path of the view that this instance provides a scope for.
- # * `plugins` -- `Array` of `Plugin` instances.
- # * `stasis` -- A reference to the `Stasis` instance that created this `Action`.
- @_ = options
+ # `String` -- If present, render this path instead of the default.
+ attr_accessor :_render
- # `Hash` -- Passed from the `params` option given to `Stasis#generate`.
- @params = options[:params]
+ def initialize(stasis)
+ @_stasis = stasis
# Some plugins define methods to be made available to action scopes. This call
# binds those methods.
- @_[:plugins].each do |plugin|
+ @_stasis.plugins.each do |plugin|
_bind_plugin(plugin, :action_method)
end
end
View
49 lib/stasis/scope/controller.rb
@@ -7,30 +7,27 @@
class Stasis
class Controller < Scope
- def initialize(dir, root)
- dir = File.expand_path(dir)
- path = "#{dir}/controller.rb"
- path = nil unless File.file?(path)
-
- @_ = {
- # Directory for which this controller provides a scope.
- :dir => dir,
- # Path to the `controller.rb` file (if it exists).
- :path => path,
- # A new instance of all known plugins.
- :plugins => self.class.find_plugins.collect { |klass| klass.new },
- # The root directory path of the user's project.
- :root => root
- }
+ def initialize(stasis)
+ @_stasis = stasis
# Some plugins define methods to be made available to controller scopes. This call
# binds those methods.
- @_[:plugins].each do |plugin|
+ @_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
+
# Evaluate `controller.rb`.
- instance_eval(File.read(path), path) if path
+ instance_eval(File.read(path), path)
+
+ # Unset temporary path variables.
+ @_stasis.path = nil
end
# Accepts three kinds of paths as the `path` parameter:
@@ -49,10 +46,10 @@ def _resolve(path, force=false)
elsif path.is_a?(Regexp)
path
# If the path is relative...
- elsif path[0..0] != '/' && (File.file?(p = File.expand_path("#{_[:dir]}/#{path}")) || force)
+ elsif path[0..0] != '/' && (File.file?(p = File.expand_path("#{File.dirname(path)}/#{path}")) || force)
p
# If the path is root...
- elsif File.file?(p = File.expand_path("#{_[:root]}/#{path}")) || force
+ elsif File.file?(p = File.expand_path("#{@_stasis.root}/#{path}")) || force
p
# If the path is absolute...
elsif File.file?(path)
@@ -61,19 +58,5 @@ def _resolve(path, force=false)
false
end
end
-
- class <<self
-
- # Returns an `Array` of `Stasis::Plugin` classes.
- def find_plugins
- plugins = []
- ObjectSpace.each_object(Class) do |klass|
- if klass < ::Stasis::Plugin
- plugins << klass
- end
- end
- plugins
- end
- end
end
end
View
1  site/stasis.js.coffee
@@ -6,6 +6,7 @@ smoothScroll = ->
$('html, body').animate { scrollTop: target.offset().top - 60 }, 400, ->
unless ran
offset = this.scrollTop
+ location.hash = anchor
this.scrollTop = offset
ran = true
false
Please sign in to comment.
Something went wrong with that request. Please try again.