Sha256: 464b9633544711c75e887aab595061fea0d14c0b55ae1e42cbcdde9d2a1f1280
Contents?: true
Size: 1.8 KB
Versions: 1
Compression:
Stored size: 1.8 KB
Contents
module Parade module Renderers # # With the given HTML content, search for the CSS class for the HTML element # and when found generate columns for each element found. The size of the # columns is a division of the number of segments. # class ColumnsRenderer attr_accessor :css_class attr_accessor :html_element attr_accessor :segments # # @example Creating a ColumnsRenderer # # Creation of a column renderer that will look for slides with the class # 'columns', and create columns out of all h2 elements found, dividing # them across 12 elements. # # ColumnsRenderer.new(:css_class => 'columns',:html_element => "h2",:segments => 12) # def initialize(params={}) params.each {|k,v| send("#{k}=",v) if respond_to? "#{k}=" } end def render(content) html = Nokogiri::XML.fragment(content) parser = CommandlineParser.new html.css(".#{css_class}").each do |slide| columns = [] slop = [] chunks = slide.children.chunk {|child| child.name == html_element } slide.children = "" slide['class'] += " container_#{segments}" current_column = slide column_count = chunks.find_all {|is_column,contents| is_column }.count chunks.each do |is_column,contents| if is_column slide.add_child current_column unless current_column == slide current_column = Nokogiri::XML::Node.new('div',html) current_column['class'] = "grid_#{ segments / column_count }" end contents.each {|content| current_column.add_child content } end slide.add_child current_column end html.to_s end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
parade-0.8.0 | lib/parade/renderers/columns_renderer.rb |