mirror of
https://github.com/funamitech/mastodon
synced 2024-11-30 15:58:28 +09:00
24 lines
540 B
Ruby
24 lines
540 B
Ruby
# frozen_string_literal: true
|
|
|
|
module ReactComponentHelper
|
|
def react_component(name, props = {}, &block)
|
|
data = { component: name.to_s.camelcase, props: Oj.dump(props) }
|
|
if block.nil?
|
|
div_tag_with_data(data)
|
|
else
|
|
content_tag(:div, data: data, &block)
|
|
end
|
|
end
|
|
|
|
def react_admin_component(name, props = {})
|
|
data = { 'admin-component': name.to_s.camelcase, props: Oj.dump(props) }
|
|
div_tag_with_data(data)
|
|
end
|
|
|
|
private
|
|
|
|
def div_tag_with_data(data)
|
|
content_tag(:div, nil, data: data)
|
|
end
|
|
end
|