Module: Storytime::ApplicationHelper
- Defined in:
- app/helpers/storytime/application_helper.rb
Instance Method Summary collapse
- #active_admin_model_class(model) ⇒ Object
- #active_blog_item_class(blog) ⇒ Object
- #active_nav_item_class(controller, type = nil) ⇒ Object
- #dashboard_nav_class ⇒ Object
- #dashboard_nav_site_path(site) ⇒ Object
- #delete_resource_link(resource, href = nil, remote = true) ⇒ Object
- #method_missing(method, *args, &block) ⇒ Object
- #render_comments ⇒ Object
- #respond_to?(*args) ⇒ Boolean
- #tag_cloud(tags, classes) ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/helpers/storytime/application_helper.rb', line 74 def method_missing method, *args, &block if method.to_s.end_with?('_path') or method.to_s.end_with?('_url') if main_app.respond_to?(method) main_app.send(method, *args) else super end else super end end |
Instance Method Details
#active_admin_model_class(model) ⇒ Object
34 35 36 |
# File 'app/helpers/storytime/application_helper.rb', line 34 def active_admin_model_class(model) 'active' if params[:controller] == 'storytime/dashboard/admin' && model_name == model end |
#active_blog_item_class(blog) ⇒ Object
26 27 28 29 30 31 32 |
# File 'app/helpers/storytime/application_helper.rb', line 26 def active_blog_item_class(blog) path_arr = request.path.split("/") return unless path_arr.include?("blogs") 'class="active"'.html_safe if path_arr[2..-1].include?(blog.slug) end |
#active_nav_item_class(controller, type = nil) ⇒ Object
18 19 20 21 22 23 24 |
# File 'app/helpers/storytime/application_helper.rb', line 18 def active_nav_item_class(controller, type = nil) return if ["storytime/pages", "storytime/posts"].include? params[:controller] current_controller = params[:controller].split("/").last 'class="active"'.html_safe if controller == current_controller end |
#dashboard_nav_class ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'app/helpers/storytime/application_helper.rb', line 8 def dashboard_nav_class if @hide_nav "off-canvas-left" elsif dashboard_controller "off-canvas-left-sm absolute" else "off-canvas-left" end end |
#dashboard_nav_site_path(site) ⇒ Object
4 5 6 |
# File 'app/helpers/storytime/application_helper.rb', line 4 def dashboard_nav_site_path(site) site.nil? || site.new_record? ? storytime.new_dashboard_site_path : storytime.edit_dashboard_site_path(site) end |
#delete_resource_link(resource, href = nil, remote = true) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/helpers/storytime/application_helper.rb', line 38 def delete_resource_link(resource, href = nil, remote = true) humanized_resource_name = resource.class.to_s.split('::').last.underscore.humanize.downcase resource_name = resource.class.to_s.downcase.split("::").last opts = { id: "delete_#{resource_name}_#{resource.id}", class: "btn btn-danger btn-outline btn-xs btn-delete-resource delete-#{resource_name}-button", data: { confirm: I18n.t('common.are_you_sure_you_want_to_delete', resource_name: humanized_resource_name), resource_id: resource.id, resource_type: resource_name }, method: :delete } if remote opts[:remote] = true end link_to content_tag(:i, "", class: "icon-st-icons-trash"), href || resource, opts end |
#render_comments ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'app/helpers/storytime/application_helper.rb', line 64 def render_comments if @current_storytime_site.disqus_forum_shortname.present? render "storytime/comments/disqus" elsif @current_storytime_site.discourse_name.present? render "storytime/comments/discourse" else render "storytime/comments/comments" end end |
#respond_to?(*args) ⇒ Boolean
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/helpers/storytime/application_helper.rb', line 86 def respond_to?(*args) method = args.first if method.to_s.end_with?('_path') or method.to_s.end_with?('_url') if main_app.respond_to?(method) true else super end else super end end |
#tag_cloud(tags, classes) ⇒ Object
56 57 58 59 60 61 62 |
# File 'app/helpers/storytime/application_helper.rb', line 56 def tag_cloud(, classes) max = .sort_by(&:count).last .each do |tag| index = tag.count.to_f / max.count * (classes.size - 1) yield(tag, classes[index.round]) end end |