class RailsViewComponentModel attr_reader :component_name, :html_identifier, :html_classes def initialize id @prefix = "rails_view_component" @components = self.class.name.underscore.split("/")[0..-2] @dir = @components.join("/") @html_class_name = @prefix + "-" + @components.join("-") @html_identifier = "#{@html_class_name}-#{id}" @html_classes = ["rails_view_component", @html_class_name] 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/#{@dir}/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