Skip to content

Commit

Permalink
Built Content Resources so they show up in Smithy navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Glen committed Aug 26, 2015
1 parent 46125cc commit 9a5163f
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require_dependency "smithy/base_controller"

class Smithy::ContentPiecesController < Smithy::BaseController
class Smithy::ContentResourcesController < Smithy::BaseController
before_filter :set_controller_path
respond_to :html, :json

Expand Down Expand Up @@ -56,7 +56,7 @@ def destroy
private
def klass
# override to provide an object for each class
raise "You must inherit from this Smithy::ContentPiecesController and provide a private #klass method"
raise "You must inherit from this Smithy::ContentResourcesController and provide a private #klass method"
end

def klass_name
Expand Down
3 changes: 3 additions & 0 deletions app/views/layouts/smithy/shared/_nav.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<ul class="nav">
<li><%= link_to "<i class=\"icon-sitemap\"></i> Manage Content".html_safe, pages_path %></li>
<li><%= link_to "<i class=\"icon-file\"></i> Images &amp; Files".html_safe, assets_path %></li>
<% Smithy::ContentResources::Registry.content_resources.each do |controller_name, title| %>
<li><%= link_to title, controller_name.to_sym %></li>
<% end %>
</ul>
<ul class="nav pull-right">
<li><%= link_to "<i class=\"icon-arrow-right\"></i> View Site".html_safe, root_path %></li>
Expand Down
3 changes: 1 addition & 2 deletions lib/smithy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
require 'smithy/formatter'
#
require 'smithy/content_blocks'
require 'smithy/content_resources'

module Smithy

def self.log(*args)
level = args.size == 1 ? 'info' : args.first
message = args.size == 1 ? args.first : args.last
::Smithy::Logger.send(level.to_sym, message)
end

end
39 changes: 0 additions & 39 deletions lib/smithy/content_pieces/registry.rb

This file was deleted.

2 changes: 2 additions & 0 deletions lib/smithy/content_resources.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'smithy/content_resources/base'
require 'smithy/content_resources/registry'
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module Smithy
module ContentPieces
module ContentResources
module Base
extend ActiveSupport::Concern
included do
Smithy::ContentPieces::Registry.register self
Smithy::ContentResources::Registry.register self
end
end
end
Expand Down
31 changes: 31 additions & 0 deletions lib/smithy/content_resources/registry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'active_support/concern'

module Smithy
module ContentResources
class Registry
@@content_resources = []

class << self
def clear
@@content_resources = []
end

def content_resources
@@content_resources
end

def register(content_resource_model_name, navigation_title=nil)
return if @@content_resources.include?(content_resource_model_name)
navigation_title ||= content_resource_model_name.to_s.titleize.pluralize
@@content_resources << [content_resource_model_name.to_s.tableize, navigation_title]
Smithy::Engine.routes.prepend do
scope '/smithy/content_resources' do
resources content_resource_model_name.to_s.tableize
end
end
@@content_resources
end
end
end
end
end

0 comments on commit 9a5163f

Please sign in to comment.