Skip to content

Commit

Permalink
Added unique View::Addon identifiers for each main_toolbar.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aquaj committed Jun 28, 2017
1 parent 23501f1 commit 1ed7611
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/helpers/toolbar_helper.rb
@@ -1,6 +1,8 @@
module ToolbarHelper
# This class permit to register the composition of a toolbar
class Toolbar
class MainToolbarIDNotFound < RuntimeError; end

def initialize(template)
@template = template
end
Expand Down Expand Up @@ -150,6 +152,14 @@ def toolbar(options = {}, &block)
end
if options[:name] == :main
html << Ekylibre::View::Addon.render(:main_toolbar, self, t: toolbar)
view_path = block.source_location.first
relevant_path_regexp = Regexp.new(Regexp.escape("#{Rails.root}/app/views/")+"(.*)"+"\.html\.haml")
match = view_path.match(relevant_path_regexp)
unless match
raise MainToolbarIDNotFound, "Couldn't extract main_toolbar_id from #{view_path}"
end
identifier = match.captures.first.gsub('/', '_')
html << Ekylibre::View::Addon.render(:"#{identifier}_main_toolbar", self, t: toolbar)
end

unless options[:wrap].is_a?(FalseClass)
Expand Down

0 comments on commit 1ed7611

Please sign in to comment.