Module: Kuhsaft::Cms::AdminHelper
- Defined in:
- app/helpers/kuhsaft/cms/admin_helper.rb
Instance Method Summary collapse
-
#all_selectable_routes ⇒ Object
here are some route helpers if you need them in your backend.
- #association_class(resource, column_name) ⇒ Object
- #link_to_content_locale(locale) ⇒ Object
- #model_attribute_field(resource, column_name, f) ⇒ Object
- #page_routes ⇒ Object
- #rails_routes ⇒ Object
- #render_language_switch? ⇒ Boolean
- #route_input(form, column_name, selectable_routes) ⇒ Object
Instance Method Details
#all_selectable_routes ⇒ Object
here are some route helpers if you need them in your backend
51 52 53 |
# File 'app/helpers/kuhsaft/cms/admin_helper.rb', line 51 def all_selectable_routes (page_routes + rails_routes).uniq.sort end |
#association_class(resource, column_name) ⇒ Object
44 45 46 47 48 |
# File 'app/helpers/kuhsaft/cms/admin_helper.rb', line 44 def association_class(resource, column_name) association = resource.class.reflect_on_all_associations.find { |r| r.name == column_name.to_sym } association_class = association.try :class_name association_class.present? ? association_class.constantize : nil end |
#link_to_content_locale(locale) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/helpers/kuhsaft/cms/admin_helper.rb', line 8 def link_to_content_locale(locale) action = params[:action] if params[:action] == 'create' action = 'new' elsif params[:action] == 'update' action = 'edit' end link_to locale.to_s.upcase, url_for( action: action, content_locale: locale) end |
#model_attribute_field(resource, column_name, f) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/helpers/kuhsaft/cms/admin_helper.rb', line 20 def model_attribute_field(resource, column_name, f) if resource.class.respond_to?(:uploaders) && resource.class.uploaders.keys.include?(column_name.to_sym) f.input column_name, as: :file elsif association_class(resource, column_name) == Kuhsaft::Page route_input f, column_name, page_routes elsif column_name == :link_url || column_name == :link route_input f, column_name, user_selectable_routes elsif column_name.to_s.end_with? '_id' f.association column_name.to_s.gsub(/_id$/, '').to_sym elsif column_name == :body f.input column_name, input_html: { class: 'ckeditor text required' } else f.input column_name end end |
#page_routes ⇒ Object
55 56 57 |
# File 'app/helpers/kuhsaft/cms/admin_helper.rb', line 55 def page_routes Kuhsaft::Page.all_urls end |
#rails_routes ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/helpers/kuhsaft/cms/admin_helper.rb', line 59 def rails_routes routes = Rails.application.routes.routes routes = routes.select do |r| r.verb.match('GET') && !r.requirements.blank? && !r.requirements[:controller].to_s.start_with?('cms') && !r.required_parts.any? && !r.requirements[:controller].to_s.start_with?('rails/') end routes.map { |r| _routes.url_for(r.requirements.merge only_path: true).strip }.uniq.sort end |
#render_language_switch? ⇒ Boolean
4 5 6 |
# File 'app/helpers/kuhsaft/cms/admin_helper.rb', line 4 def render_language_switch? I18n.available_locales.size > 1 end |
#route_input(form, column_name, selectable_routes) ⇒ Object
36 37 38 39 40 41 42 |
# File 'app/helpers/kuhsaft/cms/admin_helper.rb', line 36 def route_input(form, column_name, selectable_routes) list_name = "routes_#{column_name}" haml_tag :datalist, id: list_name, name: list_name do selectable_routes.each { |route| haml_tag :option, value: route } end form.input column_name, input_html: { list: list_name }, as: 'string' end |