lib/annex/view_helpers.rb in annex-cms-0.2.1 vs lib/annex/view_helpers.rb in annex-cms-0.3.0

- old
+ new

@@ -1,25 +1,29 @@ -require 'active_support/hash_with_indifferent_access' - module Annex # # Create global view helpers # module ViewHelpers # # annex_block is a universal helper to render content from - # mongodb and display it on the page + # the database and display it on the page # - # @TODO: implement caching - # def annex_block(identifier, opts = {}) opts[:route] ||= current_route - doc = Annex::Block.where(route: opts[:route]).first_or_create + case Annex::config[:adapter] - content = doc.content.try(:[], identifier.to_s) || opts[:default] + when :activerecord + doc = Annex::Block.where(route: "#{opts[:route]}_#{identifier}").first_or_create + content = doc.content - render partial: 'annex/block', locals: { content: content, identifier: identifier, opts: opts } + when :mongoid + doc = Annex::Block.where(route: opts[:route]).first_or_create + content = doc.content.try(:[], identifier.to_s) + + end + + render partial: 'annex/block', locals: { content: content || opts[:default], identifier: identifier, opts: opts } end def current_route "#{I18n.locale}_#{params[:controller]}_#{params[:action]}".to_sym end