module Outpost
Super-simple breadcrumbs for you and me. Include it into a controller
Arguments: Pairs of strings. Title of breadcrumb, Path
Usage: In the controller:
class PostsController < ApplicationController def new breadcrumb "New", outpost_new_post_path @post = Post.new end end
This module then makes the “breadcrumbs” helper available to you (and me), which can be used in your view:
<% breadcrumbs.each do |crumb| %> <%= link_to crumb.title, crumb.link %> <% end %>
You can also define multiple breadcrumbs at once. Every 2 arguments is a new breadcrumb:
breadcrumb "Edit", outpost_edit_post_path(@post.id), @post.title, outpost_post_path(@post)
Don't want the crumb to be linked? Just leave the second argument off, or nil
if you're defining multiple breadcrumbs:
breadcrumb "Edit", nil, @post.title
Define configuration for Outpost
This provides basic CRUD actions for you to include into any controller that you want to behave like a resource management area.
Authorization
Basic authorization methods for controllers
Naming
Some naming helpers.
Example:
Outpost::Helpers::Naming.to_class("outpost/news_stories")
Filter
Identifier
Some unique keys which can be used for routing and APIs
This could be renamed to something more specific
Naming
Some methods for naming things, and stuff
Some test helpers
Constants
- ASCENDING
- DESCENDING
- OBJ_KEY_REGEX
- VERSION
Attributes
Public Class Methods
# File lib/outpost.rb, line 28 def config @config ||= Outpost::Config.new end
# File lib/outpost.rb, line 39 def obj_by_key(key) if match = match_key(key) model = model_classes[match[1]] model.find_by_id(match[2]) if model end end
# File lib/outpost.rb, line 49 def obj_by_key!(key) obj_by_key(key) or raise ActiveRecord::RecordNotFound end
TODO can we cache this in development?
# File lib/outpost.rb, line 33 def user_class config.user_class.constantize end
Private Class Methods
# File lib/outpost.rb, line 56 def match_key(key) key.to_s.match(OBJ_KEY_REGEX) end
# File lib/outpost.rb, line 62 def model_classes @model_classes ||= begin klasses = {} Outpost.config.registered_models.each do |name| klass = name.constantize klasses.merge!(klass.content_key => klass) end klasses end end