module Opalla::ComponentHelper
Public Instance Methods
component(name, id: nil, model: nil, collection: nil)
click to toggle source
# File lib/opalla/component_helper.rb, line 3 def component(name, id: nil, model: nil, collection: nil) comp_id = (id || "#{name}-#{cidn_and_increment}") html = component_html(name, id: id, model: model, collection: collection) output = Nokogiri::HTML.fragment(html).children.attr(id: comp_id).to_s output.html_safe end
Protected Instance Methods
cidn()
click to toggle source
# File lib/opalla/component_helper.rb, line 19 def cidn @cidn ||= 0 end
cidn_and_increment()
click to toggle source
# File lib/opalla/component_helper.rb, line 23 def cidn_and_increment @cidn = cidn + 1 @cidn - 1 end
component_html(name, id: nil, model: nil, collection: nil)
click to toggle source
# File lib/opalla/component_helper.rb, line 12 def component_html(name, id: nil, model: nil, collection: nil) options = { partial: "components/#{name}", locals: {} } model.nil? || options[:locals][:model] = model collection.nil? || options[:locals][:collection] = collection render(options) end