Skip to content

Commit

Permalink
Adds support for outlets in stimulus 3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mepatterson committed Nov 29, 2022
1 parent 435bddf commit 88977aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/stimulizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,15 @@ def build_stimulus_controller
# ... or combine them:
#
# <%= stimulus(:controller, target: "button", action: "click->doThing")
def build_stimulus_hash(default_controller = false, controller_name: nil, controller: nil, target: nil, action: nil, params: nil, values: nil, classes: nil)
def build_stimulus_hash(default_controller = false, controller_name: nil, controller: nil, target: nil, action: nil, params: nil, values: nil, classes: nil, outlets: nil)
raise ArgumentError(":controller_name specified, but blank") if controller_name&.blank?
raise ArgumentError(":controller specified, but blank") if controller&.blank?
raise ArgumentError(":target specified, but blank") if target&.blank?
raise ArgumentError(":action specified, but blank") if action&.blank?
raise ArgumentError(":params specified, but blank") if params&.blank?
raise ArgumentError(":values specified, but blank") if values&.blank?
raise ArgumentError(":classes specified, but blank") if classes&.blank?
raise ArgumentError(":outlets specified, but blank") if outlets&.blank?

{}.tap do |hash|
hash[:"data-controller"] = ""
Expand Down Expand Up @@ -139,6 +140,10 @@ def build_stimulus_hash(default_controller = false, controller_name: nil, contro
hash[:"data-#{local_controller_name}-#{LuckyCase.dash_case(key.to_s)}-class"] = value
end

outlets&.each do |key, value|
hash[:"data-#{local_controller_name}-#{LuckyCase.dash_case(key.to_s)}-outlet"] = value
end

hash[:"data-#{local_controller_name}-target"] = target if target
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/stimulizer/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Stimulizer
VERSION = "0.1.2"
VERSION = "0.2.0"
end

0 comments on commit 88977aa

Please sign in to comment.