module Simplec::ActionView::Helper
Public Instance Methods
doc(slug, options={})
click to toggle source
Retreive a document.
slug - matching a Document slug. options - a string matching a Subdomain name, find a document
from another subdomain
options - if true, casuse a 404 if document isn't found
Example:
-# Save as... <%= link_to doc('/permission/general').name, doc('/permission/general').path, download: true %> -# Display in new window... <%= link_to doc('/permission/general').name, doc('/permission/general').path, target: '_blank' %>
# File lib/simplec/action_view/helper.rb, line 46 def doc(slug, options={}) @_docs ||= Hash.new key = "[#{options[:subdomain]}][#{slug}]" return @_docs[key] if @_docs[key] @_docs[key] = subdomain(options[:subdomain]). documents.find_by(slug: slug) raise ActiveRecord::RecordNotFound if options[:raise] && !@_docs[key] @_docs[key] end
docset(slug, options={})
click to toggle source
Retreive a document.
slug - matching a Document slug. options - a string matching a Subdomain name, find a document
set from another subdomain
options - if true, casuse a 404 if document set isn't found
Example:
<% docset('/faith').each do |doc| %> <%= link_to doc.name, doc.path %> <% end %>
# File lib/simplec/action_view/helper.rb, line 69 def docset(slug, options={}) @_docsets ||= Hash.new key = "[#{options[:subdomain]}][#{slug}]" return @_docsets[key] if @_docsets[key] set = subdomain(options[:subdomain]). document_sets.find_by(slug: slug) raise ActiveRecord::RecordNotFound if options[:raise] && !set @_docsets[key] = set.documents end
head(page)
click to toggle source
# File lib/simplec/action_view/helper.rb, line 5 def head(page) content_for :title, page.title content_for :meta_description, page.meta_description end
meta_description_tag()
click to toggle source
# File lib/simplec/action_view/helper.rb, line 14 def meta_description_tag tag :meta, name: 'description', content: content_for(:meta_description) end
page_field(f, options={})
click to toggle source
# File lib/simplec/action_view/helper.rb, line 23 def page_field(f, options={}) render "simplec/fields/#{options[:type]}", options.merge(f: f) end
subpages(page_or_path, options={})
click to toggle source
page_or_path - a page object or a path of a page options - a string matching a Subdomain name, find a page
from another subdomain
options - if true, casuse a 404 if a page set isn't found
Example:
<% subpages('give-volunteer', conditions: ->{ order(title: :asc) }).each do |page| %> ... do something with page ... <% end%>
# File lib/simplec/action_view/helper.rb, line 89 def subpages(page_or_path, options={}) if options[:conditions] && !options[:conditions].respond_to?(:call) raise ArgumentError, <<-ERROR #{options[:conditions]} was passed as :conditions but is not callable. "Pass a callable instead: `conditions: -> { where(approved: true) }` ERROR end @_subpages ||= Hash.new # TODO apply new conditions after cache key = "[#{options[:subdomain]}][#{page_or_path}]" unless @_subpages[key] page = page_or_path.is_a?(Page) ? page_or_path : nil page ||= subdomain(options[:subdomain]).pages.find_by(path: page_or_path) unless page raise ActiveRecord::RecordNotFound if options[:raise] return @_subpages[key] = Array.new end @_subpages[key] = page.children.includes(:subdomain) end @_subpages[key].respond_to?(:merge) && options[:conditions] ? @_subpages[key].merge(options[:conditions]) : @_subpages[key] end
template(page)
click to toggle source
# File lib/simplec/action_view/helper.rb, line 18 def template(page) _template = page.type.demodulize.downcase render "pages/#{_template}" end
title()
click to toggle source
# File lib/simplec/action_view/helper.rb, line 10 def title content_for :title end