Module: Simplec::ActionView::Helper
- Defined in:
- lib/simplec/action_view/helper.rb
Instance Method Summary collapse
-
#doc(slug, options = {}) ⇒ Object
Retreive a document.
-
#docset(slug, options = {}) ⇒ Object
Retreive a document.
- #head(page) ⇒ Object
- #meta_description_tag ⇒ Object
- #page_field(f, options = {}) ⇒ Object
- #subpages(page_or_path, options = {}) ⇒ Object
- #template(page) ⇒ Object
- #title ⇒ Object
Instance Method Details
#doc(slug, options = {}) ⇒ Object
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' %>
46 47 48 49 50 51 52 53 54 |
# File 'lib/simplec/action_view/helper.rb', line 46 def doc(slug, ={}) @_docs ||= Hash.new key = "[#{options[:subdomain]}][#{slug}]" return @_docs[key] if @_docs[key] @_docs[key] = subdomain([:subdomain]). documents.find_by(slug: slug) raise ActiveRecord::RecordNotFound if [:raise] && !@_docs[key] @_docs[key] end |
#docset(slug, options = {}) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/simplec/action_view/helper.rb', line 69 def docset(slug, ={}) @_docsets ||= Hash.new key = "[#{options[:subdomain]}][#{slug}]" return @_docsets[key] if @_docsets[key] set = subdomain([:subdomain]). document_sets.find_by(slug: slug) raise ActiveRecord::RecordNotFound if [:raise] && !set @_docsets[key] = set.documents end |
#head(page) ⇒ Object
5 6 7 8 |
# File 'lib/simplec/action_view/helper.rb', line 5 def head(page) content_for :title, page.title content_for :meta_description, page. end |
#meta_description_tag ⇒ Object
14 15 16 |
# File 'lib/simplec/action_view/helper.rb', line 14 def tag :meta, name: 'description', content: content_for(:meta_description) end |
#page_field(f, options = {}) ⇒ Object
23 24 25 |
# File 'lib/simplec/action_view/helper.rb', line 23 def page_field(f, ={}) render "simplec/fields/#{options[:type]}", .merge(f: f) end |
#subpages(page_or_path, options = {}) ⇒ Object
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%>
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/simplec/action_view/helper.rb', line 89 def subpages(page_or_path, ={}) if [:conditions] && ![:conditions].respond_to?(:call) raise ArgumentError, " \#{options[:conditions]} was passed as :conditions but is not callable.\n\"Pass a callable instead: `conditions: -> { where(approved: true) }`\n ERROR\n end\n\n @_subpages ||= Hash.new # TODO apply new conditions after cache\n key = \"[\#{options[:subdomain]}][\#{page_or_path}]\"\n\n unless @_subpages[key]\n page = page_or_path.is_a?(Page) ? page_or_path : nil\n page ||= subdomain(options[:subdomain]).pages.find_by(path: page_or_path)\n\n unless page\n raise ActiveRecord::RecordNotFound if options[:raise]\n return @_subpages[key] = Array.new\n end\n\n @_subpages[key] = page.subpages\n end\n\n @_subpages[key].respond_to?(:merge) && options[:conditions] ?\n @_subpages[key].merge(options[:conditions]) : @_subpages[key]\nend\n" |
#template(page) ⇒ Object
18 19 20 21 |
# File 'lib/simplec/action_view/helper.rb', line 18 def template(page) _template = page.type.demodulize.downcase render "pages/#{_template}" end |
#title ⇒ Object
10 11 12 |
# File 'lib/simplec/action_view/helper.rb', line 10 def title content_for :title end |