class RailsViewComponent::RalsViewComponentModel attr_reader :component_name, :html_identifier, :html_classes def initialize id @component_name = self.class.name.match(/^(?[^:]+)::/)[:name].underscore @html_identifier = "#{@component_name}_#{id}" @html_classes = ["rails_view_component", "#{@component_name}_view_component"] end def responsibility 1 end def javascripts [] end def stylesheets [] end def html erb_params={}, ajax_params={} action_view = ActionView::Base.new "#{Rails.root}/app/rails_view_components/#{@component_name}/views" erb_params.each{|k,v| action_view.assign(k=>v) } data = ajax_params.map{|k,v| "data-#{k}='#{v}'" }.join(' ') return < #{action_view.render(template: self.erb_script)} HTML end end