demarches-normaliennes/app/services/render_partial_service.rb

37 lines
708 B
Ruby
Raw Normal View History

2016-11-22 15:17:37 +01:00
class RenderPartialService
attr_accessor :controller, :method
def initialize controller, method
@controller = controller
@method = method
end
def navbar
retrieve_navbar
end
def left_panel
retrieve_left_panel
end
def self.left_panel_exist? left_panel_url
file = left_panel_url.split('/').last
File.exist?(Rails.root.join('app','views', 'layouts', 'left_panels', '_' + file + '.html.haml'))
end
2016-11-22 15:17:37 +01:00
private
def retrieve_navbar
'layouts/navbars/navbar_' + retrieve_name
2016-11-22 15:17:37 +01:00
end
def retrieve_left_panel
'layouts/left_panels/left_panel_' + retrieve_name
2016-11-22 15:17:37 +01:00
end
def retrieve_name
controller.to_s.parameterize.underscore + '_' + method.to_s
2016-11-22 15:17:37 +01:00
end
end