Module: GridomaticHelper
- Defined in:
- app/helpers/gridomatic_helper.rb
Constant Summary collapse
- COLORS =
%w( blue red green yellow cyan orange purple )
Instance Method Summary collapse
-
#clear_both ⇒ Object
If you want to put two boxes side by side, they both have to be float: left Add this tag after the last one to prevent other blocks from floating.
-
#render_box(options = {}) ⇒ Object
Render a box.
-
#render_boxes(array = [], options = {}) ⇒ Object
Render multiple boxes.
Instance Method Details
#clear_both ⇒ Object
If you want to put two boxes side by side, they both have to be float: left Add this tag after the last one to prevent other blocks from floating.
168 169 170 |
# File 'app/helpers/gridomatic_helper.rb', line 168 def clear_both content_tag :div, nil, :class => "clear_both" end |
#render_box(options = {}) ⇒ Object
Render a box.
options:
-
content (string)
-
heading (string)
-
float_left (true/false)
-
text_align_center (true/false)
-
highlight (true/false)
-
background_image (url)
-
bigfont (true/false)
-
heading_color (color name, e.g. ‘red’)
-
background_color (color name, e.g. ‘blue’)
-
inner_div_style (css style, e.g. “width: 382px; height: 281px;”)
-
outer_div_style (same)
-
heading_style (same)
-
height (css style unit, e.g. “100px” or “6em”)
-
solid_background (true/false)
You can wrap an <a> tag around the box and it will have a:hover CSS enabled, e.g.
-
link_to “www.example.com/” do
= render_box do
- "bar"
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'app/helpers/gridomatic_helper.rb', line 72 def render_box( = {}) # list of classes for the outer div. outer_div_classes = [ "textbox_container" ] # inner div, same story inner_div_classes = [ "textbox" ] # heading heading_classes = [ "heading" ] content = yield if block_given? content ||= [:content] return nil if content.blank? && [:heading].blank? unless [:empty] # Options: # float_left outer_div_classes.push("float_left") if [:float_left] === true # text_align_center inner_div_classes.push("text_align_center") if [:text_align_center] === true # highlight inner_div_classes.push("highlight") if [:highlight] === true # background_image background_image = [:background_image] # header color heading_color = [:heading_color] inner_div_classes.push("textbox_#{heading_color}") unless heading_color.blank? # background color background_color = [:background_color] ############################################################################ # inner div ############################################################################ inner_div_classes.push("#{background_color}_background") unless background_color.blank? = { :class => c(inner_div_classes) } inner_div_styles = [] unless background_image.blank? # opacity:0.4;filter:alpha(opacity=40); inner_div_styles.push "background: url(#{background_image}) no-repeat center;" end unless [:height].blank? inner_div_styles.push "height: #{[:height]}" end unless [:width].blank? inner_div_styles.push "width: #{[:width]}" end unless inner_div_styles.blank? [:style] = c(inner_div_styles) end [:style] ||= [:inner_div_style] # can be overridden ############################################################################ # outer div ############################################################################ = { :class => c(outer_div_classes) } [:style] = [:outer_div_style] ############################################################################ # text div ############################################################################ = {} text_div_classes = [] text_div_classes.push "bigfont" if [:bigfont] === true text_div_classes.push "solid_background" if [:solid_background] === true [:class] = c(text_div_classes) ############################################################################ # go render ############################################################################ # let's go, outer div content_tag :div, do content_tag :div, do # heading heading = "" heading = content_tag :p, [:heading], :class => c(heading_classes), :style => [:heading_style] unless [:heading].blank? # text div content_tag_ = content_tag :div, do content_tag :p, content, :class => "inner_p" end # do it! heading + content_tag_ end end end |
#render_boxes(array = [], options = {}) ⇒ Object
Render multiple boxes. Takes as argument a single array of Hash For the Hash options, please see render_box.
The boxes are wrapped in a div with class “textboxes”. You can pass individual styling using :textboxes_style => textboxes_style.
You can specify a template Hash ( :template => template ) which will be merged with each indivdual’s box’s options Hash. This way, you can create a list of boxes that look the same but some have their own characteristics.
Also adds a div with style “clear: both” after the output so other objects won’t start floating. If you don’t want that, add :noclear => true as an option.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/helpers/gridomatic_helper.rb', line 18 def render_boxes(array = [], = {}) boxes = "" template = {} if [:template].class.to_s.eql?("Hash") template = [:template] end array.each do || = template = template.merge() unless .nil? r = render_box() unless [:link].blank? r = "<a href='#{[:link]}' target='#{[:link_target]}' class='no_underline render_boxes'>#{r}</a>" end boxes += r unless r.blank? end boxes_div = content_tag :div, boxes, :class => "textboxes", :style => [:textboxes_style] clear_both_ = "" unless [:noclear] === true clear_both_ = clear_both end boxes_div + clear_both_ end |