module VueOnRails::ViewHelper
Public Class Methods
camelize_props(props)
click to toggle source
# File lib/vue_on_rails/view_helper.rb, line 27 def self.camelize_props(props) case props when Hash props.each_with_object({}) do |(key, value), new_props| new_key = key.to_s.camelize(:lower) new_props[new_key] = VueOnRails::ViewHelper.camelize_props(value) end else props end end
format_props(props)
click to toggle source
# File lib/vue_on_rails/view_helper.rb, line 15 def self.format_props(props) case props when Hash props.each_with_object({}) do |(key, value), new_props| new_key = key.to_s.dasherize new_props[new_key] = VueOnRails::ViewHelper.camelize_props(value) end else props end end
Public Instance Methods
vue_component(component_name, props = {}, html_options = {})
click to toggle source
# File lib/vue_on_rails/view_helper.rb, line 3 def vue_component(component_name, props = {}, html_options = {}) html_options = html_options.reverse_merge(data: {}) props = VueOnRails::ViewHelper.format_props(props) html_options[:data].tap do |data| data[:vue_component] = component_name data[:vue_props] = props.to_json end html_tag = html_options[:tag] || :div html_options.except!(:tag) content_tag(html_tag, '', html_options) end