Sha256: ad55369fe2051fd43547daaeaf86efcb3f54b3707aa61e0a56e50a256bb1c264

Contents?: true

Size: 819 Bytes

Versions: 1

Compression:

Stored size: 819 Bytes

Contents

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
    #
    # @TODO: implement caching
    #
    def annex_block(identifier, opts = {})
      opts[:route] ||= current_route

      doc = Annex::Block.where(route: opts[:route]).first_or_create

      content = doc.content.try(:[], identifier.to_s) || opts[:default]

      render partial: 'annex/block', locals: { content: content, route: opts[:route], identifier: identifier, opts: opts }
    end

    def annex_clips(clip)
      render partial: 'annex/clips'
    end

    def current_route
      "#{I18n.locale}_#{params[:controller]}_#{params[:action]}".to_sym
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
annex-cms-0.1.8 lib/annex/view_helpers.rb