Sha256: 27499bf36264812412f590cb4b03701df4364e8c9e7e4a14254ad6b38c592625
Contents?: true
Size: 945 Bytes
Versions: 3
Compression:
Stored size: 945 Bytes
Contents
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 <<HTML <div id="#{@html_identifier}" class="#{@html_classes.join(' ')}" #{data}> #{action_view.render(template: self.erb_script)} </div> HTML end end
Version data entries
3 entries across 3 versions & 1 rubygems