Skip to content

Instantly share code, notes, and snippets.

@markedmondson
Last active December 25, 2015 00:01
Show Gist options
  • Save markedmondson/5c076451bb09b20ed4ce to your computer and use it in GitHub Desktop.
Save markedmondson/5c076451bb09b20ed4ce to your computer and use it in GitHub Desktop.
Rails helpers for Zurb Ink
module InkHelper
def ink_container(*styles, &block)
styles = ["container"].concat(Array(styles))
content_tag(:table, class: styles.join(" ")) do
ink_block do
content_tag(:tr) do
content_tag(:td) do
capture { yield }
end
end
end
end
end
def ink_row(*styles, &block)
styles = ["wrapper"].concat(Array(styles))
content_tag(:table, class: "row") do
ink_block do
content_tag(:tr) do
content_tag(:td, class: styles.join(" ")) do
capture { yield }
end
end
end
end
end
def ink_columns(columns="twelve", options={}, &block)
ink_grid(columns, options, &block)
end
def ink_hr(*styles)
styles = ["last", "center"].concat(Array(styles))
ink_row styles do
ink_block do
content_tag(:table, class: "twelve columns") do
content_tag(:tr) do
content_tag(:td, class: "text-pad-left text-pad-right") do
content_tag(:hr)
end + ink_expander
end
end
end
end
end
def ink_block_grid(styles=[], elements=[])
styles = ["block-grid"].concat(Array(styles))
elements = Array(elements)
content_tag(:table, class: styles.join(" ")) do
ink_block do
content_tag(:tr) do
elements.each do |e|
concat content_tag(:td, e)
end
end
end
end
end
def ink_expander
content_tag(:td, "", class: "expander")
end
private
def ink_grid(columns="twelve", options={}, &block)
center = options.delete(:center) { true }
styles = options.delete(:styles)
styles = [columns, "columns"].concat(Array(styles))
cell_styles = options.delete(:cell_styles)
cell_styles = [center ? "center" : nil].compact.concat(Array(cell_styles))
table = capture do
content_tag(:table, class: styles.join(" ")) do
ink_block do
content_tag(:tr) do
content_tag(:td, class: cell_styles.join(" ")) do
capture { yield }
end + ink_expander
end
end
end
end
center ? ink_center { table } : table
end
def ink_block
concat(capture do
yield
end)
end
def ink_center
content_tag(:center) { yield }
end
end
@markedmondson
Copy link
Author

For using with slim:

= ink_container
    = ink_row "last"
        = ink_columns "text-pad"
            h2.center Title
        = ink_expander

@markedmondson
Copy link
Author

For using with erb:

<%= ink_container do %>
    <%= ink_row do %>
        <%= ink_columns "text-pad" %>
            <%= content_tag(:h2, "Title") %>
        <%= ink_expander %>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment