Sha256: b47194510fb35bd7908ea946a01f50133e2c92703259824be569db6f462e0bed

Contents?: true

Size: 883 Bytes

Versions: 5

Compression:

Stored size: 883 Bytes

Contents

class RailsViewComponent::RailsViewComponentModel
  attr_reader :component_name, :html_identifier, :html_classes
  def initialize id
    @component_name = self.class.name.match(/^(?<name>[^:]+)::/)[: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 <<HTML
<div id="#{@html_identifier}" class="#{@html_classes.join(' ')}" #{data}>
  #{action_view.render(template: self.erb_script)}
</div>
HTML
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rails_view_component-0.0.5 lib/rails_view_component/rails_view_component_model.rb
rails_view_component-0.0.4 lib/rails_view_component/rails_view_component_model.rb
rails_view_component-0.0.3 lib/rails_view_component/rails_view_component_model.rb
rails_view_component-0.0.2 lib/rails_view_component/rails_view_component_model.rb
rails_view_component-0.0.1 lib/rails_view_component/rails_view_component_model.rb