Sha256: 05dd79ab79ee1579c976ff3f0f6906d45caf563f36f115f5d1247f08a2161e88

Contents?: true

Size: 846 Bytes

Versions: 1

Compression:

Stored size: 846 Bytes

Contents

class RailsViewComponentBuilder
  def initialize
    @count = 0
    @components = []
  end
  def destribute name, ajax_params = {}, erb_params={}
    namespace = name.to_s.camelize
    name = namespace.split("::").last
    @count += 1
    klass = Module.const_get("#{namespace}::#{name}Model")
    obj = klass.new @count
    @components.push obj
    obj.html(ajax_params, erb_params).html_safe
  end

  def all_javascripts
    @components.inject([]){|acc,c|acc + c.javascripts}.uniq
  end
  def all_stylesheets
    @components.inject([]){|acc,c|acc + c.stylesheets}.uniq
  end

  def refer_to_javascripts
    all_javascripts.map{|js|
      "<script type='text/javascript' src='#{js}'></script>" }.join
  end
  def refer_to_stylesheets
    all_stylesheets.map{|css|
      "<link rel='stylesheet' type='text/css' href='#{css}'>" }.join
  end


end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_view_component-1.0.4 lib/generators/rails_view_component/templates/rails_view_component_builder.rb