Class: Parade::Renderers::ColumnsRenderer
- Inherits:
-
Object
- Object
- Parade::Renderers::ColumnsRenderer
- Defined in:
- lib/parade/renderers/columns_renderer.rb
Overview
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.
Instance Attribute Summary collapse
-
#css_class ⇒ Object
Returns the value of attribute css_class.
-
#html_element ⇒ Object
Returns the value of attribute html_element.
-
#segments ⇒ Object
Returns the value of attribute segments.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ ColumnsRenderer
constructor
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.
- #render(content) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ 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)
24 25 26 |
# File 'lib/parade/renderers/columns_renderer.rb', line 24 def initialize(params={}) params.each {|k,v| send("#{k}=",v) if respond_to? "#{k}=" } end |
Instance Attribute Details
#css_class ⇒ Object
Returns the value of attribute css_class.
11 12 13 |
# File 'lib/parade/renderers/columns_renderer.rb', line 11 def css_class @css_class end |
#html_element ⇒ Object
Returns the value of attribute html_element.
12 13 14 |
# File 'lib/parade/renderers/columns_renderer.rb', line 12 def html_element @html_element end |
#segments ⇒ Object
Returns the value of attribute segments.
13 14 15 |
# File 'lib/parade/renderers/columns_renderer.rb', line 13 def segments @segments end |
Instance Method Details
#render(content) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/parade/renderers/columns_renderer.rb', line 28 def render(content) html = Nokogiri::XML.fragment(content) #for each element with the class 'content.css_class' html.css(".content.#{css_class}").each do || #chunk and mark nods that are html_element as columns chunks = chunk_children_by_element(, html_element) #remove the current children .children = "" #append the container grid count..size.. thing ['class'] += " container_#{segments}" current_column = #get the number of elements that are html_element column_count = chunks.find_all {|is_column, contents| is_column }.count chunks.each do |is_column,contents| if is_column current_column = new_column_div(html, column_count) end contents.each {|content| current_column.add_child content } .add_child current_column unless current_column == end end html.to_s end |