Module: Cms::ApplicationHelper
- Defined in:
- app/helpers/cms/application_helper.rb
Instance Method Summary collapse
- #action_icon(name, options = {}) ⇒ Object
- #action_icon_src(name) ⇒ Object
-
#add_button(path, options = {bootstrap: false}) ⇒ Object
Render a CMS styled ‘Add’ button.
-
#categories_for(category_type_name, order = "name") ⇒ Object
deprecated
Deprecated.
Use <%= f.association :categories %> instead.
-
#check_uncheck_tag(selector) ⇒ Object
Renders two links that will check/uncheck a set of checkboxes.
- #cms_handler_path(*args) ⇒ Object deprecated Deprecated.
- #determine_order(current_order, order) ⇒ Object
- #dk_button_wrapper(content) ⇒ Object
-
#draft_icon_tag(content, options = {}) ⇒ String
Generate HTML for draft icon for content that are in draft.
-
#edit_button(options = {bootstrap: false}) ⇒ Object
deprecated
Deprecated.
Use link_to
- #format_date(time) ⇒ Object
- #group_filter ⇒ Object
- #group_ids ⇒ Object
-
#link_to_check_all(selector, name = "Check All") ⇒ Object
deprecated
Deprecated.
Use check_uncheck_tag instead. Retained for backwards compatibility w/ CMS implementations.
-
#link_to_uncheck_all(selector, name = "Uncheck All") ⇒ Object
deprecated
Deprecated.
Use check_uncheck_tag instead. Retained for backwards compatibility w/ CMS implementations.
- #page_versions(page) ⇒ Object
-
#preview_content_path(content) ⇒ Object
Generate the proper link to Preview a Page or Addressable content block (based on type).
-
#render_pagination(collection, content_type, options = {}) ⇒ Object
Generates the HTML to render a paging control, if there is more than one page to be shown.
- #searchable_sections(selected = nil) ⇒ Object
- #select_per_page ⇒ Object
- #span_tag(content) ⇒ Object
- #status_icon(status, options = {}) ⇒ Object
- #time_on_date(time) ⇒ Object
- #url_with_mode(url, mode) ⇒ Object
Instance Method Details
#action_icon(name, options = {}) ⇒ Object
59 60 61 |
# File 'app/helpers/cms/application_helper.rb', line 59 def action_icon(name, ={}) image_tag action_icon_src(name), {:alt => name.to_s.titleize}.merge() end |
#action_icon_src(name) ⇒ Object
55 56 57 |
# File 'app/helpers/cms/application_helper.rb', line 55 def action_icon_src(name) "cms/icons/actions/#{name}.png" end |
#add_button(path, options = {bootstrap: false}) ⇒ Object
Render a CMS styled ‘Add’ button. This button will appear on tool bars, typically set apart visually from other buttons.
239 240 241 242 243 244 |
# File 'app/helpers/cms/application_helper.rb', line 239 def (path, ={bootstrap: false}) classes = () label = [:bootstrap]? "Add" : span_tag(" Add ".html_safe) = {:class => classes} link_to label, path, end |
#categories_for(category_type_name, order = "name") ⇒ Object
Use <%= f.association :categories %> instead.
Fetches a list of categories for a cms_drop_down. Will prompt users to create Categories/Categories types if the proper ones don’t exist.
159 160 161 162 163 |
# File 'app/helpers/cms/application_helper.rb', line 159 def categories_for(category_type_name, order="name") cat_type = CategoryType.named(category_type_name).first categories = cat_type ? cat_type.category_list(order) : [Category.new(:name => "-- You must first create a 'Category Type' named '#{category_type_name}'")] categories.empty? ? [Category.new(:name => "-- You must first create a Category with a Category Type of '#{category_type_name}'.")] : categories end |
#check_uncheck_tag(selector) ⇒ Object
Renders two links that will check/uncheck a set of checkboxes.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/helpers/cms/application_helper.rb', line 78 def check_uncheck_tag(selector) check_id = to_id(selector, "check") uncheck_id = to_id(selector, "uncheck") content_for :html_head do html = "jQuery(function($) {\n $('a#\#{check_id}').click(function() {\n$('\#{selector}').prop('checked', true);\n });\n\n $('a#\#{uncheck_id}').click(function() {\n$('\#{selector}').prop('checked', false);\n });\n})\n" javascript_tag html end "#{link_to "Check All", '#', :id => check_id}, #{link_to "Uncheck All", '#', :id => uncheck_id}".html_safe end |
#cms_handler_path(*args) ⇒ Object
Help with deprecations messages
16 17 18 |
# File 'app/helpers/cms/application_helper.rb', line 16 def cms_handler_path(*args) raise "The #cms_handler_path helper method has been removed from BrowserCMS. Use '#handler_path instead'." end |
#determine_order(current_order, order) ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 |
# File 'app/helpers/cms/application_helper.rb', line 207 def determine_order(current_order, order) if current_order == order if order =~ / desc$/i order.sub(/ desc$/i, '') else order << ' desc' end else order end end |
#dk_button_wrapper(content) ⇒ Object
137 138 139 |
# File 'app/helpers/cms/application_helper.rb', line 137 def (content) (content).gsub("lt_button_", "dk_button_") end |
#draft_icon_tag(content, options = {}) ⇒ String
Generate HTML for draft icon for content that are in draft
47 48 49 50 51 52 53 |
# File 'app/helpers/cms/application_helper.rb', line 47 def draft_icon_tag(content, ={}) if content.respond_to?(:draft?) && content.draft? '<span class="draft">Draft</span>'.html_safe elsif [:force] '<span class="published">Published</span>'.html_safe end end |
#edit_button(options = {bootstrap: false}) ⇒ Object
Use link_to
Render a CMS styled ‘Edit’ button. This button will appear on tool bars, typically set apart visually from other buttons.
224 225 226 227 228 229 230 231 232 233 234 |
# File 'app/helpers/cms/application_helper.rb', line 224 def (={bootstrap: false}) label = [:bootstrap]? "Edit" : span_tag(" Edit ".html_safe) classes = () classes << " disabled" if ![:enabled] link_to_path = [:path] ? [:path] : "#" = {:id => 'edit_button', :class => classes} link_to label, link_to_path, end |
#format_date(time) ⇒ Object
71 72 73 |
# File 'app/helpers/cms/application_helper.rb', line 71 def format_date(time) time && "#{time.strftime("%b %e, %Y")}" end |
#group_filter ⇒ Object
145 146 147 148 149 150 151 152 153 |
# File 'app/helpers/cms/application_helper.rb', line 145 def group_filter select_tag("group_id", (Group.all.to_a.insert(0, Group.new(:id => nil, :name => "Show All Groups")), "id", "name", params[:group_id].to_i), class: 'group_filter' ) end |
#group_ids ⇒ Object
141 142 143 |
# File 'app/helpers/cms/application_helper.rb', line 141 def group_ids (params[:group_ids] || @user.group_ids).collect { |g| g.to_i } end |
#link_to_check_all(selector, name = "Check All") ⇒ Object
Use check_uncheck_tag instead. Retained for backwards compatibility w/ CMS implementations.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/helpers/cms/application_helper.rb', line 100 def link_to_check_all(selector, name="Check All") id = to_id(selector, "check") content_for :html_head do html = "jQuery(function($) {\n $('a#\#{id}').click(function() {\n$('\#{selector}').attr('checked', true);\n });\n})\n" javascript_tag html end link_to name, '#', :id => id end |
#link_to_uncheck_all(selector, name = "Uncheck All") ⇒ Object
Use check_uncheck_tag instead. Retained for backwards compatibility w/ CMS implementations.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'app/helpers/cms/application_helper.rb', line 116 def link_to_uncheck_all(selector, name="Uncheck All") id = to_id(selector, "uncheck") content_for :html_head do html = "jQuery(function($) {\n $('a#\#{id}').click(function() {\n$('\#{selector}').attr('checked', false);\n });\n})\n" javascript_tag html end link_to name, '#', :id => id end |
#page_versions(page) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'app/helpers/cms/application_helper.rb', line 32 def page_versions(page) text = select_tag(:version, (page.versions.all(:order => "version desc").map { |r| ["v#{r.version}: #{r.version_comment} by #{r.updated_by.login} at #{time_on_date(r.updated_at)}", r.version] }, page.version), :onchange => 'this.form.submit(); return false') text << javascript_tag("$('version').selectedIndex = 0") if page.live? text end |
#preview_content_path(content) ⇒ Object
Generate the proper link to Preview a Page or Addressable content block (based on type)
6 7 8 9 10 11 12 |
# File 'app/helpers/cms/application_helper.rb', line 6 def preview_content_path(content) if content.class == Cms::Page cms.preview_page_path(content) else content.path end end |
#render_pagination(collection, content_type, options = {}) ⇒ Object
Generates the HTML to render a paging control, if there is more than one page to be shown.
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'app/helpers/cms/application_helper.rb', line 170 def render_pagination(collection, content_type, ={}) return content_tag(:div, 'No Content', :class => 'pagination') if collection.blank? = { first_page_path: { page: 1 }, previous_page_path: { page: collection.previous_page || 1 }, current_page_path: {}, next_page_path: { page: collection.next_page || collection.current_page }, last_page_path: { page: collection.total_pages }, } locals = { collection: collection, content_type: content_type, } path_for_content_type = build_path_for(content_type) .each do |key, | locals[key] = engine(content_type).polymorphic_path(path_for_content_type, .merge()) end render partial: 'pagination', locals: locals end |
#searchable_sections(selected = nil) ⇒ Object
20 21 22 23 24 25 |
# File 'app/helpers/cms/application_helper.rb', line 20 def searchable_sections(selected = nil) root = Section.root.first = [['All sections', 'all'], [root.name, root.id]] root.master_section_list.each { |s| << [s.full_path, s.id] } (, selected.to_i) end |
#select_per_page ⇒ Object
27 28 29 30 |
# File 'app/helpers/cms/application_helper.rb', line 27 def select_per_page = [10, 20, 50, 100].collect { |c| ["#{c} per page", c] } select_tag("per_page", (, params[:per_page].to_i)) end |
#span_tag(content) ⇒ Object
131 132 133 |
# File 'app/helpers/cms/application_helper.rb', line 131 def span_tag(content) content_tag :span, content end |
#status_icon(status, options = {}) ⇒ Object
63 64 65 |
# File 'app/helpers/cms/application_helper.rb', line 63 def status_icon(status, ={}) image_tag "cms/icons/status/#{status.to_s.underscore}.gif", {:alt => status.to_s.titleize}.merge() end |
#time_on_date(time) ⇒ Object
67 68 69 |
# File 'app/helpers/cms/application_helper.rb', line 67 def time_on_date(time) time && "#{time.strftime("%l:%M %p")} on #{time.strftime("%b %e, %Y")}" end |
#url_with_mode(url, mode) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 |
# File 'app/helpers/cms/application_helper.rb', line 195 def url_with_mode(url, mode) url = "" unless url # Handles cases where request.referrer is nil (see cms/_page_toolbar.html.erb for an example) uri = URI.parse(url) if uri.query =~ /mode=[^&]*/ "#{uri.path}?#{uri.query.gsub(/((^|&)mode=)[^&]*/) { |s| "#{$1}#{mode}" }}" elsif uri.query "#{uri.path}?#{uri.query}&mode=#{mode}" else "#{uri.path}?mode=#{mode}" end end |