Module: CommandProposal::ApplicationHelper
- Includes:
- ActionDispatch::Routing::PolymorphicRoutes
- Included in:
- EngineController, Service::ProposalPresenter
- Defined in:
- app/helpers/command_proposal/application_helper.rb
Instance Method Summary collapse
- #cmd_path(*args) ⇒ Object
-
#cmd_url(*args) ⇒ Object
In order to keep the regular app’s routes working in the base template, we have to manually render the engine routes.
- #engine ⇒ Object
-
#runner_path(task, iteration = nil) ⇒ Object
Runner controller doesn’t map to a model, so needs special handling.
-
#runner_url(task, iteration = nil) ⇒ Object
Runner controller doesn’t map to a model, so needs special handling.
- #string_path(*args) ⇒ Object
Instance Method Details
#cmd_path(*args) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/helpers/command_proposal/application_helper.rb', line 34 def cmd_path(*args) args.tap { |arg_list| if arg_list.last.is_a?(Hash) arg_list.last.merge!(only_path: true) else arg_list << { only_path: true } end } cmd_url(*args) end |
#cmd_url(*args) ⇒ Object
In order to keep the regular app’s routes working in the base template, we have to manually
render the engine routes. Built a helper for this because it's long and nasty otherwise.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/helpers/command_proposal/application_helper.rb', line 7 def cmd_url(*args) return string_path(*args) if args.first.is_a?(String) model_names = [:tasks, :iterations, :comments, :task, :iteration, :comment] host = nil args.map! { |arg| next host ||= arg.delete(:host) if arg.is_a?(Hash) && arg.key?(:host) if arg.in?(model_names) "command_proposal_#{arg}".to_sym elsif arg == :task_iterations :iterations else arg end } args << { host: host, port: nil } if host.present? begin engine.url_for(args.compact) rescue NoMethodError => e if e..match?(/\_(url|path)\'/) raise e else raise "Error generating route! Please make sure `config.action_mailer.default_url_options` are set." end end end |
#engine ⇒ Object
50 51 52 |
# File 'app/helpers/command_proposal/application_helper.rb', line 50 def engine @engine ||= send(::CommandProposal.engine_name) end |
#runner_path(task, iteration = nil) ⇒ Object
Runner controller doesn’t map to a model, so needs special handling
55 56 57 58 59 60 61 |
# File 'app/helpers/command_proposal/application_helper.rb', line 55 def runner_path(task, iteration=nil) if iteration.present? engine.command_proposal_task_runner_path(task, iteration) else engine.command_proposal_task_runner_index_path(task) end end |
#runner_url(task, iteration = nil) ⇒ Object
Runner controller doesn’t map to a model, so needs special handling
64 65 66 67 68 69 70 |
# File 'app/helpers/command_proposal/application_helper.rb', line 64 def runner_url(task, iteration=nil) if iteration.present? engine.command_proposal_task_runner_url(task, iteration) else engine.command_proposal_task_runner_index_url(task) end end |
#string_path(*args) ⇒ Object
46 47 48 |
# File 'app/helpers/command_proposal/application_helper.rb', line 46 def string_path(*args) [engine.command_proposal_tasks_url + args.shift, args.to_param.presence].compact.join("?") end |